masonite
masonite copied to clipboard
[5.X] Add `logging` feature
Fix MasoniteFramework/masonite#663.
Specifications
Available drivers are: terminal, single, daily, syslog, slack.
Logging configuration is done in config/logging.py
CHANNELS = {
"default": {
"driver": "console",
# those settings will be applied to each channel if not overriden
"level": "info",
"timezone": "UTC",
"format": "{timestamp} - {levelname}: {message}",
"date_format": "YYYY-MM-DD HH:mm:ss",
},
"console": {
"driver": "terminal",
},
"single": {
"driver": "single",
"path": "logs/single.log",
},
"daily": {
"driver": "daily",
"path": "logs/daily.log",
"days": 7,
"keep": 10,
},
"all": {"driver": "stack", "channels": ["single", "daily", "console"]},
"syslog": {"driver": "syslog", "address": "/var/log/system.log"},
"papertrail": {
"driver": "syslog",
"host": "logs.papertrailapp.com",
"port": None, # specify here the port as an integer
},
"slack": {
"driver": "slack",
"webhook_url": "",
},
}
from masonite.facades import Log
# Log a message to the default configured channel
Log.debug("hello !")
Log.info("hello !")
Log.notice("hello !")
Log.warning("hello !")
Log.critical("hello !")
Log.critical("hello !")
Log.alert("hello !")
Log.emergency("hello !")
# You can change channel on the fly
Log.channel("daily").info("Some message")
# You can stack channels to log a message to multiple channels
Log.stack("console", "daily", "slack").critical("Some message")
Actually Sentry can be used in two different ways. One can add a custom exception handler and use sentry python binding to send the info or there could be a Sentry logging driver, but it would not do much more than the python sentry binding. So what I propose is to maybe create a package for integrating a sentry exception handler a bit like sentry-laravel.
What's left to do
- [x] add
syslog,slackdrivers. - [ ] ensure exceptions are logged with enough information -> needs to work a bit ExceptionHandler code
- [ ] add
propagateoption - [ ] add documentation https://github.com/MasoniteFramework/docs/pull/221
- [x] add catch all listener to log exceptions
great feature and great code looks awesome💥
Nice work @girardinsamuel
This looks exactly like what I was getting at in #663. Functional and flexible.
Keep up the great work. Cheers