mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
log: improve the most common use case (#19242)
This commit is contained in:
parent
55575fd7bd
commit
6fb4a481f8
16 changed files with 576 additions and 150 deletions
37
vlib/log/default_test.v
Normal file
37
vlib/log/default_test.v
Normal file
|
@ -0,0 +1,37 @@
|
|||
import log
|
||||
import time
|
||||
|
||||
fn test_default_log_instance() {
|
||||
println(@FN + ' start')
|
||||
log.info('info')
|
||||
log.warn('warn')
|
||||
log.error('error')
|
||||
log.debug('no output for debug')
|
||||
println('^^^ there should be no `no output for debug` shown above')
|
||||
log.set_level(.debug)
|
||||
log.debug('debug now')
|
||||
println('^^^ there should be `debug now` shown above')
|
||||
log.set_level(log.level_from_tag('INFO') or { log.Level.disabled })
|
||||
log.info('info again')
|
||||
log.set_level(log.level_from_tag('') or { log.Level.disabled })
|
||||
log.error('no output anymore')
|
||||
println('^^^ there should be no `no output anymore` shown above')
|
||||
println(@FN + ' end')
|
||||
}
|
||||
|
||||
fn log_messages(tidx int) {
|
||||
time.sleep(2 * time.millisecond)
|
||||
for i in 0 .. 3 {
|
||||
log.debug('hi from thread ${tidx}')
|
||||
}
|
||||
}
|
||||
|
||||
fn test_default_log_instance_used_in_multiple_threads() {
|
||||
eprintln('\n${@METHOD} start')
|
||||
log.set_level(.debug)
|
||||
mut threads := []thread{}
|
||||
for tidx in 0 .. 3 {
|
||||
threads << spawn log_messages(tidx)
|
||||
}
|
||||
threads.wait()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue