Skip to content
Michael Justin edited this page Feb 8, 2016 · 25 revisions

Usage

Register a specific implementation

To register a specific logging framework, just add one of the djLogOver... units to the project.

Available binding units:

  • djLogOverLog4D for logging over Log4D
  • djLogOverLazLogger for logging over LazLogger
  • djLogOverSimpleLogger for logging over SimpleLogger (included)
  • djLogOverNOPLogger for logging over NOPLogger (included)

Example

program HelloWorld;

uses
  djLogOverLazLogger, djLogAPI, djLoggerFactory;

var
  Logger: ILogger;

begin
  Logger := TdjLoggerFactory.GetLogger('demo');
  Logger.Info('Hello World');

  WriteLn('hit any key');
  ReadLn;
end. 

djLogOverLog4D

This unit will register Log4D as the logging framework. Configuration of Log4D must be applied as usual, either by invoking file based configuration, or by setting properties in application code (or both). See Logging over Log4D for details.

djLogOverLazLogger

This unit will register LazLogger as logging framework. See Logging over LazLogger for details.

djLogOverSimpleLogger

This unit will register SimpleLogger as the logging framework. See SimpleLogger for details.

djLogOverNOPLogger

This unit will register NOPLogger as logging framework. NOPLogger actually does nothing, so it is equivalent to disabling logging for the program, and removing dependencies (except on SLF4P).

Create loggers where needed

unit UnitA;
interface
uses 
   ...
   djLogAPI, djLoggerFactory;
type
  TMyMainClass = class(TObject)
  private
    Logger: ILogger;
    ...
  public
    constructor Create;
    ...
  end;
  ...
constructor TMyMainClass.Create;
begin
  inherited;
  
  Logger := TdjLoggerFactory.GetLogger('main.Logger');
  Logger.Trace('Creating instance of TMyMainClass.');
  ...
end;

Log output:

42 TRACE main.Logger - Creating instance of TMyMainClass.
Clone this wiki locally