Skip to content
Max S edited this page Aug 13, 2015 · 1 revision

Logger

Overview

Both the slave and cache servers use the same logging facility, the snipe.lib.Logger class. The logger runs in a separate thread that waits until the message appears in the queue and writes it into one or multiple files. You can always use the snipe.cache.CacheServer.log() or snipe.slave.Server.log() methods to add new message to log but sometimes you will need a separate log for some purpose. In that case the new logger class instance can be created.

Server logs

By default the log messages are both written to logfiles and printed to stdout. You can change this in the configuration files.

When you first start the server, the following log directories will be created automatically.

In normal mode:

  • "logs" - log directory.
  • "trace" - trace log directory. Each log message with "trace" type will also be copied into the log in this directory.
  • "stats" - statistics log directory. Log messages with "stats" type will be copied here.

In uniserver mode:

  • "logs.cache/", "logs.game/" - log directories for game and cache server.
  • "trace.cache/", "trace.game/" - trace log directories.
  • "stats.cache/", "stats.game/" - stats log directories.

There are several important things to note here. Firstly, if you have more slave servers of other types, more directories will be created using this naming scheme. Secondly, new logfiles are created at the start of every new hour. Thirdly, the log naming scheme is "YYYY-MM-DD-HH.txt" (or "YYYY-MM-DD.txt" in case of daily rotated logfiles). And lastly, server log output is not flushed to file immediately so the logs will miss a dozen or so of the most recent lines until the OS does the next flush.

Custom logs

Custom logs are created with new instances of logger class. This class receives an object containing logger parameters. Let's take a look at these:

  • "name" - this parameter specifies the logger thread short name. The full name will be "logger: <name>" so you need to keep it short because of pthreads thread name limit of 15 symbols.
  • "directory" - this parameter specifies the log directory name.
  • "printLog" - if enabled, will print log messages to stdout.
  • "writeLog" - if enabled, will write log messages to logfiles.
  • "isHourly" - if enabled, the logfile is rotated hourly. Otherwise, rotated daily.
  • "logFull" - if enabled, will add date and message type in front of all messages.
  • "doFlush" - if enabled, will flush the output after each log message. This option should only be enabled in low-volume logs.

Here's the full usage example using slave server module:

  var _logger: Logger;

  public function new(srv: ServerTest)
    {
      super(srv);

      // ...

      _logger = new Logger({ 
        name: 'battle', 
        printLog: false, 
        writeLog: true,
        directory: 'battle',
        isHourly: true,
        logFull: false,
        doFlush: false,
        });
    }

  public inline function event(type: String, params: Dynamic)
    {
      var o = { event: type, properties: params };
      _logger.add(haxe.Json.stringify(o));
    }
Clone this wiki locally