Class Logger

java.lang.Object
tripleplay.util.Logger

public class Logger extends Object
Provides logging services that are routed to the appropriate logging destination on the client or server. A useful usage pattern is for a library or game to define a shared Log class like so:

 import tripleplay.util.Logger;
 public class Log {
   public static final Logger log = new Logger("libident");
 }
 
and then import Log.log statically into classes so that they can invoke log.info, etc.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Wires the logging front-end to the logging back-end.
    static enum 
    Tags a log message with a particular severity level.
    static class 
    Manages the target log levels for a given ident.
    static class 
    A logging back-end that writes to PlayN.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    Log levels can be configured via this instance.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Logger(String ident)
    Creates a logger with the specified ident string.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    debug(String message, Object... args)
    Logs a debug message.
    void
    error(String message, Object... args)
    Logs an error message.
    static String
    format(Object message, Object... args)
    Formats and returns the supplied message and key/value arguments as message [key=value, key=value, ...].
    format(StringBuilder into, Object... args)
    Formats the supplied key/value arguments into the supplied string builder as key=value, key=value, ....
    void
    info(String message, Object... args)
    Logs an info message.
    static void
    Configures the logging back-end.
    boolean
    Tests if this logger will output messages of the given level.
    void
    warning(String message, Object... args)
    Logs a warning message.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • levels

      public static Logger.Levels levels
      Log levels can be configured via this instance.
  • Constructor Details

    • Logger

      public Logger(String ident)
      Creates a logger with the specified ident string.
  • Method Details

    • setImpl

      public static void setImpl(Logger.Impl impl)
      Configures the logging back-end. This should be called before any code that makes use of the logging services. The default back-end logs to stderr, which is useful when running in unit tests. null may be supplied to restore the default (stderr) back-end.
    • format

      public static String format(Object message, Object... args)
      Formats and returns the supplied message and key/value arguments as message [key=value, key=value, ...].
    • format

      public static StringBuilder format(StringBuilder into, Object... args)
      Formats the supplied key/value arguments into the supplied string builder as key=value, key=value, ....
      Returns:
      the supplied string builder.
    • shouldLog

      public boolean shouldLog(Logger.Level level)
      Tests if this logger will output messages of the given level.
    • debug

      public void debug(String message, Object... args)
      Logs a debug message.
      Parameters:
      message - the text of the message.
      args - a series of zero or more key/value pairs followed by an optional Throwable cause.
    • info

      public void info(String message, Object... args)
      Logs an info message.
      Parameters:
      message - the text of the message.
      args - a series of zero or more key/value pairs followed by an optional Throwable cause.
    • warning

      public void warning(String message, Object... args)
      Logs a warning message.
      Parameters:
      message - the text of the message.
      args - a series of zero or more key/value pairs followed by an optional Throwable cause.
    • error

      public void error(String message, Object... args)
      Logs an error message.
      Parameters:
      message - the text of the message.
      args - a series of zero or more key/value pairs followed by an optional Throwable cause.