log: add log.use_stdout(), use it to silence the transition note for the most commonly used V tools/examples (#23642)

This commit is contained in:
Delyan Angelov 2025-02-03 12:37:57 +02:00 committed by GitHub
parent 23c3af8b4d
commit 319eb83525
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 24 additions and 7 deletions

View file

@ -58,16 +58,17 @@ fn main() {
After 2025/01/21, the `log` module outputs to `stderr` by default.
Before that, it used `stdout` by default.
If you want to restore the previous behaviour, you have to explicitly call l.set_output_stream():
If you want to restore the previous behaviour, you have to explicitly call `log.use_stdout()` :
```v
import os
import log
fn main() {
// log.info('this will be printed to stderr after 2025/01/21 by default')
mut l := log.ThreadSafeLog{}
l.set_output_stream(os.stdout())
log.set_logger(l)
log.use_stdout()
log.info('this will be printed to stdout')
}
```
If you want to just silence the note about the stdout -> stderr, during the transition period,
call `l.set_output_stream(os.stderr())` explicitly.

View file

@ -324,3 +324,11 @@ pub fn (mut l Log) set_short_tag(enabled bool) {
pub fn (l Log) get_short_tag() bool {
return l.short_tag
}
// use_stdout will restore the old behaviour of logging to stdout, instead of stderr.
// It will also silence the deprecation note in the transition period.
pub fn use_stdout() {
mut l := ThreadSafeLog{}
l.set_output_stream(os.stdout())
set_logger(l)
}