How to use the logger ? (solved)
# help
k
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 ?
A small example: >
Copy code
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"
generates the output: >
Copy code
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
my Conclusion: the application defines the wanted log.level
logger ::= log.Logger logLevel
the logger is then **chained **to the used 'logging components'
f
You can also set the default logger:
Copy code
import log

main:
  log.set_default (log.default.with_level log.FATAL_LEVEL)
I will update the library documentation.
k
Can I use a specific name in components for logging ?
f
Wait. There are a few mistakes 🙂 Fixing them right now.
fixed.
f
looks good.