Package org.xjge.core

Class Logger

java.lang.Object
org.xjge.core.Logger

public final class Logger
extends java.lang.Object
A lightweight application logger comprised of a single static class which can be used to keep a chronological record of significant events occurring within the application at runtime.

Output provided by the logger can be viewed through the applications console at runtime, or after the application has ceased execution following a call made to logSevere() in which case a .txt file will be generated containing the loggers output.

The logger provides the following methods for generating text output:

  • logInfo() - Produces a low-priority message, useful for tracking state changes.
  • logWarning() - Indicates that the application may have encountered a non-fatal error.
  • logSevere() - A fatal error has occurred which will require the application to cease execution immediately.
  • setDomain() - Appends the name of whichever application is using the logger to the log messages it creates.
  • newLine() - Inserts a new line into the text output.
Since:
2.0.0
  • Constructor Summary

    Constructors
    Constructor Description
    Logger()  
  • Method Summary

    Modifier and Type Method Description
    static void logInfo​(java.lang.String message)
    Writes an informative low-priority message to the applications console.
    static void logSevere​(java.lang.String message, java.lang.Exception e)
    Writes a high-priority message to the applications console.
    static void logWarning​(java.lang.String message, java.lang.Exception e)
    Writes a medium-priority message to the applications console.
    static void setDomain​(java.lang.String domain)
    Appends the name of a module to the log message following the priority indicator (INFO, WARNING, etc).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Logger

      public Logger()
  • Method Details

    • setDomain

      public static void setDomain​(java.lang.String domain)
      Appends the name of a module to the log message following the priority indicator (INFO, WARNING, etc). Included so log messages can be better located within different domains of the engine. You likely won't need to make use of it in your game project unless you really want to.

      NOTE: Should you choose to utilize this feature remember to pass null following the log message to reset the state of the logger so any log messages following this one do not inadvertently exhibit erroneous domain names. This process often looks something like this:

       setDomain("myDomain");
           logInfo(...);
       setDomain(null);
       
      Parameters:
      domain - the name of the module to append to the log message
    • logInfo

      public static void logInfo​(java.lang.String message)
      Writes an informative low-priority message to the applications console. Typically used to indicate significant state changes occurring within the application.
      Parameters:
      message - the text to appear as output in the console/log file
    • logWarning

      public static void logWarning​(java.lang.String message, java.lang.Exception e)
      Writes a medium-priority message to the applications console. Warning messages should be used to indicate that the application may have entered an invalid state which hasn't (yet) resulted in a crash- but may produce undefined behavior.
      Parameters:
      message - the text to appear as output in the console/log file
      e - an optional exception used to output a stack trace. If null is passed, no stack trace information will be displayed.
    • logSevere

      public static void logSevere​(java.lang.String message, java.lang.Exception e)
      Writes a high-priority message to the applications console. Use of this method is reserved only for instances wherein the application has encountered some fatal error that will require it to cease execution.

      A .txt file containing the recorded output will be generated in the directory from which the application was launched.

      Parameters:
      message - the text to appear as output in the console/log file
      e - an optional exception used to output a stack trace. If null is passed, JLogger will generate a nondescript RuntimeException.