fqr.loggers.obj module¶
Loggers objects.
- log = <Logger fqr.loggers.obj (DEBUG)>¶
Centralized application log.
Pre-configured so you do not need to. By default, this loggger will do everything it can to keep your log stream as actionable and free from pollution as possible.
emits neatly formatted JSON log messages
intercepts forgotten print statements
silences them in all deployed environments
intercepts forgotten debug-level logs
silences them in deployed environments > dev
intercepts irritating warnings, displaying them once as neatly formatted warning level log messages
automatically redacts things that should never be logged in the first place (like API Keys, credentials, SSN’s, etc.)
Usage¶
The expectation is this will be the only log used across an application.
Set logging level through the
LOG_LEVELenvironment variable.Defaults to ‘DEBUG’ if
Constants.ENVis eitherlocal(default) ordev, otherwise ‘INFO’.
Special Rules¶
Can only log
str,dict, andObjecttypes.Automatically redacts almost all sensitive data, including api keys, tokens, credit card numbers, connection strings, and secrets.
All
warningswill be filtered through this log and displayed only once.All
printstatements will be silenced except whenConstants.ENVis set to ‘local’ (its default ifENVis unavailable inos.environat runtime).Best practice is to set log level to ‘DEBUG’ and use the
log.debugmethod in place ofprintstatements.warningswill be displayed once for allprintstatements that would otherwise be silenced in any non-local development environment.
Usage Examples¶
import fgr fgr.log.debug('example') # >>> # { # "level": DEBUG, # "time": 2024-02-25 15:30:01.061 UTC, # "log": fgr.core.log, # "data": { # "message": "example" # } # } fgr.log.info({'str': 'example', 'a': 2}) # >>> # { # "level": INFO, # "time": 2024-02-25 15:31:11.118 UTC, # "log": fgr.core.log, # "data": { # "a": 2, # "str": "example" # } # } class Pet(fgr.Object): """A pet.""" id_: fgr.Field[str] _alternate_id: fgr.Field[str] name: fgr.Field[str] type: fgr.Field[str] in_: fgr.Field[str] is_tail_wagging: fgr.Field[bool] = True fgr.log.debug(Pet) # >>> # { # "level": DEBUG, # "time": 2024-02-25 15:30:01.339 UTC, # "log": fgr.core.log, # "data": { # "Pet": { # "_alternate_id": "Field[str]", # "id": "Field[str]", # "in": "Field[str]", # "is_tail_wagging": "Field[bool]", # "name": "Field[str]", # "type": "Field[str]" # } # } # } fgr.log.debug( Pet( id_='abc1234', name='Fido', type='dog', ) ) # >>> # { # "level": DEBUG, # "time": 2024-02-25 15:30:01.450 UTC, # "log": fgr.core.log, # "data": { # "Pet": { # "_alternate_id": null, # "id": "abc1234", # "in": null, # "is_tail_wagging": true, # "name": "Fido", # "type": "dog" # } # } # }