Skip to content

Commit

Permalink
Add separate log levels for console and file.
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
docbacardi committed Sep 30, 2021
1 parent 1260d08 commit e08ea63
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions local/lua/test_system.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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('<LEVEL>')
: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('<LEVEL>')
: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

Expand All @@ -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

Expand Down

0 comments on commit e08ea63

Please sign in to comment.