Formatting message does not work

Open
#190 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python

Research direction

Start at fluent.handler.FluentRecordFormatter and reproduce the supplied logging configuration, comparing its handling of the message field with the other formatted fields. Done means the configured "%(message).5s" value is emitted as five characters in the Fluentd output, with a regression test covering the behavior.

Written by the indexing model from the issue text.

Description

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"}

Dominant language
Python
Stars
457
Forks
138
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from fluent/fluent-logger-python

All issues in fluent/fluent-logger-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.