log: allow for -d log_default_level=debug, to change the default log level for programs and tests, that do not explicitly call log.set_level/1 themselves.

This commit is contained in:
Delyan Angelov 2025-07-08 17:08:43 +03:00
parent f683ab69d6
commit bb7f9f2562
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 5 additions and 1 deletions

View File

@ -14,6 +14,7 @@ fn test_reopen() {
dump(lfolder)
mut l := log.new_thread_safe_log()
l.set_level(.debug)
l.set_full_logpath(lpath1)
l.warn('one warning')
l.error('one error')
@ -42,6 +43,7 @@ fn test_reopen() {
}
fn test_set_always_flush() {
log.set_level(.debug)
lfolder := os.join_path(os.vtmp_dir(), rand.ulid())
lpath1 := os.join_path(lfolder, 'current.log')
os.mkdir_all(lfolder)!

View File

@ -13,8 +13,10 @@ pub mut:
// new_thread_safe_log returns a new log structure, whose methods are safe
// to call by multiple threads.
pub fn new_thread_safe_log() &ThreadSafeLog {
slevel := $d('log_default_level', 'info')
level := level_from_tag(slevel.to_upper()) or { panic('invalid log_default_level: ${slevel}') }
mut x := &ThreadSafeLog{
level: .info
level: level
}
return x
}