v/vlib/log
2024-11-27 16:29:13 +03:00
..
common.v fmt: fix alignment of enumeration types (#21999) 2024-08-07 15:46:50 +03:00
default.c.v all: replace usages of C.atexit(cb) with at_exit(cb) or {} (part 2) (#21263) 2024-04-12 13:51:18 +03:00
default.v log: tag log.fatal with @[noreturn] (#22986) 2024-11-27 16:29:13 +03:00
default_test.v log: add support for l.set_short_tag/1 (#20652) 2024-01-25 10:47:00 +02:00
file_log_test.v breaking,checker: disallow initializing private struct fields outside structs module (#21183) 2024-04-12 13:53:02 +03:00
log.v vlib: remove modules/functions/fields, deprecated in 2023 (#22750) 2024-11-17 20:09:21 +02:00
log_test.v log: tag log.fatal with @[noreturn] (#22986) 2024-11-27 16:29:13 +03:00
logger_interface.v log: implement set_always_flush/1 for log.Log, log.ThreadSafeLog and log.Logger (#20698) 2024-02-01 07:51:52 +02:00
README.md doc: update trim_doc_node_description, make module readmes more uniform (#20792) 2024-02-12 12:38:47 +02:00
safe_log.v all: replace fn name '@xxx' with 'xxx' (#22506) 2024-10-12 22:17:02 +03:00

Description

log provides your application logging services. You can log to file or to the console and use different logging levels, so that you are not overwhelmed by the logs.

Basic usage

The log module creates a default Log instance by default, and provides utility functions, that you can use to access it. Note: the default Log instance is thread safe.

That makes it very convenient to use in subsystems, without having to thread a log instance everywhere:

import log

fn abc() {
	log.info('some information')
	log.warn('a warning')
}

// this will not be visible, the default log level is .info:
log.debug('a debug message')

log.set_level(.debug)

// this will be now visible, the log level was changed to .debug:
log.debug('a debug message')

abc()

Advanced usage

You can also create your own log instances, with different options applied to them:

import log

fn main() {
	mut l := log.Log{}
	l.set_level(.info)
	l.set_full_logpath('./info.log')
	l.log_to_console_too()

	l.info('info')
	l.warn('warn')
	l.error('error')
	l.fatal('fatal') // panic, marked as [noreturn]
}