diff --git a/lua/devcontainer-cli/log.lua b/lua/devcontainer-cli/log.lua index fdda1e9..9b7d221 100644 --- a/lua/devcontainer-cli/log.lua +++ b/lua/devcontainer-cli/log.lua @@ -20,8 +20,10 @@ local default_config = { -- Should write to a file use_file = true, - -- Any messages above this level will be logged. - level = "debug", + -- Any messages above this level will be logged to log file. + log_level = "debug", + -- Any messages above this level will be logged to console. + console_level = "info", -- Level configuration modes = { @@ -85,10 +87,6 @@ log.new = function(config, standalone) local log_at_level = function(level, level_config, message_maker, ...) - -- Return early if we're below the config.level - if level < levels[config.level] then - return - end local nameupper = level_config.name:upper() local msg = message_maker(...) @@ -96,7 +94,7 @@ log.new = function(config, standalone) local lineinfo = info.short_src .. ":" .. info.currentline -- Output to console - if config.use_console then + if config.use_console and level < levels[config.console_level] then local console_string = string.format( "[%-6s%s] %s: %s", nameupper, @@ -120,7 +118,7 @@ log.new = function(config, standalone) end -- Output to log file - if config.use_file then + if config.use_file and level < levels[config.log_level] then local fp = io.open(outfile, "a") local str = string.format("[%-6s%s] %s: %s\n", nameupper, os.date(), lineinfo, msg)