Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.X] Add logging feature #718

Merged
merged 19 commits into from
Jul 5, 2024
Merged

Conversation

girardinsamuel
Copy link
Contributor

@girardinsamuel girardinsamuel commented Oct 10, 2022

Fix #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

  • add syslog, slack drivers.
  • ensure exceptions are logged with enough information -> needs to work a bit ExceptionHandler code
  • add propagate option
  • add documentation Add logging feature docs#221
  • add catch all listener to log exceptions

@BSN4
Copy link
Contributor

BSN4 commented Oct 11, 2022

great feature and great code looks awesome💥

@girardinsamuel girardinsamuel added the Next Minor Non-breaking change that can go into the next minor version label Oct 13, 2022
@girardinsamuel girardinsamuel marked this pull request as draft October 13, 2022 12:45
@circulon
Copy link
Contributor

Nice work @girardinsamuel

This looks exactly like what I was getting at in #663.
Functional and flexible.

Keep up the great work.
Cheers

@girardinsamuel girardinsamuel added Next Major Only and removed Next Minor Non-breaking change that can go into the next minor version labels Oct 22, 2022
@girardinsamuel girardinsamuel changed the base branch from 4.0 to 5.0 October 22, 2022 17:32
@girardinsamuel girardinsamuel changed the title Add logging feature [5.X] Add logging feature Nov 1, 2022
@girardinsamuel girardinsamuel changed the base branch from 5.0 to 5.x November 1, 2022 14:17
@josephmancuso josephmancuso marked this pull request as ready for review March 12, 2024 22:51
@josephmancuso josephmancuso changed the base branch from 5.x to 4.0 June 30, 2024 15:41
@eaguad1337 eaguad1337 self-assigned this Jul 4, 2024
@eaguad1337 eaguad1337 added this to the Masonite 5 milestone Jul 4, 2024
@eaguad1337 eaguad1337 merged commit 8e83cf7 into MasoniteFramework:4.0 Jul 5, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add logging feature with different logging handlers
4 participants