Skip to content

[Feature Request] Support multiple log handler groups under one logger instance #103

@Embers-of-the-Fire

Description

@Embers-of-the-Fire

Brief

Add support for multiple log handlers to forward log into different log assembly line.

Why?

It's a common senario to print logs to multiple outputs with different config.

Example API

This is merely a simple demonstration; the specific API selection requires further consideration.

Logger logger = Logger();
LoggerHandler fileHandler = LoggerHandler(
  printer: SimplePrinter(),
  filter: ProductionPrinter(LogLevel.Info),
  output: FileOutput("foo.log"),
);
logger.addHandler(fileHandler);
LoggerHandler consoleHandler = LoggerHandler(
  printer: PrefixPrinter(PrettyPrinter()),
  filter: DevelopmentPrinter(LogLevel.Info),
  output: ConsoleOutput(),
);
logger.addHandler(consoleHandler);

And, when calling log functions, e.g. logger.i("hello world!"), the output will be forwarded to both handler.

This could be implemented with two separate Logger with a manager now.

Reference

See python's logging module for more (possible) use cases.

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