1 | import log |
2 | |
3 | fn main() { |
4 | // Note: you *do not* need to create a logger instance, and pass it around, just to use the `log` module. |
5 | // The log module already creates an instance of a thread safe Logger, and utility functions to work with it: |
6 | log.set_level(.debug) |
7 | log.debug('simple debug message') |
8 | log.warn('simple warning message') |
9 | log.info('simple information message') |
10 | log.error('simple error message') |
11 | |
12 | mut l := log.Log{} |
13 | l.set_level(.info) |
14 | // Make a new file called info.log in the current folder |
15 | l.set_full_logpath('./info.log') |
16 | l.log_to_console_too() |
17 | println('Please check the file: ${l.output_file_name} after this example crashes.') |
18 | |
19 | l.info('info') |
20 | l.warn('warn') |
21 | l.error('error') |
22 | l.debug('no output for debug') |
23 | l.set_level(.debug) |
24 | l.debug('debug now') |
25 | l.set_level(log.level_from_tag('INFO') or { log.Level.disabled }) // set level from string, sample |
26 | l.info('info again') |
27 | l.set_level(log.level_from_tag('') or { log.Level.disabled }) // set level from string, sample |
28 | l.error('no output anymore') |
29 | l.fatal('fatal') // panic, next statements won't be executed |
30 | } |