Logger

* Logger class is used for logging a message. * You can log a message to the system console or to a file: "logs.txt". * You can change the log file name. * You can activate or deactivate logger any time.

Members

Static functions

console
void console(string message, string objectName, bool onlyToConsole)

* Log a debug information message. * It starts with the current time + " -> LOG_DEBUG: " * Only works in debug mode. * Params: * message = the debug information message * obj = current class reference, mostly you pass 'this'

deinitialize
void deinitialize()

*

error
void error(string message, string objectName, bool onlyToConsole)

* Log an error message. * The type of the error is fatal so the program will exit with a status code of 1. * It starts with the current time + " -> LOG_ERROR: " * Params: * message = the error message * obj = current class reference, mostly you pass 'this'

exception
void exception(string message, bool onlyToConsole)

* Log an exception message. * It starts with the current time + " -> LOG_EXCEPTION: " * Params: * message = the exception message

info
void info(string message, string objectName, bool onlyToConsole)

* Log an information message. * It starts with the current time + " -> LOG_INFO: " * Params: * message = the information message * obj = current class reference, mostly you pass 'this'

initialize
void initialize()

*

log
void log(LogType type, string message, bool onlyToConsole)

* Log a message using LogType.

todo
void todo(string message, string objectName, bool onlyToConsole)

* Log a todo message. * It starts with the current time + " -> LOG_TODO: " * Params: * message = the todo message * obj = current class reference, mostly you pass 'this'

warning
void warning(string message, string objectName, bool onlyToConsole)

* Log a warning message. * It starts with the current time + " -> LOG_WARNING: " * Params: * message = the warning message * obj = current class reference, mostly you pass 'this'

Static variables

isActive
bool isActive;

* Set false if you don't want logger to run.

logFileName
string logFileName;

* Log file name.

Examples

* Example for Logger usage:

class LogClass {
  this() {
    Logger.initialize();
    scope(exit) Logger.deinitialize();
    Logger.console("Test message!", typeof(this).stringof);
    Logger.info("Info test message!", typeof(this).stringof);
    Logger.warning("Warning test message!", typeof(this).stringof);
    Logger.error("Error test message!", typeof(this).stringof);
    try {
      immutable int x = 5;
      if (x == 5)
        throw new Exception("x cannot be 5!");
    } catch (Exception e) {
      Logger.exception("Exception test message!");
    }
    Logger.todo("Todo test message!", typeof(this).stringof);
  }
}

new LogClass();

Meta