diff --git a/examples/log.v b/examples/log.v index e29ec8b0f3..c7ed77dfe4 100644 --- a/examples/log.v +++ b/examples/log.v @@ -19,6 +19,4 @@ fn main() { l.set_level(log.level_from_tag('') or { log.Level.disabled }) // set level from string, sample l.error('no output anymore') l.fatal('fatal') // panic, next statements won't be executed - l.set_level(.info) - l.warn('warn') } diff --git a/examples/logfatal.v b/examples/logfatal.v new file mode 100644 index 0000000000..3b38241b9d --- /dev/null +++ b/examples/logfatal.v @@ -0,0 +1,11 @@ +import log + +[noreturn] +fn should_not_return(mut logger log.Log) { + logger.fatal('${@FILE_LINE}: yikes!') +} + +fn main() { + mut my_log := log.Log{} + should_not_return(mut my_log) +} diff --git a/vlib/log/log.v b/vlib/log/log.v index b2aba65734..bf3abd7760 100644 --- a/vlib/log/log.v +++ b/vlib/log/log.v @@ -179,6 +179,7 @@ pub fn (mut l Log) send_output(s &string, level Level) { // 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. +[noreturn] pub fn (mut l Log) fatal(s string) { if int(l.level) >= int(Level.fatal) { l.send_output(s, .fatal)