Catalog · How the catalog works
Mir-Logger
Mir-Logger is a Mir framework logging library with configurable levels, colored console output, and file logging.
- ★ 1 on GitHub
Anyone may press Interesting, signed in or not. It helps others find this project.
README
Logging Example
The logger is not part of the framework core. It lives in the example application as an external-style dependency registered by the application bootstrap.
Units:
Mir-Logger/Logger.Port.pas
Mir-Logger/Logger.Options.pas
Mir-Logger/Logger.pasPort
ILogger = interface
procedure Log(const Level: TLogLevel; const Message: string);
procedure Debug(const Message: string);
procedure Info(const Message: string);
procedure Warning(const Message: string);
procedure Error(const Message: string);
end;Log levels
Logger.Port.pas defines:
TLogLevel = (llDebug, llInfo, llWarning, llError);Logger.Options.pas maps string values from configuration to this enum.
Valid configured values:
DebugInfoWarningError
Values are normalized using trim and uppercase comparison.
Options
TLoggerOptions is an example options section:
type
TLoggerOptions = class(TOptionsSection)
private
FLogLevel: string;
FFilePath: string;
function GetSectionName: string; override;
public
property LogLevel: string read FLogLevel write FLogLevel;
property FilePath: string read FFilePath write FFilePath;
end;The section name is defined by GetSectionName:
function TLoggerOptions.GetSectionName: string;
begin
Result := 'Logger';
end;The root app config must contain:
{
"Logger": {
"LogLevel": "Info",
"FilePath": "./Logs/App.log"
}
}Registration
The framework does not register the logger by default. The example application registers TLogger and its options in dpr or bootstrap unit:
App.AddOptions<TLoggerOptions>;
App.AddSingleton<ILogger, TLogger>;TLogger receives its configuration through constructor injection:
constructor TLogger.Create(const AOptions: IOptions<TLoggerOptions>);Behavior
TLogger writes to:
- console, with ANSI colors by level;
- file, using the configured
FilePath.
It validates:
LogLevelis present;FilePathis present;- the log file path is valid;
- the log file can be opened.
Writes are synchronized using TCriticalSection.

