log4v
Logging framework for V.
For changes and release notes, see CHANGELOG.
Setup and run
Get the module via vpm
:
v install smartiniOnGitHub.log4v
then use by importing it. Note that some stuff has to be imported from v 'log' module.
Examples
Examples can be found it the /examples
directory.
Requirements
Latest V (vlang) stable, or built from latest sources.
Sources
Source code is all inside main repo: log4v.
Documentation generated from source code (library API): here.
Note
In the code, there are references to V integrated 'log' module, for better compliance and reuse of existing code.
Current setup (and related commands) are for a Linux system, but can be updated for other platforms (Mac, Windows, etc).
Contributing
- Fork it ( https://github.com/smartiniOnGitHub/log4v/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
License
Licensed under Apache-2.0.
Constants #
const version = '0.1'
version library version
const messages_buffer_default = 1000
fn format_message_default #
fn format_message_default(name string, s string, level Level) string
format_message_default format the given log name/context name
, message s
and level level
with the log format set in the logger
This is default implementation of LogFormatter for Log4v formatter.
inlined for better performances
fn level_from_string #
fn level_from_string(s string) ?Level
level_from_string returns the log level from the given string if matches This function calls 'level_from_tag' in log module, for better compliance and reuse of code.
fn new_log4v #
fn new_log4v() &Log4v
new_log4v create and return a new Log4v instance start must be called manually to let the instance process log messages
fn new_log4v_as_logger #
fn new_log4v_as_logger() (&Logger, thread)
new_log4v_as_logger create, start and return a new mutable Log4v instance, as a generic Logger implementation
fn new_log4v_as_logger_full_start #
fn new_log4v_as_logger_full_start(name string, level Level, formatter LogFormatter, messages_buffer_len int) (&Logger, thread)
new_log4v_as_logger_full_start create, start and return a new mutable Log4v instance, as a generic Logger implementation
fn new_log4v_full #
fn new_log4v_full(name string, level Level, formatter LogFormatter, messages_buffer_len int) &Log4v
new_log4v_full create and return a new Log4v instance by specifying some logger settings start must be called manually to let the instance process log messages
fn new_log4v_full_start #
fn new_log4v_full_start(name string, level Level, formatter LogFormatter, messages_buffer_len int) (&Log4v, thread)
new_log4v_full_start create, start and return a new mutable Log4v instance by specifying some logger settings
type LogFormatter #
type LogFormatter = fn (name string, text string, level Level) string
LogFormatter defines a generic log formatter function
struct Log4v #
struct Log4v {
formatter LogFormatter = format_message_default
// appender LogAppender[] TODO: ...
mut:
level Level = .info
name string
ch chan string
processed_tot u64
}
Log4v represents a log manager
fn (Log4v) get_level #
fn (mut l Log4v) get_level() Level
get_level gets the internal logging level
fn (Log4v) set_level #
fn (mut l Log4v) set_level(level Level)
set_level sets the internal logging to level
fn (Log4v) flush #
fn (mut l Log4v) flush()
flush writes the log file content to disk
fn (Log4v) close #
fn (mut l Log4v) close()
close closes log channel and appenders resources
fn (Log4v) close_stop #
fn (mut l Log4v) close_stop(t thread)
close_stop closes log channel and appenders resources and stop processing messages thread and others (if any)
fn (Log4v) start #
fn (mut l Log4v) start()
start get (process) log messages from logger channel and send to all log appenders It must be called asynchronously
fn (Log4v) fatal #
fn (mut l Log4v) fatal(s string)
fatal logs the given message 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 (Log4v) error #
fn (mut l Log4v) error(s string)
error logs the given message if Log.level
is greater than or equal to the Level.error
category
fn (Log4v) warn #
fn (mut l Log4v) warn(s string)
warn logs the given message if Log.level
is greater than or equal to the Level.warn
category
fn (Log4v) info #
fn (mut l Log4v) info(s string)
info logs the given message if Log.level
is greater than or equal to the Level.info
category
fn (Log4v) debug #
fn (mut l Log4v) debug(s string)
debug logs the given message if Log.level
is greater than or equal to the Level.debug
category
fn (Log4v) trace #
fn (mut l Log4v) trace(s string)
trace logs the given message if Log.level
is greater than or equal to the Level.debug
category logging level here is the same of debug (a new '.trace' level is not really needed) but note that this function is available only when compiling with the 'debug' flag
fn (Log4v) print_processed_log_messages #
fn (mut l Log4v) print_processed_log_messages()
processed_log_messages return the total number of log messages processed since started but note that this function is available only when compiling with the 'debug' flag