Comprehensive Logging with mORMot 2 on Delphi and FPC

ArnaudBouchez1 27 views 76 slides Oct 29, 2025
Slide 1
Slide 1 of 76
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76

About This Presentation

The logging feature of mORMot is worth investigating for any Delphi or FPC project, even if you do not need any other part of the library. This session will present what makes mORMot unique in the modern object Pascal scene.

Hands-On

How to use only some part of the mORMot 2 toolbox
Genera...


Slide Content

Comprehensive Logging
with mORMot 2
The more logs…
the better

Welcome
Arnaud Bouchez
•Open Source Founder
• mORMot 1, mORMot 2, SynPDF, dmustache
•Modern Object Pascal
Delphi and FPC -Embarcadero MVP
•Synopse Tranquil IT
https://synopse.info https://tranquil.it

Welcome
Arnaud Bouchez
•Open Source Founder
• mORMot 1, mORMot 2, SynPDF, dmustache
•Modern Object Pascal
Delphi and FPC -Embarcadero MVP
•Synopse Tranquil IT
https://synopse.info https://tranquil.it

Comprehensive Logging

Comprehensive Logging
with mORMot 2

Hands On
•Use only some part of mORMot 2
•General best-practices about logging
•Server-side logging particularities
•A cross-compiler/platform journey

Today’s Special
•TSynLogclass or instance
•The LogViewertool
•Advanced features
•Logging with love

Today’s Special
•TSynLogclass or instance
•The LogViewertool
•Advanced features
•Logging with love
Showing actual code

Today’s Special
•TSynLogclass or instance
•The LogViewertool
•Advanced features
•Logging with love

mORMot Logs

mORMot Logs
•Application Logs
•HTTP Logs
•SOA Audit Trail

mORMot Logs
•Application Logs
•HTTP Logs
•SOA Audit Trail
calls into SQlite3 DB

mORMot Logs
•Application Logs
•HTTP Logs

mORMot Logs
•Application Logs
plain UTF-8 text format
•HTTP Logs
“combined” format

mORMot Logs
•Application Logs
TSynLog
•HTTP Logs
THttpLogger

mORMot Logs
•Application Logs
TSynLog

TSynLog
•Class-driven
(not Instance-driven)
•Several families
(each with its own children)

TSynLog
•Class-driven
(not Instance-driven)
•Several families
(each with its own loggers)

TSynLogSub-Classes

TSynLogSub-Classes
TMySynLog= class(TSynLog)
•Its own TMySynLog.Family
•Its own log file(s) on disk

TSynLog
•TSynLog.Family
Per-class settings
•TSynLog.Add
Logger instance

TSynLog.Family
TSynLogFamily.Level
asetof levels
not a single level

TSynLog.Family
Most common app logging:
TRACE,DEBUG,INFO,WARN,ERROR

TSynLog.Family
Most common app logging:
TRACE,DEBUG,INFO,WARN,ERROR
less critical …… most critical

TSynLog.Family
Most common app logging:
TRACE,DEBUG,INFO,WARN,ERROR
most verbose …… less verbose

TSynLog.Family.Level
TSynLogLevels= set of TSynLogLevel;

TSynLog.Family.Level
TSynLogLevel= (sllNone, sllInfo, sllDebug, sllTrace,
sllWarning, sllError, sllEnter, sllLeave, sllLastError,
sllException, sllExceptionOS, sllMemory,
sllStackTrace, sllFail, sllSQL, sllCache, sllResult,
sllDB, sllHTTP, sllClient, sllServer, sllServiceCall,
sllServiceReturn, sllUserAuth, sllCustom1,
sllCustom2, sllCustom3, sllCustom4, sllNewRun,
sllDDDError, sllDDDInfo, sllMonitoring);

App logic Levels
TSynLogLevel= (sllNone, sllInfo, sllDebug, sllTrace,
sllWarning, sllError, sllEnter, sllLeave, sllLastError,
sllException, sllExceptionOS, sllMemory,
sllStackTrace, sllFail, sllSQL, sllCache, sllResult,
sllDB, sllHTTP, sllClient, sllServer, sllServiceCall,
sllServiceReturn, sllUserAuth, sllCustom1,
sllCustom2, sllCustom3, sllCustom4, sllNewRun,
sllDDDError, sllDDDInfo, sllMonitoring);

OS Errors Levels
TSynLogLevel= (sllNone, sllInfo, sllDebug, sllTrace,
sllWarning, sllError, sllEnter, sllLeave, sllLastError,
sllException, sllExceptionOS,sllMemory,
sllStackTrace, sllFail, sllSQL, sllCache, sllResult,
sllDB, sllHTTP, sllClient, sllServer, sllServiceCall,
sllServiceReturn, sllUserAuth, sllCustom1,
sllCustom2, sllCustom3, sllCustom4, sllNewRun,
sllDDDError, sllDDDInfo, sllMonitoring);

Advanced Levels
TSynLogLevel= (sllNone, sllInfo, sllDebug, sllTrace,
sllWarning, sllError, sllEnter, sllLeave, sllLastError,
sllException, sllExceptionOS, sllMemory,
sllStackTrace, sllFail, sllSQL, sllCache, sllResult,
sllDB, sllHTTP, sllClient, sllServer, sllServiceCall,
sllServiceReturn, sllUserAuth, sllCustom1,
sllCustom2, sllCustom3, sllCustom4, sllNewRun,
sllDDDError, sllDDDInfo, sllMonitoring);

Toolbox Levels
TSynLogLevel= (sllNone, sllInfo, sllDebug, sllTrace,
sllWarning, sllError, sllEnter, sllLeave, sllLastError,
sllException, sllExceptionOS, sllMemory,
sllStackTrace, sllFail, sllSQL, sllCache, sllResult,
sllDB, sllHTTP, sllClient, sllServer, sllServiceCall,
sllServiceReturn, sllUserAuth, sllCustom1,
sllCustom2, sllCustom3, sllCustom4, sllNewRun,
sllDDDError, sllDDDInfo, sllMonitoring);

Custom Levels
TSynLogLevel= (sllNone, sllInfo, sllDebug, sllTrace,
sllWarning, sllError, sllEnter, sllLeave, sllLastError,
sllException, sllExceptionOS, sllMemory,
sllStackTrace, sllFail, sllSQL, sllCache, sllResult,
sllDB, sllHTTP, sllClient, sllServer, sllServiceCall,
sllServiceReturn, sllUserAuth, sllCustom1,
sllCustom2, sllCustom3, sllCustom4, sllNewRun,
sllDDDError, sllDDDInfo, sllMonitoring);

Profiling Levels
TSynLogLevel= (sllNone, sllInfo, sllDebug, sllTrace,
sllWarning, sllError, sllEnter, sllLeave, sllLastError,
sllException, sllExceptionOS, sllMemory,
sllStackTrace, sllFail, sllSQL, sllCache, sllResult,
sllDB, sllHTTP, sllClient, sllServer, sllServiceCall,
sllServiceReturn, sllUserAuth, sllCustom1,
sllCustom2, sllCustom3, sllCustom4, sllNewRun,
sllDDDError, sllDDDInfo, sllMonitoring);

TSynLog.Family
TSynLogFamily.Level
a setof levels
to rule them all

TSynLog.Add
TSynLoginstance
•Map a log file on disk
•Host of the Log() methods

TSynLog.Log()
TSynLog.Log() overloads
•Thread-safe and very efficient
•UTF-8/JSON serialization
•Formatting with % place holder

TSynLog.Log()
TSynLog.Log() overloads
•Thread-safe and very efficient
•UTF-8/JSON serialization
•Formatting with % place holder
(not %s %d with runtime errors)

TSynLog.Log()
procedure TSomeClass.SomeMethod(a: integer);
begin
TSynLog.Add.Log(sllTrace,'SomeMethoda=%',[a],self);
// do some stuff
if error <> '' then
TSynLog.Add.Log(sllError, 'SomeMethodfailed as %',
[error], self);
end;

TSynLog.Log()
procedure TSomeClass.SomeMethod(a: variant);
begin
try
// do some stuff
except
on E: Exception do
TSynLog.Add.Log(sllError, 'SomeMethod(%) raised %',
[a, E], self);
end;

ISynLog
TSynLog.Enter/EnterLocal
•Return an ISynLoginstance
•Simple Method profiling
•Regular ISynLog.Add() methods

ISynLog
procedure TSomeClass.DoIt(param: TSomeObject)
varlog: ISynLog; // local variable
begin
log := TSynLog.Enter(self, 'DoIt');
// do some stuff
if Assigned(log) then// may be nil if no sllEnter
log.Log(sllInfo, 'DoItcalled as %', [param], self);
end; // when log is out-of-scope, log the method leaving

ISynLog
procedure TSomeClass.DoIt(param: TSomeObject)
varlog: ISynLog;
begin
TSynLog.EnterLocal(log, self, 'DoIt'); // slightly faster
// do some stuff
if Assigned(log) then// may be nil if no sllEnter
log.Log(sllInfo, 'DoItcalled as %', [param], self);
end; // when log is out-of-scope, log the method leaving

ISynLog
procedure TSomeClass.DoIt(param: TSomeObject)
begin
TSynLog.Enter(self, 'DoIt');// returns an ISynLog
// do some stuff
end; // when ISynLogis out-of-scope, log the method leaving

ISynLog
procedure TSomeClass.DoIt(param: TSomeObject)
begin
TSynLog.Enter(self, 'DoIt');
// do some stuff
end; // when ISynLogis out-of-scope, log the method leaving

ISynLog
procedure TSomeClass.DoIt(param: TSomeObject)
begin
TSynLog.Enter(self, 'DoIt');
// do some stuff
end; // ISYNLOG RELEASED NOW
WARNING: SCOPE IS AT METHOD ENDINGWITH OLDDELPHI

ISynLog
procedure TSomeClass.DoIt(param: TSomeObject)
begin
TSynLog.Enter(self, 'DoIt');
// ISYNLOG RELEASED NOW
// do some stuff
end;
WARNING: SCOPE IS ASAP/LOCALWITH FPCOR LATESTDELPHI

ISynLog
procedure TSomeClass.DoIt(param: TSomeObject)
varlog: ISynLog; // use local varon modern Delphi or FPC
begin
TSynLog.EnterLocal(log, self, 'DoIt');
// do some stuff
if Assigned(log) then// may be nil if no sllEnter
log.Log(sllInfo, 'DoItcalled as %', [param], self);
end; // when log is out-of-scope, log the method leaving

TSynLogClass or Instance
SHOW ME THE CODE !

Today’s Special
•TSynLogclass or instance
•The LogViewertool
•Advanced features
•Logging with love

LogViewer

LogViewer
•VCL/LCL Open Source Tool

LogViewer
•VCL/LCL Open Source Tool
•Map the file in memory

LogViewer
•VCL/LCL Open Source Tool
•Map the file in memory
•Index/search/filter/view

LogViewer
•VCL/LCL Open Source Tool
•Map the file in memory
•Index/search/filter/view
•Thread oriented

LogViewer
SHOW ME THE CODE !
SHOW ME THE TOOL !

Today’s Special
•TSynLogclass or instance
•The LogViewertool
•Advanced features
•Logging with love

Advanced Features

Advanced Features
•Integrated in whole Framework
•Optimized Generation
•TSynLogFamilyproperties
•Cross-OS and Cross-Compiler

Advanced Features
•Integrated in whole Framework
•Network/socket/http process
•REST/SOA calls
•Database queries (SQL/NoSQL)

Advanced Features
•Integrated in whole Framework
•Network/socket/http process
•REST/SOA calls
•Database queries (SQL/NoSQL)
BUILT-IN !

Advanced Features
Optimized Generation
•Full rewrite in latest mORMot 2
•No transient memory allocation
•Validated on production servers

Advanced Features
Optimized Generation
•TSynLogThreadInfo
•Buffered output
•Fast UTF-8/JSON serialization
•“Fake” ISynLog

Advanced Features
TSynLogFamilyproperties
•Log File Content
•Log File Lifetime

Log File Content
•HighResolutionTimestamp
•PerThreadLog
•BufferSize
•LevelSysInfo
•AutoFlushTimeOut

Log File Lifetime
•Log Rotation
•Log Archival
•Console Logging
•Remote Logging

Advanced Features
Cross-OS and Cross-Compiler
•Efficient OS API calls
•Delphi and FPC
•Leverage mormot.core.os/rtti

Advanced Features
SHOW ME THE CODE !

Today’s Special
•TSynLogclass or instance
•The LogViewertool
•Advanced features
•Logging with love

Logging For You

Logging For You
•Exception logging

Logging For You
•Exception logging
•Production profiling

Logging For You
•Exception logging
•Production profiling
•Low performance overhead

Logging For You
•Exception logging
•Production profiling
•Low performance overhead
•Built-in SOA and DB integration

Today’s Special
•TSynLogclass or instance
•The LogViewertool
•Advanced features
•Logging with love

To Visit the marmots
https://cauterets.site

Questions?