Improve logging

Everything that gets logged now has a log level associated with it.

The log level can be set with the new `-l` or `--log-level` arguments.

The defaul log level is `debug` for now. There aren't many things that get
logged but if the logs get spammed in the future it can be set down to `info`.
This commit is contained in:
saltycrys 2020-12-21 16:05:35 +01:00
parent dba7dc4e96
commit b39f01dcdf
8 changed files with 51 additions and 57 deletions

View file

@ -107,7 +107,8 @@ LOCALES = {
YT_POOL = QUICPool.new(YT_URL, capacity: CONFIG.pool_size, timeout: 2.0)
config = CONFIG
logger = Invidious::LogHandler.new
output = STDOUT
loglvl = LogLevel::Debug
Kemal.config.extra_options do |parser|
parser.banner = "Usage: invidious [arguments]"
@ -127,11 +128,14 @@ Kemal.config.extra_options do |parser|
exit
end
end
parser.on("-o OUTPUT", "--output=OUTPUT", "Redirect output (default: STDOUT)") do |output|
FileUtils.mkdir_p(File.dirname(output))
logger = Invidious::LogHandler.new(File.open(output, mode: "a"))
parser.on("-o OUTPUT", "--output=OUTPUT", "Redirect output (default: STDOUT)") do |output_arg|
FileUtils.mkdir_p(File.dirname(output_arg))
output = File.open(output_arg, mode: "a")
end
parser.on("-v", "--version", "Print version") do |output|
parser.on("-l LEVEL", "--log-level=LEVEL", "Log level, one of #{LogLevel.values} (default: #{loglvl})") do |loglvl_arg|
loglvl = LogLevel.parse(loglvl_arg)
end
parser.on("-v", "--version", "Print version") do
puts SOFTWARE.to_pretty_json
exit
end
@ -139,6 +143,8 @@ end
Kemal::CLI.new ARGV
logger = Invidious::LogHandler.new(output, loglvl)
# Check table integrity
if CONFIG.check_tables
check_enum(PG_DB, logger, "privacy", PlaylistPrivacy)
@ -1495,7 +1501,7 @@ post "/feed/webhook/:token" do |env|
signature = env.request.headers["X-Hub-Signature"].lchop("sha1=")
if signature != OpenSSL::HMAC.hexdigest(:sha1, HMAC_KEY, body)
logger.puts("#{token} : Invalid signature")
logger.error("/feed/webhook/#{token} : Invalid signature")
env.response.status_code = 200
next
end