Class SimpleLog

java.lang.Object
org.plumelib.bcelutil.SimpleLog

public final class SimpleLog extends Object
A logging class with the following features.
  • Can be enabled and disabled (when disabled, all operations are no-ops),
  • Can indent/exdent log output,
  • Writes to a file or to standard output, and
  • Can provide a stack trace.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    boolean
    If false, do no output.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new SimpleLog object with logging to standard out enabled.
    SimpleLog(boolean enabled)
    Create a new SimpleLog object with logging to standard out.
    SimpleLog(@Nullable String filename)
    Create a new SimpleLog object with logging to a file enabled.
    SimpleLog(@Nullable String filename, boolean enabled)
    Create a new SimpleLog object with logging to a file.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Return whether logging is enabled.
    void
    Decreases indentation by one level.
    void
    Increases indentation by one level.
    void
    log(String format, @Nullable Object... args)
    Log a message.
    void
    Print a stack trace to the log.
    void
    Resets indentation to none.

    Methods inherited from class java.lang.Object

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

    • enabled

      public boolean enabled
      If false, do no output.
  • Constructor Details

    • SimpleLog

      public SimpleLog()
      Create a new SimpleLog object with logging to standard out enabled.
    • SimpleLog

      public SimpleLog(boolean enabled)
      Create a new SimpleLog object with logging to standard out.
      Parameters:
      enabled - whether the logger starts out enabled
    • SimpleLog

      public SimpleLog(@Nullable String filename)
      Create a new SimpleLog object with logging to a file enabled.
      Parameters:
      filename - file name, or use "-" or null for System.out
    • SimpleLog

      public SimpleLog(@Nullable String filename, boolean enabled)
      Create a new SimpleLog object with logging to a file.
      Parameters:
      filename - file name, or use "-" or null for System.out
      enabled - whether the logger starts out enabled
  • Method Details

    • enabled

      public boolean enabled()
      Return whether logging is enabled.
      Returns:
      whether logging is enabled
    • log

      @FormatMethod public void log(String format, @Nullable Object... args)
      Log a message. The message is prepended with the current indentation string. The indentation is only applied at the start of the message, not for every line break within the message.
      Parameters:
      format - format string for message
      args - values to be substituted into format
    • logStackTrace

      public void logStackTrace()
      Print a stack trace to the log.
    • indent

      public void indent()
      Increases indentation by one level.
    • exdent

      public void exdent()
      Decreases indentation by one level.
    • resetIndent

      public void resetIndent()
      Resets indentation to none. Has no effect if logging is disabled.