Make the log system easier to use, by simply:
import log
log.info("Hello handy-log!")
- While the builtin
logging.info(msg)
uses theroot
logger to record message,log.info(msg)
can usecurrent module
's logger. Here,current module
means the module inside which you invoked thelog.info(msg)
. You don't have to code like this any more:import logging logger = logging.getLogger(you_package_name) logger.info(your_msg)
- A bunch of predefined formats, handlers, loggers.
- Easy to config, and easy to invoke.
- This is a wrapper for python builtin
logging
system. - Load yaml to dict, then use the
logging.config.dictConfig(config_dict)
to configure the logging system. - When you invoke
log.info(msg)
,handy-log
will first findcurrent module
's logger, and then use thislogger
to log the message.
- Option 1:
Do nothing, use the default configuration. Justimport log
and use it. - Option 2:
- Create your own
handy-log.yaml
in yourcurrent work directory
. - Then just
import log
and use it.
- Create your own
- Option 3:
-
Create your own yaml configuration file.
-
Invoke
log.init(your_config_file)
to configure the logger.This will merge
your_config_file
's content with the builtinhandy-log.yaml
first, then apply the merged configuration to the builtin logging system. -
Then
import log
and use it.
-
- Since the root logger can only be initialized once,
you should invoke
log.init()
before any other logger configuration takes effect. - In the configuration file, loggers and handlers have their independent
logging level
, The message needs to pass through all theselevel
to be recorded.