From e08ea6341fd60915fa805782baaa8b82eb5320a9 Mon Sep 17 00:00:00 2001 From: Christoph Thelen Date: Thu, 30 Sep 2021 14:32:51 +0200 Subject: [PATCH] Add separate log levels for console and file. The "-v" or "--verbose" option now defines the default log level. It can be overridden for the console with "--verbose-console" and for the file with "--verbose-file". --- local/lua/test_system.lua | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/local/lua/test_system.lua b/local/lua/test_system.lua index 0977fae..6d8c4e3 100644 --- a/local/lua/test_system.lua +++ b/local/lua/test_system.lua @@ -232,12 +232,39 @@ function TestSystem:parse_commandline_arguments() end end) :target('strLogLevel') + tParser:option('--verbose-console') + :description(string.format('Set the verbosity level for the console output to LEVEL. Possible values for LEVEL are %s.', table.concat(atLogLevels, ', '))) + :argname('') + :convert(function(strArg) + local tIdx = self.pl.tablex.find(atLogLevels, strArg) + if tIdx==nil then + return nil, string.format('Invalid console verbosity level "%s". Possible values are %s.', strArg, table.concat(atLogLevels, ', ')) + else + return strArg + end + end) + :target('strLogLevelConsole') + tParser:option('--verbose-file') + :description(string.format('Set the verbosity level for the file output to LEVEL. Possible values for LEVEL are %s.', table.concat(atLogLevels, ', '))) + :argname('') + :convert(function(strArg) + local tIdx = self.pl.tablex.find(atLogLevels, strArg) + if tIdx==nil then + return nil, string.format('Invalid file verbosity level "%s". Possible values are %s.', strArg, table.concat(atLogLevels, ', ')) + else + return strArg + end + end) + :target('strLogLevelFile') local tArgs = tParser:parse() -- Save the selected log level. self.strLogLevel = tArgs.strLogLevel + -- Get the log levels for the console and file. Fallback to the log level if they are not set. + local strLogLevelConsole = tArgs.strLogLevelConsole or tArgs.strLogLevel + local strLogLevelFile = tArgs.strLogLevelFile or tArgs.strLogLevel self.fShowParameters = tArgs.fShowParameters @@ -263,12 +290,12 @@ function TestSystem:parse_commandline_arguments() else tLogWriterConsole = require 'log.writer.console'.new() end - table.insert(atLogWriters, tLogWriterConsole) + table.insert(atLogWriters, require "log.writer.filter".new(strLogLevelConsole, tLogWriterConsole)) -- Create the file logger if requested. local tLogWriterFile if tArgs.strLogFileName~=nil then - tLogWriterFile = require 'log.writer.file'.new{ log_name=tArgs.strLogFileName } + tLogWriterFile = require "log.writer.filter".new(strLogLevelFile, require 'log.writer.file'.new{ log_name=tArgs.strLogFileName }) table.insert(atLogWriters, tLogWriterFile) end