diff --git a/ci/common/runner.v b/ci/common/runner.v index 2798374f77a06b..fe369b3828d8c1 100644 --- a/ci/common/runner.v +++ b/ci/common/runner.v @@ -34,6 +34,7 @@ pub fn (t Task) run() { pub fn run(all_tasks map[string]Task) { unbuffer_stdout() + log.use_stdout() if os.args.len < 2 { println('Usage: v run macos_ci.vsh ') println('Available tasks are: ${all_tasks.keys()}') diff --git a/cmd/tools/fast/fast.v b/cmd/tools/fast/fast.v index f31fd214870a0c..00dc25cc86d3b6 100644 --- a/cmd/tools/fast/fast.v +++ b/cmd/tools/fast/fast.v @@ -41,6 +41,7 @@ fn lexec(cmd string) string { fn main() { // ensure all log messages will be visible to the observers, even if the program panics + log.use_stdout() log.set_always_flush(true) total_sw := time.new_stopwatch() diff --git a/cmd/tools/gen_vc.v b/cmd/tools/gen_vc.v index 386d364db1776b..8dace3983ed885 100644 --- a/cmd/tools/gen_vc.v +++ b/cmd/tools/gen_vc.v @@ -97,6 +97,7 @@ struct FlagOptions { } fn main() { + log.use_stdout() mut fp := flag.new_flag_parser(os.args.clone()) fp.application(app_name) fp.version(app_version) diff --git a/cmd/tools/vcover/main.v b/cmd/tools/vcover/main.v index 5e8b9e29bd44b8..9d09cc5692690b 100644 --- a/cmd/tools/vcover/main.v +++ b/cmd/tools/vcover/main.v @@ -148,6 +148,7 @@ fn normalize_path(path string) string { } fn main() { + log.use_stdout() mut ctx := Context{} ctx.working_folder = normalize_path(os.real_path(os.getwd())) mut fp := flag.new_flag_parser(os.args#[1..]) diff --git a/cmd/tools/vdownload.v b/cmd/tools/vdownload.v index 5d5b4bf940f341..9b4e24060a6715 100644 --- a/cmd/tools/vdownload.v +++ b/cmd/tools/vdownload.v @@ -23,9 +23,7 @@ mut: const vexe = os.real_path(os.getenv_opt('VEXE') or { @VEXE }) fn main() { - mut l := log.ThreadSafeLog{} - l.set_output_stream(os.stdout()) - log.set_logger(l) + log.use_stdout() mut ctx := Context{} mut fp := flag.new_flag_parser(os.args#[1..]) fp.application(os.file_name(os.executable())) diff --git a/cmd/tools/vretry_test.v b/cmd/tools/vretry_test.v index d727293ff24622..fd6f1916f28bad 100644 --- a/cmd/tools/vretry_test.v +++ b/cmd/tools/vretry_test.v @@ -22,6 +22,7 @@ fn run(cmd string) os.Result { } fn test_retry() { + log.use_stdout() log.warn('start...') defer { log.warn('... done') diff --git a/cmd/tools/vshould-compile-all.v b/cmd/tools/vshould-compile-all.v index 3185d53b08d9c8..ebe9a8a22a7045 100644 --- a/cmd/tools/vshould-compile-all.v +++ b/cmd/tools/vshould-compile-all.v @@ -4,6 +4,7 @@ import log const should_clean = os.args.contains('-c') fn main() { + log.use_stdout() mut files := []string{} args := os.args#[2..].filter(it != '-c') for a in args { diff --git a/examples/pendulum-simulation/animation.v b/examples/pendulum-simulation/animation.v index 1d93764eb6982e..bcd4cbe469dfed 100644 --- a/examples/pendulum-simulation/animation.v +++ b/examples/pendulum-simulation/animation.v @@ -8,6 +8,7 @@ import sim.args as simargs fn main() { unbuffer_stdout() + log.use_stdout() args := simargs.parse_args(extra_workers: 1)! as simargs.ParallelArgs mut app := anim.new_app(args) mut workers := []thread{cap: args.workers} diff --git a/examples/poll_coindesk_bitcoin_vs_usd_rate.v b/examples/poll_coindesk_bitcoin_vs_usd_rate.v index 254e8ac8a80616..10a2bcfc66448f 100644 --- a/examples/poll_coindesk_bitcoin_vs_usd_rate.v +++ b/examples/poll_coindesk_bitcoin_vs_usd_rate.v @@ -7,6 +7,7 @@ import net.http const url = 'https://api.coindesk.com/v1/bpi/currentprice.json' fn main() { + log.use_stdout() mut old_rate := f64(0) for i := u64(1); true; i++ { data := http.get(url) or { diff --git a/examples/veb/websocket/server.v b/examples/veb/websocket/server.v index f6eafefe776544..b776f4b8fb6482 100644 --- a/examples/veb/websocket/server.v +++ b/examples/veb/websocket/server.v @@ -12,6 +12,7 @@ import net.websocket const app_port = 8990 fn main() { + log.use_stdout() mut app := &App{ wss: new_websocker_server()! } @@ -64,6 +65,7 @@ fn wlog(message string) { fn new_websocker_server() !&websocket.Server { mut logger := &log.Log{} logger.set_level(.info) + logger.set_output_stream(os.stderr()) mut wss := websocket.new_server(.ip, app_port, '', logger: logger) wss.set_ping_interval(100) wss.on_connect(fn [mut logger] (mut server_client websocket.ServerClient) !bool { diff --git a/vlib/log/README.md b/vlib/log/README.md index 56ad52917b8627..1239ce029189f9 100644 --- a/vlib/log/README.md +++ b/vlib/log/README.md @@ -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. diff --git a/vlib/log/log.v b/vlib/log/log.v index 3cc0f4b7d0b00e..0ddb0b286f37d2 100644 --- a/vlib/log/log.v +++ b/vlib/log/log.v @@ -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) +}