This is a Sourcemod extension that wraps the spdlog library to enhance SourcePawn logging and debugging.
-
Very fast, much faster than LogMessage
-
Each
Logger
andSink
can customize the log level -
Each
Logger
andSink
can customize the log message pattern -
Each
Logger
can customize the flush policy -
Each
Logger
can have multipleSink
- For example: A
Logger
that has bothServerConsoleSink
andDailyFileSink
is similar to LogMessage
- For example: A
-
Each
Logger
can dynamic change the log level and pattern- see server command
"sm log4sp"
- see server command
-
Supports asynchronous
Logger
-
Supports format parameters with variable numbers
-
Parameter formatting usage is consistent with LogMessage
-
The maximum length of a variable parameter string is 2048 characters If characters exceeding this length will be truncated If longer message need to be log, non
AmxTpl
API can be used, e.g.void Info(const char [] msg)
-
-
Supports backtrace
- When enabled,
Trace
andDebug
level log message are stored in a circular buffer and only output explicitly after callingDumpBacktrace()
- When enabled,
-
Supports various log targets
-
ServerConsoleSink (Similar to PrintToServer)
-
ClientConsoleSink (Similar to PrintToConsole)
-
BaseFileSink (Similar to LogToFile when sv_logecho is 0)
-
DailyFileSink (Similar to LogMessage when sv_logecho is 0)
-
RotatingFileSink
-
Documentation can be found in the wiki pages.
log4sp.ext
should work for all games on Linux and Windows.
Test platform: Windows 11 + VMware + Ubuntu 24.04 LTS + sourcemod 1.11
Host configuration: AMD Ryzen 7 6800H + 32 GB Memory
VMware configuration: 1 CPU + 8 kernel + 4 GB Memory
Test case 1: benchmark-log4sp.sp
Test case 2: benchmark-sm-logging.sp
[benchmark] base-file-st | Iters 1000000 | Elapsed 0.268 secs 3719518/sec
[benchmark] daily-file-st | Iters 1000000 | Elapsed 0.278 secs 3589439/sec
[benchmark] rotating-file-st | Iters 1000000 | Elapsed 0.279 secs 3578598/sec
[benchmark] server-console-st | Iters 1000000 | Elapsed 5.609 secs 178255/sec
# Queue size: 8192 Thread count: 1
[benchmark] base-file-block | Iters 1000000 | Elapsed 0.479 secs 2084762/sec
[benchmark] daily-file-block | Iters 1000000 | Elapsed 0.488 secs 2046592/sec
[benchmark] rotating-file-block | Iters 1000000 | Elapsed 0.462 secs 2162868/sec
[benchmark] server-console-block | Iters 1000000 | Elapsed 8.422 secs 118725/sec
[benchmark] base-file-overrun | Iters 1000000 | Elapsed 0.442 secs 2259856/sec
[benchmark] daily-file-overrun | Iters 1000000 | Elapsed 0.438 secs 2280891/sec
[benchmark] rotating-file-overrun | Iters 1000000 | Elapsed 0.442 secs 2260684/sec
[benchmark] server-console-overrun | Iters 1000000 | Elapsed 0.379 secs 2632167/sec
# Queue size: 8192 Thread count: 4
[benchmark] base-file-block | Iters 1000000 | Elapsed 1.049 secs 952753/sec
[benchmark] daily-file-block | Iters 1000000 | Elapsed 1.086 secs 920584/sec
[benchmark] rotating-file-block | Iters 1000000 | Elapsed 1.034 secs 967049/sec
[benchmark] server-console-block | Iters 1000000 | Elapsed 15.784 secs 63354/sec
[benchmark] base-file-overrun | Iters 1000000 | Elapsed 0.439 secs 2273952/sec
[benchmark] daily-file-overrun | Iters 1000000 | Elapsed 0.451 secs 2212609/sec
[benchmark] rotating-file-overrun | Iters 1000000 | Elapsed 0.453 secs 2204658/sec
[benchmark] server-console-overrun | Iters 1000000 | Elapsed 0.372 secs 2684282/sec
# Queue size: 131072 Thread count: 4
[benchmark] base-file-block | Iters 1000000 | Elapsed 0.998 secs 1001216/sec
[benchmark] daily-file-block | Iters 1000000 | Elapsed 0.973 secs 1027070/sec
[benchmark] rotating-file-block | Iters 1000000 | Elapsed 0.956 secs 1045255/sec
[benchmark] server-console-block | Iters 1000000 | Elapsed 13.952 secs 71671/sec
[benchmark] base-file-overrun | Iters 1000000 | Elapsed 0.472 secs 2116635/sec
[benchmark] daily-file-overrun | Iters 1000000 | Elapsed 0.441 secs 2264892/sec
[benchmark] rotating-file-overrun | Iters 1000000 | Elapsed 0.478 secs 2091503/sec
[benchmark] server-console-overrun | Iters 1000000 | Elapsed 0.385 secs 2592245/sec
# Queue size: 8192 Thread count: 8
[benchmark] base-file-block | Iters 1000000 | Elapsed 1.135 secs 881010/sec
[benchmark] daily-file-block | Iters 1000000 | Elapsed 1.183 secs 845069/sec
[benchmark] rotating-file-block | Iters 1000000 | Elapsed 1.193 secs 838199/sec
[benchmark] server-console-block | Iters 1000000 | Elapsed 14.925 secs 67000/sec
[benchmark] base-file-overrun | Iters 1000000 | Elapsed 0.533 secs 1875363/sec
[benchmark] daily-file-overrun | Iters 1000000 | Elapsed 0.569 secs 1754767/sec
[benchmark] rotating-file-overrun | Iters 1000000 | Elapsed 0.508 secs 1967969/sec
[benchmark] server-console-overrun | Iters 1000000 | Elapsed 0.394 secs 2532556/sec
As a reference, sourcemod logging API was also tested
[benchmark] LogMessage | Iters 1000000 | Elapsed 10.740 secs 93108/sec
[benchmark] LogToFile | Iters 1000000 | Elapsed 9.091 secs 109989/sec
[benchmark] LogToFileEx | Iters 1000000 | Elapsed 8.823 secs 113336/sec
[benchmark] PrintToServer | Iters 1000000 | Elapsed 5.779 secs 173024/sec
-
gabime spdlog library implements most of the functionality, log4sp.ext wraps the spdlog API for SourcePawn to use
-
Fyren, nosoop, Deathreus provides solution for managing the Sink Handle
If I missed anyone, please contact me.