Class Log

java.lang.Object
com.portal.pcm.Log
Direct Known Subclasses:
ErrorLog

public class Log extends Object
Log presents a Java interface for the PCM library log and is the base class for logging functionality.

There are two types of logging styles: by priority and by flag. Each type has a choice of control levels that determine which messages are logged. You configure logging by setting the log entries in the Infranet.properties file.

Logging by priority:

In priority style, you assign each message a priority level. All messages with a priority level lower than the log control level are logged. (A lower number equals a higher priority.) If the priority control level is not configured, all messages are logged.

Logging by flag:

In flag style, each message is tagged with a flag that specifies the error message type. Possible flag values are defined in ErrorLog. You specify which flags will result in a message being logged in the Infranet.properties file.

Configuring the Infranet.properties file:

You must configure each log you use in the Infranet.properties file. Log entries consist of:
  • Infranet.log.log_name.file: Full path to the log file for the application. To log messages, you must set the log path.
  • Infranet.log.log_name.name: The name of the log to write to.
  • Infranet.log.log_name.style: Specifies the logging control style. The values for this entry can be:
    • priority: Logs messages according to their priority level, specified by the .level entry.
    • flag: Logs messages according to their type, specified by the .level entry.
  • Infranet.log.log_name.level: Specifies how much information the application should log. Possible values depend on the log control style specified by the .style entry. Values for this entry can be:
    • For control by priority style, use a decimal value.
    • For control by flag style, values can be:
      • 0 for none (default)
      • 1 for ERRORS messages
      • 2 for ERRORS and WARNINGS
      • 3 for ERRORS, WARNING, and DEBUG messages
  • Infranet.log.log_name.enable Enables or disables logging to this log. To disable logging, set to "f", "n", or zero.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Specifies logging by flag.
    static final int
    Specifies logging by priority.
    protected static SimpleDateFormat
     
    static final String
    Specifies a newline character, used in the log file.
    static final int
    Specifies no control styles on logging.
    static final int
    Specifies all flags for flag style logging.
    static final int
    Specifies no flags for flag style logging.
    static final int
    Specifies the highest priority for priority style logging.
    static final int
     
    static final int
     
    static final int
    Specifies the lowest priority for priority style logging.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Log()
    Constructs an instance of Log.
    Log(String path)
    Constructs an instance of Log from a path.
    Log(String path, String name, int control, int state)
    Constructs an instance of Log from a given path, application name, and logging flags.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes the log.
    protected String
    controlToString(int control)
     
    boolean
    doLog(int control)
    Evaluates the control level to determine whether a log call will result in a log entry.
    int
    Retrieves the message priority level or flag, depending on the logging control style.
    int
    Retrieves the Log control style type that specifies whether logging is controlled by priority or by flag.
    Retrieves the Log as an InputStream.
    protected String
    getMessageHeader(String src, int control)
     
    Retrieves the name of the application doing the logging.
    boolean
    Determines if the message logged is stored in memory rather than on disk.
    void
    log(int control, String message)
    Logs information to the log file.
    void
    log(Object srcOb, int control, String message)
    Logs information to the log file.
    void
    log(Object src, int control, String message, byte[] buf)
    Logs a message to the log file along with a hex dump of the array of bytes.
    void
    log(Object src, int control, String message, byte[] buf, int off, int len)
    Logs a message to the log file along with a hex dump of the array of bytes.
    void
    log(Object src, int control, Throwable thrown)
    Logs the error message retrieved from the Throwable object thrown by an error.
    protected void
     
    void
    setControlState(int state)
    Sets the Log priority level or flag, depending on the logging control style specified in the setControlStyle method.
    void
    setControlStyle(int control)
    Sets the Log control style that specifies whether logging is controlled by priority or by flag.
    void
    setInMemoryFlagValue(int logvalue)
    Sets the Log inmemorylogvalue Value 0 indicates no in memory logging is not selected any other value indicates in memory logging is selected
    void
    setInMemoryLogSize(long logsize)
    Sets the Log inmemorylogsize
    void
    Sets the application Log name.
    void
    setNames(int[] priorities, String[] names)
     
    void
    setNames(String[] names)
     
    void
    Sets the log file path name.
    void
    setWriter(Writer writer)
    Set log writer

    Methods inherited from class java.lang.Object

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

    • NO_LOG_CONTROL

      public static final int NO_LOG_CONTROL
      Specifies no control styles on logging. This logs no messages.
      See Also:
    • CONTROL_BY_PRIORITY

      public static final int CONTROL_BY_PRIORITY
      Specifies logging by priority.
      See Also:
    • CONTROL_BY_FLAG

      public static final int CONTROL_BY_FLAG
      Specifies logging by flag.
      See Also:
    • STATE_FLAG_NONE

      public static final int STATE_FLAG_NONE
      Specifies no flags for flag style logging. This logs no messages.
      See Also:
    • STATE_FLAG_ALL

      public static final int STATE_FLAG_ALL
      Specifies all flags for flag style logging. This logs all messages.
      See Also:
    • STATE_PRIORITY_LOG_NONE

      public static final int STATE_PRIORITY_LOG_NONE
      See Also:
    • STATE_PRIORITY_LOG_ALL

      public static final int STATE_PRIORITY_LOG_ALL
      See Also:
    • STATE_PRIORITY_HIGHEST

      public static final int STATE_PRIORITY_HIGHEST
      Specifies the highest priority for priority style logging.
      See Also:
    • STATE_PRIORITY_LOWEST

      public static final int STATE_PRIORITY_LOWEST
      Specifies the lowest priority for priority style logging.
      See Also:
    • NEWLINE

      public static final String NEWLINE
      Specifies a newline character, used in the log file.
    • m_sdf

      protected static SimpleDateFormat m_sdf
  • Constructor Details

    • Log

      public Log()
      Constructs an instance of Log. The default file name is "JavaLog" and the default path is "javapcm.log". The default is to log no messages.
    • Log

      public Log(String path, String name, int control, int state)
      Constructs an instance of Log from a given path, application name, and logging flags.
      Parameters:
      path - The path for the log file.
      name - The name of the application doing the logging.
      control - The logging control style. Valid control values are CONTROL_BY_PRIORITY and CONTROL_BY_FLAG.
      state - The priority level or flag, depending on the control style.
    • Log

      public Log(String path)
      Constructs an instance of Log from a path. The default file name is "JavaLog". The default is to log no messages.
      Parameters:
      path - The path for the log file.
  • Method Details

    • setName

      public void setName(String name)
      Sets the application Log name.
      Parameters:
      name - The name of the application doing the logging.
    • setPath

      public void setPath(String path)
      Sets the log file path name.
      Parameters:
      path - The new log path.
    • setWriter

      public void setWriter(Writer writer)
      Set log writer
      Parameters:
      writer - The writer for log.
    • setControlStyle

      public void setControlStyle(int control)
      Sets the Log control style that specifies whether logging is controlled by priority or by flag.
      Parameters:
      control - The control style. Valid values are CONTROL_BY_PRIORITY and CONTROL_BY_FLAG.
    • setControlState

      public void setControlState(int state)
      Sets the Log priority level or flag, depending on the logging control style specified in the setControlStyle method.
      Parameters:
      state - The priority level or flag.
    • setInMemoryFlagValue

      public void setInMemoryFlagValue(int logvalue)
      Sets the Log inmemorylogvalue Value 0 indicates no in memory logging is not selected any other value indicates in memory logging is selected
      Parameters:
      logvalue - The in memory log value.
    • setInMemoryLogSize

      public void setInMemoryLogSize(long logsize)
      Sets the Log inmemorylogsize
      Parameters:
      logsize - The in memory log size.
    • getControlStyle

      public int getControlStyle()
      Retrieves the Log control style type that specifies whether logging is controlled by priority or by flag.
      Returns:
      The control style.
    • getControlState

      public int getControlState()
      Retrieves the message priority level or flag, depending on the logging control style.
      Returns:
      The level or flag.
    • getName

      public String getName()
      Retrieves the name of the application doing the logging.
      Returns:
      The application name.
    • setNames

      public void setNames(String[] names)
    • setNames

      public void setNames(int[] priorities, String[] names)
    • doLog

      public boolean doLog(int control)
      Evaluates the control level to determine whether a log call will result in a log entry.
      Parameters:
      control - The priority level or flag (depending on logging control style) that is passed to the Log method.
      Returns:
      true if the specified control level permits writing to the log file.
    • log

      public void log(int control, String message) throws IOException
      Logs information to the log file.
      Parameters:
      control - The priority level or flag, depending on logging control style.
      message - The message to log.
      Throws:
      IOException - is thrown if there is an error writing to the log file.
    • log

      public void log(Object src, int control, Throwable thrown) throws IOException
      Logs the error message retrieved from the Throwable object thrown by an error.
      Parameters:
      src - The location of the error. For example, a file name and a line number. If src is a string, it is used to describe the source. Otherwise, the name of the object class is used.
      control - The priority level or flag, depending on logging control style.
      thrown - The thrown error or exception to log.
      Throws:
      IOException - is thrown if there is an error writing to the log file.
    • log

      public void log(Object src, int control, String message, byte[] buf) throws IOException
      Logs a message to the log file along with a hex dump of the array of bytes.
      Parameters:
      src - The location of the error. For example, a file name and a line number. If src is a string, it is used to describe the source. Otherwise, the name of the object class is used.
      control - The priority level or flag, depending on logging control style.
      message - The message to log.
      buf - The array of bytes to append to the message.
      Throws:
      IOException - is thrown if there is an error writing to the log file.
    • log

      public void log(Object src, int control, String message, byte[] buf, int off, int len) throws IOException
      Logs a message to the log file along with a hex dump of the array of bytes.
      Parameters:
      src - An The location of the error. For example, a file name and a line number. If src is a string, it is used to describe the source. Otherwise, the name of the object class is used.
      control - The priority level or flag, depending on logging control style.
      message - The message to log.
      buf - The array of bytes to append to the message.
      off - Offset into the buffer; the position at which to start the hex dump.
      len - Number of buf bytes to log.
      Throws:
      IOException - is thrown if there is an error writing to the log file.
    • log

      public void log(Object srcOb, int control, String message) throws IOException
      Logs information to the log file.
      Parameters:
      srcOb - The location of the error. For example, a file name and a line number. If srcOb is a string, it is used to describe the source. Otherwise, the name of the object class is used.
      control - The priority level or flag, depending on logging control style.
      message - The message to log.
      Throws:
      IOException - is thrown if there is an error writing to the log file.
    • getMessageHeader

      protected String getMessageHeader(String src, int control)
    • controlToString

      protected String controlToString(int control)
    • close

      public void close()
      Closes the log.
    • isLogInMemory

      public boolean isLogInMemory()
      Determines if the message logged is stored in memory rather than on disk.
      Returns:
      true if the log is in memory.
    • getLog

      public InputStream getLog() throws IOException
      Retrieves the Log as an InputStream.
      Returns:
      An InputStream of the Log object.
      Throws:
      IOException - thrown if InputStream cannot be created.
    • openLog

      protected void openLog()