YOUSEFUL / DELPHI / COMPONENTS

TAtlasLogChannel

A logger bound to one category; cheap to copy and to keep in a field.

Record Unit Atlas.Log · Product Atlas Log

Description

Returned by TAtlasLogger.Channel. It has the same logging methods as the logger and adds its category to every event, which SetCategoryLevel thresholds and the {category} token use. It holds a reference to the logger and the category string, nothing else, so create channels freely and keep them in fields. A channel that was never assigned (a zeroed field) does nothing and reports IsEnabled as False. Do not use a channel after its logger is freed.

Members

MemberKindWhat it does
IsEnabledmethodTrue when an event at Level in the channel's category would be logged (the logger's IsEnabled with this category).
LogmethodLogs Template at Level in the channel's category.
LogmethodLogs at Level in the channel's category, filling the template from Args as TAtlasLogger.Log does.
TracemethodLogs Template at llTrace with the channel's category.
TracemethodLogs at llTrace with the channel's category, filling the {name} holes of Template from Args in order and recording each as a property.
DebugmethodLogs Template at llDebug with the channel's category.
DebugmethodLogs at llDebug with the channel's category, filling the {name} holes of Template from Args in order and recording each as a property.
InfomethodLogs Template at llInfo with the channel's category.
InfomethodLogs at llInfo with the channel's category, filling the {name} holes of Template from Args in order and recording each as a property.
WarningmethodLogs Template at llWarning with the channel's category.
WarningmethodLogs at llWarning with the channel's category, filling the {name} holes of Template from Args in order and recording each as a property.
ErrormethodLogs Template at llError with the channel's category.
ErrormethodLogs at llError with the channel's category, filling the {name} holes of Template from Args in order and recording each as a property.
FatalmethodLogs Template at llFatal with the channel's category.
FatalmethodLogs at llFatal with the channel's category, filling the {name} holes of Template from Args in order and recording each as a property.
FailuremethodLogs an exception in the channel's category, as TAtlasLogger.Failure does: class and message go into separate event fields; holes in Template are not filled.
CategorypropertyThe channel's category, as given to TAtlasLogger.Channel.

Properties

Category property

property Category: string read FCategory;

The channel's category, as given to TAtlasLogger.Channel.

Methods

IsEnabled method

function IsEnabled(Level: TAtlasLogLevel): Boolean;

True when an event at Level in the channel's category would be logged (the logger's IsEnabled with this category). False for a channel that was never assigned.

Log method

procedure Log(Level: TAtlasLogLevel; const Template: string); overload;

Logs Template at Level in the channel's category.

Log method

procedure Log(Level: TAtlasLogLevel; const Template: string; const Args: array of const); overload;

Logs at Level in the channel's category, filling the template from Args as TAtlasLogger.Log does.

Trace method

procedure Trace(const Template: string); overload;

Logs Template at llTrace with the channel's category. Text without holes is used as it is.

pascal
Orders.Trace('Entering validation');

Trace method

procedure Trace(const Template: string; const Args: array of const); overload;

Logs at llTrace with the channel's category, filling the {name} holes of Template from Args in order and recording each as a property. See Log for the template rules.

pascal
Orders.Trace('Validating field {field}', ['email']);

Debug method

procedure Debug(const Template: string); overload;

Logs Template at llDebug with the channel's category. Text without holes is used as it is.

pascal
Orders.Debug('Cache rebuilt');

Debug method

procedure Debug(const Template: string; const Args: array of const); overload;

Logs at llDebug with the channel's category, filling the {name} holes of Template from Args in order and recording each as a property. See Log for the template rules.

pascal
Orders.Debug('Cache holds {n} entries', [128]);

Info method

procedure Info(const Template: string); overload;

Logs Template at llInfo with the channel's category. Text without holes is used as it is.

pascal
Orders.Info('Application started');

Info method

procedure Info(const Template: string; const Args: array of const); overload;

Logs at llInfo with the channel's category, filling the {name} holes of Template from Args in order and recording each as a property. See Log for the template rules.

pascal
Orders.Info('Order {id} placed by {customer}', [1042, 'Contoso']);

Warning method

procedure Warning(const Template: string); overload;

Logs Template at llWarning with the channel's category. Text without holes is used as it is.

pascal
Orders.Warning('Disk space is low');

Warning method

procedure Warning(const Template: string; const Args: array of const); overload;

Logs at llWarning with the channel's category, filling the {name} holes of Template from Args in order and recording each as a property. See Log for the template rules.

pascal
Orders.Warning('Stock for {sku} is low: {left} left', ['AX-7', 3]);

Error method

procedure Error(const Template: string); overload;

Logs Template at llError with the channel's category. Text without holes is used as it is.

pascal
Orders.Error('Could not save the settings');

Error method

procedure Error(const Template: string; const Args: array of const); overload;

Logs at llError with the channel's category, filling the {name} holes of Template from Args in order and recording each as a property. See Log for the template rules.

pascal
Orders.Error('Payment {id} was declined', [77]);

Fatal method

procedure Fatal(const Template: string); overload;

Logs Template at llFatal with the channel's category. Text without holes is used as it is.

pascal
Orders.Fatal('Shutting down');

Fatal method

procedure Fatal(const Template: string; const Args: array of const); overload;

Logs at llFatal with the channel's category, filling the {name} holes of Template from Args in order and recording each as a property. See Log for the template rules.

pascal
Orders.Fatal('Database {name} is unreachable; stopping', ['orders']);

Failure method

procedure Failure(E: Exception; const Template: string = ''; Level: TAtlasLogLevel = llError);

Logs an exception in the channel's category, as TAtlasLogger.Failure does: class and message go into separate event fields; holes in Template are not filled.

pascal
on E: Exception do Orders.Failure(E, 'Could not archive the order');

Examples

A channel per service

A class keeps its channel in a field and guards an expensive debug message.

pascal
uses System.SysUtils, Atlas.Log;

type
  TOrderService = class
  private
    FLog: TAtlasLogChannel;
  public
    constructor Create(Logger: TAtlasLogger);
    procedure Place(Id: Integer; const Customer: string);
  end;

constructor TOrderService.Create(Logger: TAtlasLogger);
begin
  inherited Create;
  FLog := Logger.Channel('orders');
end;

procedure TOrderService.Place(Id: Integer; const Customer: string);
begin
  if FLog.IsEnabled(llDebug) then FLog.Debug('Validating order {id}', [Id]);
  FLog.Info('Order {id} placed by {customer}', [Id, Customer]);
end;

TAtlasLogger · TAtlasLogEvent

Also in Atlas Log

TAtlasLogger · TAtlasMemorySink · TAtlasCallbackSink · TAtlasConsoleSink · TAtlasDebugSink · TAtlasFileSink · TAtlasAsyncSink · TAtlasLogView