Skip to content

Logger

Logging is always a heated subject. You should definitely have it, but how? Some prefere relying on existing libraries.

Among those we are aware of, we can vouch for

  • loguru, user friendly logging, period 😊.
  • icecream, more for debugging purposes as they advocate themselves

Our solution is more similar to loguru, but without the additional dependency.

How to use logging?

Vanilla log

Simply put on top of all of your modules

from ecodev_core import logger_get

log = logger_get(__name__)

Afterwards, you use log as you would use it normally: log.info('info'), log.critical('critical')... The benefits of using the ecodev_core logger can hopefully be illustrated in the next image

logger example

Benefits of using ecodev_core logger

As you can see, you get out of the box

  • colors
  • datetime
  • ppid
  • the name of the method and module where the log sits, alongside with the exact code line
  • the actual message

In production, the colors prove invaluable when scanning big chunk of logs (yes, we can improve on the automatic log treatment side 😊). Same goes for where the log was generated.

log_critical

sometimes you want to log an error inside a try except. This you can accomplish in the following manner

from ecodev_core import logger_get

log = logger_get(__name__)

log_critical("something terrible happened", log)

log critical

Benefits of using ecodev_core log_critical

This proves particularly useful in Dash applications, where by default if do not use this logger you get very uninformative messages

log critical

Sometimes dash is not really nice