log #
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.
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.
interface Logger #
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
enum Level #
enum Level {
disabled = 0
fatal
error
warn
info
debug
}
Level defines possible log levels used by Log
enum LogTarget #
enum LogTarget {
console
file
both
}
LogTarget defines possible log targets
struct Log #
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) 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 #
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.