Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions src/dodal/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from pathlib import Path
from typing import TypedDict

import colorlog
from bluesky.log import logger as bluesky_logger
from graypy import GELFTCPHandler
from ophyd.log import logger as ophyd_logger
Expand All @@ -26,31 +25,22 @@

# Temporarily duplicated https://github.com/bluesky/ophyd-async/issues/550
DEFAULT_FORMAT = (
"%(log_color)s[%(levelname)1.1s %(asctime)s.%(msecs)03d "
"%(module)s:%(lineno)d] %(message)s"
"%(levelname)1.1s %(asctime)s.%(msecs)03d %(module)s:%(lineno)d] %(message)s"
)

DEFAULT_DATE_FORMAT = "%y%m%d %H:%M:%S"

DEFAULT_LOG_COLORS = {
"DEBUG": "cyan",
"INFO": "green",
"WARNING": "yellow",
"ERROR": "red",
"CRITICAL": "red,bg_white",
}


class ColoredFormatterWithDeviceName(colorlog.ColoredFormatter):
class FormatterWithDeviceName(logging.Formatter):
def format(self, record):
message = super().format(record)
if device_name := getattr(record, "ophyd_async_device_name", None):
message = f"[{device_name}]{message}"
return message


DEFAULT_FORMATTER = ColoredFormatterWithDeviceName(
fmt=DEFAULT_FORMAT, datefmt=DEFAULT_DATE_FORMAT, log_colors=DEFAULT_LOG_COLORS
DEFAULT_FORMATTER = FormatterWithDeviceName(
fmt=DEFAULT_FORMAT, datefmt=DEFAULT_DATE_FORMAT
)


Expand Down
Loading