Skip to content

Latest commit

 

History

History
63 lines (48 loc) · 2.44 KB

02_logging.md

File metadata and controls

63 lines (48 loc) · 2.44 KB

1. Logging

1.1. Customize

It is very easy to customize the configuration of the Logger provided by the Batch.dart to suit your preferences.

Just pass the LogConfiguration object to the constructor when instantiating the BatchApplication as below.

BatchApplication(
  logConfig: LogConfiguration(
    // Change log level to debug.
    level: LogLevel.debug,
  ),
);

Also, the logging feature can be freely customized by inheriting the following abstract classes and setting them in the LogConfiguration.

Description
LogFilter This is the layer that determines whether log output should be performed. By default, only the log level is determined.
LogPrinter This layer defines the format for log output.
LogOutput This is the layer that actually performs the log output. By default, it outputs to the console.

1.1.2. LogOutput

Description
ConsoleLogOutput Provides features to output log to console. This filter is used by default.
FileLogOutput Provides features to output the log to the specified file.
MultiLogOutput Allows multiple log outputs. This is useful, for example, when you want to have console output and file output at the same time.

Example

BatchApplication(
  logConfig: LogConfiguration(
    output: ConsoleLogOutput(),
  ),
);

With MultiLogOutput

BatchApplication(
  logConfig: LogConfiguration(
    output: MultiLogOutput([
      ConsoleLogOutput(),
      FileLogOutput(file: File('./test.txt')),
    ]),
  ),
);