Module log stdlib

log
Version:
0.3.3
License:
MIT
Dependencies from vmod:
0
Imports:
3
Imported by:
1
Repository:
OS-specific
Show selected OS-specific symbols.
Backend-specific
Show selected Backend-specific symbols.

Dependencies defined in v.mod

This section is empty.

Imports

Imported by

Overview

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.

Aliases

This section is empty.

Constants

This section is empty.

Sum types

This section is empty.

Functions

#fn level_from_tag

fn level_from_tag(tag string) ?Level

level_from_tag returns the log level from the given string if it matches.

#fn target_from_label

fn target_from_label(label string) ?LogTarget

target_from_label returns the log target from the given string if it matches.

Structs

#struct Log

pub struct Log {
mut:
	level         Level
	output_label  string
	ofile         os.File
	output_target LogTarget // output to console (stdout/stderr) or file or both.
pub mut:
	output_file_name string // log output to this file
}

Log represents a logging object

#fn (&Log) get_level

fn (mut l &Log) get_level() Level

get_level gets the internal logging level.

#fn (&Log) set_level

fn (mut l &Log) set_level(level Level)

set_level sets the internal logging to level.

#fn (&Log) set_output_level

fn (mut l &Log) set_output_level(level Level)

set_output_level sets the internal logging output to level.

#fn (&Log) set_full_logpath

fn (mut l &Log) set_full_logpath(full_log_path string)

set_full_logpath sets the output label and output path from full_log_path.

#fn (&Log) set_output_label

fn (mut l &Log) set_output_label(label string)

set_output_label sets the label for the output.

#fn (&Log) set_output_path

fn (mut l &Log) set_output_path(output_file_path string)

set_output_path sets the file to which output is logged to.

#fn (&Log) log_to_console_too

fn (mut l &Log) log_to_console_too()

log_to_console_too turns on logging to the console too, in addition to logging to a file.

You have to call it after calling .set_output_path(output_file_path).

#fn (&Log) flush

fn (mut l &Log) flush()

flush writes the log file content to disk.

#fn (&Log) close

fn (mut l &Log) close()

close closes the log file.

#fn (&Log) log_file

fn (mut l &Log) log_file(s string, level Level)

log_file writes log line s with level to the log file.

#fn (&Log) log_cli

fn (l &Log) log_cli(s string, level Level)

log_cli writes log line s with level to stdout.

#fn (&Log) send_output

fn (mut l &Log) send_output(s &string, level Level)

send_output writes log line s with level to either the log file or the console according to the value of the .output_target field.

#fn (&Log) fatal

noreturn
fn (mut l &Log) fatal(s string)

fatal logs line s via send_output if Log.level is greater than or equal to the Level.fatal category.

Note that this method performs a panic at the end, even if log level is not enabled.

#fn (&Log) error

fn (mut l &Log) error(s string)

error logs line s via send_output if Log.level is greater than or equal to the Level.error category.

#fn (&Log) warn

fn (mut l &Log) warn(s string)

warn logs line s via send_output if Log.level is greater than or equal to the Level.warn category.

#fn (&Log) info

fn (mut l &Log) info(s string)

info logs line s via send_output if Log.level is greater than or equal to the Level.info category.

#fn (&Log) debug

fn (mut l &Log) debug(s string)

debug logs line s via send_output if Log.level is greater than or equal to the Level.debug category.

Interfaces

#interface Logger

pub interface Logger {
mut:
	fatal(s string)
	error(s string)
	warn(s string)
	info(s string)
	debug(s string)
	set_level(level Level)
}

Logger is an interface that describes a generic Logger

Enums

#enum Level

pub enum Level {
	disabled = 0
	fatal
	error
	warn
	info
	debug
}

Level defines possible log levels used by Log

#enum LogTarget

pub enum LogTarget {
	console
	file
	both
}

LogTarget defines possible log targets