Skip to content

Unable to change message format in SEQ #86

@matt-amwins

Description

@matt-amwins

Despite multiple attempts, I am unable to get the message formatting to match the style being used by the console. When I inspect the log formatter while debugging, I can see that the format looks correct. However, the message still comes up in SEQ with the default formatting. Appreciate any help.

Init File

import logging.handlers
import logging.config
import logging
from pathlib import Path
from copy import deepcopy
import socket
import seqlog
import yaml

def configure_logging(app, name=None):
    config = app.config
    try:
        logging.raiseExceptions = config["ENV"] in ["development", "local"]
        log_config = get_log_config_dict()
        log_config["handlers"]["seq"]["server_url"] = config.get("SEQ_SERVER_URL")
        log_config["handlers"]["seq"]["api_key"] = config.get("SEQ_API_KEY")
        seqlog.configure_from_dict(log_config, override_root_logger=True, use_structured_logger=True, support_extra_properties=True, support_stack_info=True, use_clef=False)
        seqlog.set_global_log_properties(
            Application="AMI",
            Environment=config.get("ENV", "development"),
            Hostname=socket.gethostname()
        )
        seqlog.set_callback_on_failure(
            lambda e: logging.exception('Failure occurred during log submission', exc_info=e),
        )
        logging.info("Seq logging configured")
        return logging.getLogger(name) or logging.getLogger()
    except Exception as e:
        print(f"Error configuring Seq logging: {e}")
        return logging.getLogger()

def get_log_config_dict():
    with open('log_config.yml', 'r') as log_config_file:
        return yaml.safe_load(log_config_file.read())

Logging Config

version: 1

disable_existing_loggers: True

root:
  level: INFO
  handlers:
  - console
  - seq

loggers:
  CELERY:
    level: INFO
    handlers:
    - console
    - seq
    propagate: no

handlers:
  console:
    class: seqlog.structured_logging.ConsoleStructuredLogHandler
    formatter: standard

  seq:
    class: seqlog.structured_logging.SeqLogHandler
    formatter: standard
    server_url: ''
    api_key: ''
    batch_size: 10
    auto_flush_timeout: 10

formatters:
  standard:
    format: '[%(asctime)s] - [%(process)d] [%(levelname)s]: %(filename)s %(funcName)s (%(lineno)d): %(message)s'
    datefmt: '%Y-%m-%d %H:%M:%S'
    style: '%'

Result

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions