mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2025-04-20 18:16:30 +02:00
Move default filter set to config file.
Show available filter sets in help output.
This commit is contained in:
parent
1db8bf3119
commit
c8bea605f7
@ -1,9 +1,19 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M.default = { -- TEST set
|
M.default = {
|
||||||
|
['options'] = { ['mode'] = 'keep', count = 'none' },
|
||||||
|
['patterns'] = {
|
||||||
|
['%(error%)'] = 'red',
|
||||||
|
['%(warning%)'] = 'yellow',
|
||||||
|
['%(bulk%)'] = 'gray',
|
||||||
|
['setState%(%)'] = 'bblue'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
M.test = { -- TEST set
|
||||||
['options'] = { ['mode'] = 'keep', count = 'all' },
|
['options'] = { ['mode'] = 'keep', count = 'all' },
|
||||||
['patterns'] = {
|
['patterns'] = {
|
||||||
['%(info%)'] = 'magenta'
|
['%(info%)'] = 'yellow'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14,14 +24,4 @@ M.printstart = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
M.test = {
|
|
||||||
['options'] = { 'delete_mode' },
|
|
||||||
['patterns'] = {
|
|
||||||
['(verbose)'] = 'underline,cyan,_delete',
|
|
||||||
['(info)'] = 'magenta',
|
|
||||||
['ABSD'] = '_nodelete',
|
|
||||||
['SE?RV?'] = 'bblue'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@ -45,18 +45,11 @@ local ANSI_COLORS = {
|
|||||||
|
|
||||||
local ESCAPE_STR = string.char(27) .. "["
|
local ESCAPE_STR = string.char(27) .. "["
|
||||||
local RESET_CODE = ESCAPE_STR .. "m"
|
local RESET_CODE = ESCAPE_STR .. "m"
|
||||||
|
|
||||||
local DFL_FILTERSET_FILE = "loglite-filters.lua"
|
local DFL_FILTERSET_FILE = "loglite-filters.lua"
|
||||||
|
|
||||||
local DEFAULT_FILTERSET = {
|
|
||||||
['options'] = { ['mode'] = 'keep', count = 'none' },
|
|
||||||
['patterns'] = {
|
|
||||||
['%(error%)'] = 'red',
|
|
||||||
['%(warning%)'] = 'yellow',
|
|
||||||
['%(bulk%)'] = 'gray',
|
|
||||||
['setState%(%)'] = 'bblue'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
--[[========================================================================]]--
|
||||||
|
|
||||||
--- Stringifies the given object.
|
--- Stringifies the given object.
|
||||||
-- From util/utils.lua
|
-- From util/utils.lua
|
||||||
@ -134,9 +127,10 @@ end
|
|||||||
--[[========================================================================]]--
|
--[[========================================================================]]--
|
||||||
|
|
||||||
local function tailStream(stream, filterSet)
|
local function tailStream(stream, filterSet)
|
||||||
patterns = filterSet.patterns
|
patterns = filterSet and filterSet.patterns or {}
|
||||||
options = filterSet.options
|
options = filterSet and filterSet.options or { ['mode'] = 'keep' }
|
||||||
local c = 0
|
local c = 0
|
||||||
|
|
||||||
for line in stream:lines() do
|
for line in stream:lines() do
|
||||||
--c = c + 1 -- Note: this would also count deleted lines
|
--c = c + 1 -- Note: this would also count deleted lines
|
||||||
local embellished = line
|
local embellished = line
|
||||||
@ -204,26 +198,18 @@ end
|
|||||||
--NOTE: if command-line options get any more complex, switch to a lightweight
|
--NOTE: if command-line options get any more complex, switch to a lightweight
|
||||||
-- getopt like this one? https://attractivechaos.wordpress.com/2011/04/07/getopt-for-lua/
|
-- getopt like this one? https://attractivechaos.wordpress.com/2011/04/07/getopt-for-lua/
|
||||||
local function main()
|
local function main()
|
||||||
|
-- handle command-line arguments
|
||||||
|
local showHelp, followFile, filterSetName = false, nil, 'default'
|
||||||
if #arg > 0 and arg[1] == "-h" or arg[1] == "--help" then
|
if #arg > 0 and arg[1] == "-h" or arg[1] == "--help" then
|
||||||
print("Usage: loglite.lua [file-to-tail] [filter-set]")
|
showHelp = true
|
||||||
print(" If no arguments are supplied, or if the first one is `-', stdin is used as input.")
|
else
|
||||||
print(" If no filter set is supplied, a set named `default' will be looked for.")
|
if #arg > 0 and arg[1] ~= '-' then followFile = arg[1] end
|
||||||
print(" Filter sets can be defined in a file `loglite-filters.lua' in your home directory.")
|
if #arg > 1 then filterSetName = arg[2] end
|
||||||
os.exit(0)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local followFile = #arg > 0 and arg[1] ~= '-' and arg[1] or nil
|
-- read filter set file if available
|
||||||
local filterSetName = #arg > 1 and arg[2] or 'default'
|
local filterSet = nil
|
||||||
|
configSets = readConfigFile(DFL_FILTERSET_FILE, os.getenv('HOME')) or {}
|
||||||
--print("[DEBUG] following file: '" .. (followFile and followFile or "<stdin>") .. "', with filter set '" .. filterSetName .. "'.")
|
|
||||||
|
|
||||||
|
|
||||||
--local tailin = io.popen('tail -F '..(...)..' 2>&1', 'r')
|
|
||||||
local tailin = followFile and io.popen('tail -f ' .. followFile, 'r') or io.stdin
|
|
||||||
|
|
||||||
local filterSet = DEFAULT_FILTERSET
|
|
||||||
|
|
||||||
configSets = readConfigFile(DFL_FILTERSET_FILE, os.getenv('HOME'))
|
|
||||||
for k,_ in pairs(configSets) do
|
for k,_ in pairs(configSets) do
|
||||||
if k == filterSetName then
|
if k == filterSetName then
|
||||||
filterSet = configSets[filterSetName]
|
filterSet = configSets[filterSetName]
|
||||||
@ -232,13 +218,25 @@ local function main()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO: add commandline option to enable this flag
|
-- if requested, display help and exit
|
||||||
if listAvailableFilterSets == true then
|
if showHelp and showHelp == true then
|
||||||
print(" Available filter sets in " .. DFL_FILTERSET_FILE .. ": " .. keysToString(configSets, ', '))
|
print("Usage: loglite.lua [file-to-tail] [filter-set]")
|
||||||
|
print(" If no arguments are supplied, or if the first one is `-', stdin is used as input.")
|
||||||
|
print(" If no filter set is supplied, a set named `default' will be looked for.")
|
||||||
|
print(" Filter sets can be defined in a file `loglite-filters.lua' in your home directory.")
|
||||||
|
print()
|
||||||
|
print(" Available filter sets in " .. os.getenv('HOME') .. "/" .. DFL_FILTERSET_FILE .. ": " .. keysToString(configSets, ', ', true))
|
||||||
os.exit(0)
|
os.exit(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
--print("[DEBUG] following file: '" .. (followFile and followFile or "<stdin>") .. "', with filter set '" .. filterSetName .. "'.")
|
||||||
|
|
||||||
|
--local tailin = io.popen('tail -F '..(...)..' 2>&1', 'r')
|
||||||
|
local tailin = followFile and io.popen('tail -f ' .. followFile, 'r') or io.stdin
|
||||||
|
|
||||||
pcall(tailStream, tailin, filterSet) -- Note: protected call to suppress interrupt error thrown by lines iterator
|
pcall(tailStream, tailin, filterSet) -- Note: protected call to suppress interrupt error thrown by lines iterator
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user