dlogg

Default synchronized log realization. The logging process performs instantly (if it can be processed properly). Logger puts message style string and current timestamp before the message.

Tested to be able operate in daemon mode and under heavy concurrent writing.

License
Subject to the terms of the MIT license, as written in the included LICENSE file.
Authors
NCrashed

alias  StrictLogger = StyledStrictLogger!(LoggingLevel, cast(LoggingLevel)2, "Debug: %1$s", "[%2$s]: Debug: %1$s", cast(LoggingLevel)0, "Notice: %1$s", "[%2$s]: Notice: %1$s", cast(LoggingLevel)1, "Warning: %1$s", "[%2$s]: Warning: %1$s", cast(LoggingLevel)3, "Fatal: %1$s", "[%2$s]: Fatal: %1$s", cast(LoggingLevel)4, "", "").StyledStrictLogger;

Standard implementation of IStyledLogger interface.

Example:
shared ILogger logger = new StrictLogger("my_awesome_log.log");
logger.minOutputLevel = LoggingLevel.Warning; // info msgs won't be printed in console
logger.logInfo("Info message!");
logger.logError("Error message!");
logger.logDebug("Debug message!");

// received USR1 signal from logrotate
logger.reload;

class  StyledStrictLogger(StyleEnum, US...): IStyledLogger!StyleEnum;

Implementation of IStyledLogger with custom style. Usually you want to use StrictLogger alias, but there are cases where you want custom styles.

Example of custom styled logger:

enum MyLevel
{
    Error,
    Debug
}

alias MyLogger = StyledStrictLogger!(MyLevel
            , MyLevel.Debug,   "Debug: %1$s",   "[%2$s] Debug: %1$s"
            , MyLevel.Error,   "Fatal: %1$s",   "[%2$s] Fatal: %1$s");

See Also
dlogg.style

enum  Mode;

Option how to open logging file


Don't override, append to end


Override, start new file


const nothrow @property @safe string  name();

Log file  name.


@property @trusted void  name(string value);

Setting new log file  name. If the value differs from old one, logger should close old one and open new file.


@trusted void  log(lazy string message, StyleEnum level);

Prints message into  log. Displaying in the console controlled by minOutputLevel property.


const @property @trusted StyleEnum  minOutputLevel();

Returns
minimum log level, will be printed in the console.

@property @trusted void  minOutputLevel(StyleEnum level);

Setups minimum log level,


@property StyleEnum  minLoggingLevel();

Setups minimum message level that goes to file.


@property void  minLoggingLevel(StyleEnum level);

Setups minimum message level that goes to file.


void  reload();

Checks if the log file is exists at specified location and if can't find it, recreates the file and continues write into it.

Useful for logrotate utility. GNU/Linux system checks file identity by inode, that doesn't change while renaming. Thus after renaming the file at location log continues write into the renamed file. The call to the  reload method force splitting log into two parts.


@trusted this(string name, Mode mode = Mode.Rewrite);

Creates log at dir/name. Tries to create parent directory and all sub directories.

Note:
Can throw if there is a problem with access permissions.

@trusted void  initialize(Mode mode = Mode.Rewrite);

Tries to create log file at location.


@trusted void  rawInput(string message);

Unsafe write down the message without any meta information.


@trusted void  finalize();

Used to manual shutdown protocols.