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

Formatting message does not work #190

Open
hemanthactionfi opened this issue Jun 2, 2022 · 0 comments
Open

Formatting message does not work #190

hemanthactionfi opened this issue Jun 2, 2022 · 0 comments

Comments

@hemanthactionfi
Copy link

hemanthactionfi commented Jun 2, 2022

While trying to truncate the message part using formatter. fluent.handler.FluentRecordFormatter works normally with all fields except message

configuration

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'verbose': {
            'format': "[%(levelname)s %(asctime)s %(module)s -> %(lineno)d] %(message)s",
            'datefmt': "%Y-%b-%d %H:%M:%S"
        },
        'console': {
            'format': '[%(levelname)s %(asctime)s] %(message)s',
            'datefmt': "%Y-%b-%d %H:%M:%S"
        },
        'fluent_fmt': {
            '()': "fluent.handler.FluentRecordFormatter",
            'format': {
                'lvl': '%(levelname)s',
                'host': '%(hostname)s',
                'mod': '%(module)s',
                'line': '%(lineno)d',
                'tms': '%(created)d',
                'trace': '%(exc_text)s',
                "proc": '%(processName)s',
                "message": "%(message).5s"
            }
        },
    },
    'handlers': {
        'console': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose'
        },
        'file': {
            'level': 'INFO',
            'class': 'logging.handlers.TimedRotatingFileHandler',
            'filename': 'celery_nohup',
            'when': 'D',  # this specifies the interval
            'interval': 1,  # defaults to 1, only necessary for other values
            'formatter': 'verbose',
        },
        'fluentd': {
            'level': 'INFO',
            'class': 'fluent.handler.FluentHandler',
            'formatter': 'fluent_fmt',
            'tag': 'default.log',
            'host': 'localhost',
            'port': 24224,
            'timeout':3.0,
            'verbose': False,
            "msgpack_kwargs":{'default' : str}
        }, 

    },
    'loggers': {
        'django': {
            'handlers': ['console'],
            'level': "INFO",
            'propagate': True,
        },
        'celery': {
            'handlers': ['console', 'fluentd'],
            'level': "INFO",
            'propagate': True,
        },
        'ap_scheduler': {
            'handlers': ['console', 'fluentd'],
            'level': "INFO",
            'propagate': True,
        },
    },
}

expected output: message truncated to 5 characters
fluentd_1 | 2022-06-02 18:58:43.000000000 +0000 default.log: {"lvl":"INFO","host":"E7440","mod":"mingle","line":"40","tms":"1654196323","trace":"None","proc":"MainProcess","message":"mingl"}

obtained output
fluentd_1 | 2022-06-02 18:58:43.000000000 +0000 default.log: {"lvl":"INFO","host":"E7440","mod":"mingle","line":"40","tms":"1654196323","trace":"None","proc":"MainProcess","message":"mingle: searching for neighbors"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant