Add CLI arguments to config file
The log level can now be set with `log_level` (accepts ints and strings). The log file can now be set with `output` (also accepts `STDOUT`).
This commit is contained in:
parent
2c24bf3222
commit
7a8620a570
3 changed files with 25 additions and 19 deletions
|
@ -107,8 +107,6 @@ LOCALES = {
|
||||||
YT_POOL = QUICPool.new(YT_URL, capacity: CONFIG.pool_size, timeout: 2.0)
|
YT_POOL = QUICPool.new(YT_URL, capacity: CONFIG.pool_size, timeout: 2.0)
|
||||||
|
|
||||||
config = CONFIG
|
config = CONFIG
|
||||||
output = STDOUT
|
|
||||||
loglvl = LogLevel::Debug
|
|
||||||
|
|
||||||
Kemal.config.extra_options do |parser|
|
Kemal.config.extra_options do |parser|
|
||||||
parser.banner = "Usage: invidious [arguments]"
|
parser.banner = "Usage: invidious [arguments]"
|
||||||
|
@ -128,12 +126,11 @@ Kemal.config.extra_options do |parser|
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
parser.on("-o OUTPUT", "--output=OUTPUT", "Redirect output (default: STDOUT)") do |output_arg|
|
parser.on("-o OUTPUT", "--output=OUTPUT", "Redirect output (default: #{config.output})") do |output|
|
||||||
FileUtils.mkdir_p(File.dirname(output_arg))
|
config.output = output
|
||||||
output = File.open(output_arg, mode: "a")
|
|
||||||
end
|
end
|
||||||
parser.on("-l LEVEL", "--log-level=LEVEL", "Log level, one of #{LogLevel.values} (default: #{loglvl})") do |loglvl_arg|
|
parser.on("-l LEVEL", "--log-level=LEVEL", "Log level, one of #{LogLevel.values} (default: #{config.log_level})") do |log_level|
|
||||||
loglvl = LogLevel.parse(loglvl_arg)
|
config.log_level = LogLevel.parse(log_level)
|
||||||
end
|
end
|
||||||
parser.on("-v", "--version", "Print version") do
|
parser.on("-v", "--version", "Print version") do
|
||||||
puts SOFTWARE.to_pretty_json
|
puts SOFTWARE.to_pretty_json
|
||||||
|
@ -143,7 +140,14 @@ end
|
||||||
|
|
||||||
Kemal::CLI.new ARGV
|
Kemal::CLI.new ARGV
|
||||||
|
|
||||||
logger = Invidious::LogHandler.new(output, loglvl)
|
if config.output.upcase == "STDOUT"
|
||||||
|
output = STDOUT
|
||||||
|
else
|
||||||
|
FileUtils.mkdir_p(File.dirname(config.output))
|
||||||
|
output = File.open(config.output, mode: "a")
|
||||||
|
end
|
||||||
|
|
||||||
|
logger = Invidious::LogHandler.new(output, config.log_level)
|
||||||
|
|
||||||
# Check table integrity
|
# Check table integrity
|
||||||
if CONFIG.check_tables
|
if CONFIG.check_tables
|
||||||
|
|
|
@ -64,11 +64,13 @@ end
|
||||||
class Config
|
class Config
|
||||||
include YAML::Serializable
|
include YAML::Serializable
|
||||||
|
|
||||||
property channel_threads : Int32 # Number of threads to use for crawling videos from channels (for updating subscriptions)
|
property channel_threads : Int32 = 1 # Number of threads to use for crawling videos from channels (for updating subscriptions)
|
||||||
property feed_threads : Int32 # Number of threads to use for updating feeds
|
property feed_threads : Int32 = 1 # Number of threads to use for updating feeds
|
||||||
|
property output : String = "STDOUT" # Log file path or STDOUT
|
||||||
|
property log_level : LogLevel = LogLevel::Debug # Default log level, valid YAML values are ints and strings, see src/invidious/helpers/logger.cr
|
||||||
property db : DBConfig # Database configuration
|
property db : DBConfig # Database configuration
|
||||||
property decrypt_polling : Bool = true # Use polling to keep decryption function up to date
|
property decrypt_polling : Bool = true # Use polling to keep decryption function up to date
|
||||||
property full_refresh : Bool # Used for crawling channels: threads should check all videos uploaded by a channel
|
property full_refresh : Bool = false # Used for crawling channels: threads should check all videos uploaded by a channel
|
||||||
property https_only : Bool? # Used to tell Invidious it is behind a proxy, so links to resources should be https://
|
property https_only : Bool? # Used to tell Invidious it is behind a proxy, so links to resources should be https://
|
||||||
property hmac_key : String? # HMAC signing key for CSRF tokens and verifying pubsub subscriptions
|
property hmac_key : String? # HMAC signing key for CSRF tokens and verifying pubsub subscriptions
|
||||||
property domain : String? # Domain to be used for links to resources on the site where an absolute URL is required
|
property domain : String? # Domain to be used for links to resources on the site where an absolute URL is required
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
require "logger"
|
require "logger"
|
||||||
|
|
||||||
enum LogLevel
|
enum LogLevel
|
||||||
All
|
All = 0
|
||||||
Trace
|
Trace = 1
|
||||||
Debug
|
Debug = 2
|
||||||
Info
|
Info = 3
|
||||||
Warn
|
Warn = 4
|
||||||
Error
|
Error = 5
|
||||||
Fatal
|
Fatal = 6
|
||||||
Off
|
Off = 7
|
||||||
end
|
end
|
||||||
|
|
||||||
class Invidious::LogHandler < Kemal::BaseLogHandler
|
class Invidious::LogHandler < Kemal::BaseLogHandler
|
||||||
|
|
Loading…
Reference in a new issue