Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Introduce different verbosity levels.

Defined levels are INFO, DEBUG and TRACE.

For each `verbose` option present in the compiler options,
the verbosity level used is put up a notch
(i.e. `[... verbose, verbose, ...]` yields INFO and DEBUG output).
  • Loading branch information...
commit 507c6d75683663a12b61a744f51e71a2acc9158e 1 parent c7b2883
@kaos kaos authored
View
10 include/erlydtl_ext.hrl
@@ -24,7 +24,7 @@
compiler_options = [],
binary_strings = true,
force_recompile = false,
- verbose = false,
+ verbose = 0,
is_compiling_dir = false,
extension_module = undefined,
scanner_module = erlydtl_scanner,
@@ -60,3 +60,11 @@
-define(ERR(Err, Ctx), erlydtl_compiler_utils:add_error(?MODULE, Err, Ctx)).
-define(WARN(Warn, Ctx), erlydtl_compiler_utils:add_warning(?MODULE, Warn, Ctx)).
+
+-define(V_INFO,1).
+-define(V_DEBUG,2).
+-define(V_TRACE,3).
+
+-define(LOG_INFO(Fmt, Args, Ctx), erlydtl_compiler_utils:print(?V_INFO, Fmt, Args, Ctx)).
+-define(LOG_DEBUG(Fmt, Args, Ctx), erlydtl_compiler_utils:print(?V_DEBUG, Fmt, Args, Ctx)).
+-define(LOG_TRACE(Fmt, Args, Ctx), erlydtl_compiler_utils:print(?V_TRACE, Fmt, Args, Ctx)).
View
6 src/erlydtl_beam_compiler.erl
@@ -60,7 +60,7 @@
-import(erlydtl_compiler_utils,
[unescape_string_literal/1, full_path/2, push_scope/2,
restore_scope/2, begin_scope/1, begin_scope/2, end_scope/4,
- empty_scope/0, print/3, get_current_file/1, add_errors/2,
+ empty_scope/0, get_current_file/1, add_errors/2,
add_warnings/2, merge_info/2, call_extension/3,
init_treewalker/1, resolve_variable/2, resolve_variable/3,
reset_parse_trail/2, load_library/3, load_library/4]).
@@ -241,7 +241,7 @@ maybe_write(Module, Bin, Context) ->
?WARN(no_out_dir, Context);
OutDir ->
BeamFile = filename:join([OutDir, [Module, ".beam"]]),
- print("Template module: ~w -> ~s\n", [Module, BeamFile], Context),
+ ?LOG_INFO("Template module: ~w -> ~s\n", [Module, BeamFile], Context),
case file:write_file(BeamFile, Bin) of
ok -> Context;
{error, Reason} ->
@@ -268,7 +268,7 @@ maybe_debug_template(Forms, Context) ->
false -> nop;
true ->
Options = Context#dtl_context.compiler_options,
- print("Compiler options: ~p~n", [Options], Context),
+ ?LOG_DEBUG("Compiler options: ~p~n", [Options], Context),
try
Source = erl_prettypr:format(erl_syntax:form_list(Forms)),
File = lists:concat([proplists:get_value(source, Options), ".erl"]),
View
8 src/erlydtl_compiler.erl
@@ -51,7 +51,7 @@
-export([parse_file/2, parse_template/2, do_parse_template/2]).
-import(erlydtl_compiler_utils,
- [add_filters/2, add_tags/2, print/3, call_extension/3,
+ [add_filters/2, add_tags/2, call_extension/3,
load_library/2]).
-include("erlydtl_ext.hrl").
@@ -69,12 +69,12 @@ compile_template(Template, Module, Options) ->
compile_file(File, Module, Options) ->
Context = process_opts(File, Module, Options),
- print("Compile template: ~s~n", [File], Context),
+ ?LOG_INFO("Compile template: ~s~n", [File], Context),
compile(Context).
compile_dir(Dir, Module, Options) ->
Context = process_opts({dir, Dir}, Module, Options),
- print("Compile directory: ~s~n", [Dir], Context),
+ ?LOG_INFO("Compile directory: ~s~n", [Dir], Context),
compile(Context).
@@ -253,7 +253,7 @@ init_context(ParseTrail, DefDir, Module, Options) ->
compiler_options = proplists:append_values(compiler_options, Options),
binary_strings = proplists:get_value(binary_strings, Options, Ctx#dtl_context.binary_strings),
force_recompile = proplists:get_bool(force_recompile, Options),
- verbose = proplists:get_value(verbose, Options, Ctx#dtl_context.verbose),
+ verbose = length(proplists:get_all_values(verbose, Options)),
is_compiling_dir = ParseTrail == [],
extension_module = proplists:get_value(extension_module, Options, Ctx#dtl_context.extension_module),
scanner_module = proplists:get_value(scanner_module, Options, Ctx#dtl_context.scanner_module),
View
13 src/erlydtl_compiler_utils.erl
@@ -58,6 +58,7 @@
load_library/4,
merge_info/2,
print/3,
+ print/4,
to_string/2,
unescape_string_literal/1,
reset_parse_trail/2,
@@ -99,8 +100,16 @@ full_path(File, DocRoot) ->
_ -> filename:join([DocRoot, File])
end.
-print(Fmt, Args, #dtl_context{ verbose = true }) -> io:format(Fmt, Args);
-print(_Fmt, _Args, _Context) -> ok.
+print(Fmt, Args, Context) ->
+ print(?V_INFO, Fmt, Args, Context).
+
+print(Verbosity, Fmt, Args, #treewalker{ context=Context }) ->
+ print(Verbosity, Fmt, Args, Context);
+print(Verbosity, Fmt, Args, #dtl_context{ verbose = Verbose })
+ when Verbosity =< Verbose ->
+ io:format(Fmt, Args);
+print(_Verbosity, _Fmt, _Args, _Context) ->
+ ok.
get_current_file(#treewalker{ context=Context }) ->
get_current_file(Context);
Please sign in to comment.
Something went wrong with that request. Please try again.