@@ -20,8 +20,10 @@ local default_config = {
2020 -- Should write to a file
2121 use_file = true ,
2222
23- -- Any messages above this level will be logged.
24- level = " debug" ,
23+ -- Any messages above this level will be logged to log file.
24+ log_level = " debug" ,
25+ -- Any messages above this level will be logged to console.
26+ console_level = " info" ,
2527
2628 -- Level configuration
2729 modes = {
@@ -85,18 +87,14 @@ log.new = function(config, standalone)
8587
8688
8789 local log_at_level = function (level , level_config , message_maker , ...)
88- -- Return early if we're below the config.level
89- if level < levels [config .level ] then
90- return
91- end
9290 local nameupper = level_config .name :upper ()
9391
9492 local msg = message_maker (... )
9593 local info = debug.getinfo (2 , " Sl" )
9694 local lineinfo = info .short_src .. " :" .. info .currentline
9795
9896 -- Output to console
99- if config .use_console then
97+ if config .use_console and level < levels [ config . console_level ] then
10098 local console_string = string.format (
10199 " [%-6s%s] %s: %s" ,
102100 nameupper ,
@@ -120,7 +118,7 @@ log.new = function(config, standalone)
120118 end
121119
122120 -- Output to log file
123- if config .use_file then
121+ if config .use_file and level < levels [ config . log_level ] then
124122 local fp = io.open (outfile , " a" )
125123 local str = string.format (" [%-6s%s] %s: %s\n " ,
126124 nameupper , os.date (), lineinfo , msg )
0 commit comments