guild icon
Toit
#How to use the logger ? (solved)
Thread channel in help
kaxori
kaxori 07/28/2023 08:01 AM
Where can I find an example or doc to learn the correct usage of the logging ?
The lib doc (https://libs.toit.io/log/library-summary) contains no application example.

What should be done to suppress all the info logs in an application ?
kaxori
kaxori 07/28/2023 09:38 AM
A small example:

`import log

class Component:
logger /log.Logger

constructor
--logger /log.Logger = log.default:

logger
= logger
logger.debug "Component constructed"

use:
logger
.debug "debug"
logger.info "info"
logger
.warn "warning"
logger.error "error"
//logger
.fatal "fatal" // exeption !


main:
5.repeat:
print "\nlog level: $it $(log.level_name it)"
logger ::= log.Logger it log.DefaultTarget --name="test"

component := Component --logger=logger
component.use

print "done"`
(edited)
kaxori
kaxori 07/28/2023 09:39 AM
generates the output:

log level: 0 DEBUG [test] DEBUG: Component constructed [test] DEBUG: debug [test] INFO: info [test] WARN: warning [test] ERROR: error log level: 1 INFO [test] INFO: info [test] WARN: warning [test] ERROR: error log level: 2 WARN [test] WARN: warning [test] ERROR: error log level: 3 ERROR [test] ERROR: error log level: 4 FATAL done
(edited)
kaxori
kaxori 07/28/2023 09:42 AM
my Conclusion:
the application defines the wanted log.level
logger ::= log.Logger logLevel
the logger is then chained to the used 'logging components'
(edited)
floitsch
floitsch 07/28/2023 10:16 AM
You can also set the default logger:
import log main: log.set_default (log.default.with_level log.FATAL_LEVEL)

I will update the library documentation.
kaxori
kaxori 07/28/2023 12:14 PM
Can I use a specific name in components for logging ?
floitsch
floitsch 07/28/2023 12:36 PM
Wait. There are a few mistakes :๐Ÿ™‚:
Fixing them right now.
floitsch
floitsch 07/28/2023 12:37 PM
fixed.
kaxori
kaxori 07/28/2023 02:34 PM
Thank you,
my logging example.
floitsch
floitsch 07/28/2023 03:47 PM
looks good.
12 messages in total