mirror of
https://github.com/vlang/v.git
synced 2025-08-03 09:47:15 -04:00
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:
parent
23c3af8b4d
commit
319eb83525
@ -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 <task_name>')
|
||||
println('Available tasks are: ${all_tasks.keys()}')
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -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..])
|
||||
|
@ -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()))
|
||||
|
@ -22,6 +22,7 @@ fn run(cmd string) os.Result {
|
||||
}
|
||||
|
||||
fn test_retry() {
|
||||
log.use_stdout()
|
||||
log.warn('start...')
|
||||
defer {
|
||||
log.warn('... done')
|
||||
|
@ -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 {
|
||||
|
@ -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}
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user