[Plugin] SPDLog - Fast async logging
#1

Hello guys,

currently I'm refactoring my plugin and started moving some stuff to a new plugin.
I made this plugin before and I thought I can share it with you guys.

This plugin provides an API for gabime/spdlog.
With that plugin your logs doesnt block on write. You can easily write some stuff asynchronous.

Flush policies
By default spdlog lets the the underlying libc flush whenever it sees fit to achieve good performance. You can override this using the following options:
- Manual flush: LogFlush(const name[]) (See the example below)
- Flush on log level: LogFlushOn(const name[], SPDLOG_LEVEL:level)

Example ConsoleLogger
Код:
#include <a_spdlog>
#define Console "stdout"
public OnGameModeInit()
{
    // Enable async logging
    LoggerSetAsyncMode(4096);

    // Initialize logger
    ConsoleLogger(Console); // To console (no log)

    // Info (This text doesnt show up in server_log.txt)
    LogInfo(Console, "Gamemode initializing...");

    // Don't use these lines if it's a filterscript
    SetGameModeText("SPDLog Test");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);

    // Info (This text doesnt show up in server_log.txt)
    LogInfo(Console, "Gamemode initialized...");
    LogInfo(Console, "Server started or whateverr...");
    LogCritical(Console, "The server is burning! <- Colored console in samp 'WOW'");
    return 1;
}
Manual flush (BasicLogger)
You can manually flush the log using the LogFlush function.

Код:
#include <a_spdlog>
#define Log "stdlog"
public OnGameModeInit()
{
    // Enable async logging
    LoggerSetAsyncMode(4096);

    // Initialize logger
    BasicLogger(Log, "test.log"); // To console (no log)

    // Info (This text doesnt show up in server_log.txt)
    LogInfo(Log, "Gamemode initializing...");
    LogFlush(Log);    

    // Don't use these lines if it's a filterscript
    SetGameModeText("SPDLog Test");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);

    // Info (This text doesnt show up in server_log.txt)
    LogInfo(Log, "Gamemode initialized...");
    LogInfo(Log, "Server started or whateverr...");

    // Flush
    LogFlush(Log);
    return 1;
}
Don't use the example code, please change the defines to variables to lower the memory ussage.

The source code is hosted on github.
- Sphinxila/samp-plugin-spdlog

Download:
- Download Linux: Download v.1.0.0
- Download Windows: Download v.1.0.0

Support:
If you have some bugs, feel free to share that on github as an issue: Klick

The chance that I see some bug reports here are very low cause I'm not very active at this board (forum).

Kind regards
Sphinx (ProMetheus)
Reply
#2

Good 4 stars.
Reply
#3

I will give it a shot.
Reply
#4

Fixed some issues, please use the latest release.
I will implement a version check in the next release to avoid plugin / header missmatches.

Kind regards
Sphinx
Reply
#5

v.0.0.4-stable
  • A few bugfixes
  • Directory tree
  • Argument count
  • Version check added
  • Checks the logger version (Just OnGameModeInit)!
- Download Linux: Download v.0.0.4
- Download Windows: Download v.0.0.4
Reply
#6

v.1.0.0-stable
  • Updated SPDLog to Gabime/spdlog.git@e9b82867144cbb70993ce3680bfb8c30a30ca27 3
  • Fixed LoggerSetLevel, LogFlushOn
  • Added LogLevel - Set log level for a specified logger.
- Download Linux: Download v.1.0.0
- Download Windows: Download v.1.0.0
Reply
#7

Very nice.

rep += 1;
Reply
#8

Nice +7rep.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)