From 9c55542f019ccaf40db9c5f3270d8ff5945bb8cc Mon Sep 17 00:00:00 2001 From: dvs1 Date: Fri, 25 Oct 2024 17:24:10 +1000 Subject: Added the rest of the logging and debug level stuff from apt-panopticon, except for file logging --- _.lua | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/_.lua b/_.lua index 945f4f2..43f3f59 100755 --- a/_.lua +++ b/_.lua @@ -16,14 +16,22 @@ local _ = {} _.version = '0.0 crap' --- TODO - add the rest of the logging and debug level stuff from apt-panopticon. +_.verbosity = 2 +local log = function(v, t, s) + if v <= _.verbosity then + if 3 <= _.verbosity then t = os.date('!%F %T') .. " " .. t end + print(t .. ": " .. s) + end + io.flush() +end + -- This sets the global values, here and in the caller. -D = function(s) print('DEBUG ' .. s); io.flush() end -I = function(s) print('INFO ' .. s); io.flush() end -T = function(s) print('TIMEOUT ' .. s); io.flush() end -W = function(s) print('WARNING ' .. s); io.flush() end -E = function(s) print('ERROR ' .. s); io.flush() end -C = function(s) print('CRITICAL ' .. s); io.flush() end +D = function(s) log(4, 'DEBUG ', s) end +I = function(s) log(3, 'INFO ', s) end +T = function(s) log(2, 'TIMEOUT ', s) end +W = function(s) log(1, 'WARNING ', s) end +E = function(s) log(0, 'ERROR ', s) end +C = function(s) log(-1, 'CRITICAL ', s) end local optionsCommon = @@ -41,6 +49,18 @@ local optionsCommon = os.exit(0) end }, + ['-q'] = {help = 'Decrease verbosity level.', + func = function(self, options, a, args, i) + if _.verbosity > -1 then _.verbosity = _.verbosity - 1 end + print('New verbosity level is ' .. _.verbosity) + end + }, + ['-v'] = {help = 'Increase verbosity level.', + func = function(self, options, a, args, i) + if _.verbosity < 4 then _.verbosity = _.verbosity + 1 end + print('New verbosity level is ' .. _.verbosity) + end + }, } optionsCommon['--help'] = optionsCommon['help'] -- cgit v1.1