Class AbstractSessionLog

java.lang.Object
org.eclipse.persistence.logging.AbstractSessionLog
All Implemented Interfaces:
Cloneable, SessionLog
Direct Known Subclasses:
DefaultSessionLog, JavaLog, ServerLog, SLF4JLogger

public abstract class AbstractSessionLog extends Object implements SessionLog, Cloneable
Represents the abstract log that implements all the generic logging functions. It contains a singleton SessionLog that logs messages from outside any EclipseLink session. The singleton SessionLog can also be passed to an EclipseLink session when messages are logged through that session. By default, a singleton DefaultSessionLog is created.
See Also:
  • Field Details

    • level

      protected int level
      Represents the log level
    • defaultLog

      protected static SessionLog defaultLog
      Represents the singleton SessionLog
    • SEVERE_PREFIX

      protected static String SEVERE_PREFIX
      Represents prefix to logged severe
    • WARNING_PREFIX

      protected static String WARNING_PREFIX
      Represents prefix to logged warning
    • INFO_PREFIX

      protected static String INFO_PREFIX
      Represents prefix to logged info
    • CONFIG_PREFIX

      protected static String CONFIG_PREFIX
      Represents prefix to logged config
    • FINE_PREFIX

      protected static String FINE_PREFIX
      Represents prefix to logged fine
    • FINER_PREFIX

      protected static String FINER_PREFIX
      Represents prefix to logged finer
    • FINEST_PREFIX

      protected static String FINEST_PREFIX
      Represents prefix to logged finest
    • CONNECTION_STRING

      protected static final String CONNECTION_STRING
      Connection string
      See Also:
    • THREAD_STRING

      protected static final String THREAD_STRING
      Thread string
      See Also:
    • writer

      protected Writer writer
      Represents the writer that will receive the formatted log entries
    • DATE_FORMAT_STR

      protected static String DATE_FORMAT_STR
      The pattern for formatting date-time in the log entries. By default, set to "yyyy.MM.dd HH:mm:ss.SSS".
    • timeStampFormatter

      protected DateTimeFormatter timeStampFormatter
      Formatter used to print the current date/time.
  • Constructor Details

    • AbstractSessionLog

      protected AbstractSessionLog()
      Creates a new instance of AbstractSessionLog class.
  • Method Details

    • getDefaultLoggingLevel

      public static int getDefaultLoggingLevel()
      Return the system default log level. This is based on the System property "eclipselink.logging.level", or INFO if not set.
      Returns:
      the system default log level
    • getLevel

      public int getLevel()
      Return the log level. It is used when session is not available.
      Specified by:
      getLevel in interface SessionLog
      Returns:
      the log level
    • getLevelString

      public String getLevelString()
      Return the log level as a string value.
      Specified by:
      getLevelString in interface SessionLog
      Returns:
      the current log level name
    • getLevel

      public int getLevel(String category)
      Return the log level for the category name space.
      Specified by:
      getLevel in interface SessionLog
      Parameters:
      category - the string representation of a EclipseLink category, e.g. "sql", "transaction" ...
      Returns:
      the log level
    • setLevel

      public void setLevel(int level)
      Set the log level. It is used when session is not available.
      Specified by:
      setLevel in interface SessionLog
      Parameters:
      level - the new log level
    • setLevel

      public void setLevel(int level, String category)
      Set the log level for the category name space.
      Specified by:
      setLevel in interface SessionLog
      Parameters:
      level - the new log level
      category - the string representation of an EclipseLink category, e.g. "sql", "transaction" ...
    • shouldLog

      public boolean shouldLog(int level)
      Check if a message of the given level would actually be logged. It is used when session is not available.
      Specified by:
      shouldLog in interface SessionLog
      Parameters:
      level - the log request level
      Returns:
      true if the given message level will be logged
    • shouldLog

      public boolean shouldLog(int level, String category)
      Check if a message of the given level would actually be logged for the category name space. !isOff() is checked to screen out the possibility when both log level and log request level are set to OFF.
      Specified by:
      shouldLog in interface SessionLog
      Parameters:
      level - the log request level
      category - the string representation of an EclipseLink category, e.g. "sql", "transaction" ...*
      Returns:
      true if the given message level will be logged
    • getLog

      public static SessionLog getLog()
      Return the singleton SessionLog. If the singleton SessionLog does not exist, a new one is created based on the version of JDK being used from the Version class.
      Returns:
      the singleton SessionLog
    • setLog

      public static void setLog(SessionLog sessionLog)
      Set the singleton SessionLog.
      Parameters:
      sessionLog - a SessionLog
    • getSessionName

      public String getSessionName()
      Description copied from interface: SessionLog
      Return the name of the session.
      Specified by:
      getSessionName in interface SessionLog
      Returns:
      the name of the session
    • setSessionName

      public void setSessionName(String sessionName)
      Description copied from interface: SessionLog
      Set the name of the session.
      Specified by:
      setSessionName in interface SessionLog
      Parameters:
      sessionName - the name of the session
    • log

      public void log(int level, Supplier<String> messageSupplier)
      Description copied from interface: SessionLog
      Log a message with message content supplier. See class description for the list of available levels.
      Specified by:
      log in interface SessionLog
      Parameters:
      level - the log level
      messageSupplier - the message string supplier
    • log

      public void log(int level, String category, Supplier<String> messageSupplier)
      Description copied from interface: SessionLog
      Log a message with message content supplier for provided category. See class description for the list of available levels and categories.
      Specified by:
      log in interface SessionLog
      Parameters:
      level - the log level
      category - the log category
      messageSupplier - the message string supplier
    • log

      public void log(int level, String message)
      Description copied from interface: SessionLog
      Log a message.

      The message won't be translated. This method is intended for external use when logging messages are wanted within the EclipseLink output. See class description for the list of available levels.

      Specified by:
      log in interface SessionLog
      Parameters:
      level - the log level
      message - the message string
    • log

      public void log(int level, String message, Object param)
      Description copied from interface: SessionLog
      Log a message with one parameter. The message will be translated. See class description for the list of available levels.
      Specified by:
      log in interface SessionLog
      Parameters:
      level - the log level
      message - the message string
      param - the message parameter
    • log

      public void log(int level, String category, String message, Object param)
      Description copied from interface: SessionLog
      Log a message with one parameter for provided category. The message will be translated. See class description for the list of available levels and categories.
      Specified by:
      log in interface SessionLog
      Parameters:
      level - the log level
      category - the log category
      message - the message string
      param - the message parameter
    • log

      public void log(int level, String message, Object param1, Object param2)
      Description copied from interface: SessionLog
      Log a message with two parameters. The message will be translated. See class description for the list of available levels.
      Specified by:
      log in interface SessionLog
      Parameters:
      level - the log level
      message - the message string
      param1 - the 1st message parameter
      param2 - the 2nd message parameter
    • log

      public void log(int level, String category, String message, Object param1, Object param2)
      Description copied from interface: SessionLog
      Log a message with two parameters for provided category. The message will be translated. See class description for the list of available levels and categories.
      Specified by:
      log in interface SessionLog
      Parameters:
      level - the log level
      category - the log category
      message - the message string
      param1 - the 1st message parameter
      param2 - the 2nd message parameter
    • log

      public void log(int level, String message, Object param1, Object param2, Object param3)
      Description copied from interface: SessionLog
      Log a message with three parameters. The message will be translated. See class description for the list of available levels.
      Specified by:
      log in interface SessionLog
      Parameters:
      level - the log level
      message - the message string
      param1 - the 1st message parameter
      param2 - the 2nd message parameter
      param3 - the 3rd message parameter
    • log

      public void log(int level, String category, String message, Object param1, Object param2, Object param3)
      Description copied from interface: SessionLog
      Log a message with three parameters for provided category. The message will be translated. See class description for the list of available levels and categories.
      Specified by:
      log in interface SessionLog
      Parameters:
      level - the log level
      category - the log category
      message - the message string
      param1 - the 1st message parameter
      param2 - the 2nd message parameter
      param3 - the 3rd message parameter
    • log

      public void log(int level, String message, Object param1, Object param2, Object param3, Object param4)
      Description copied from interface: SessionLog
      Log a message with four parameters. The message will be translated. See class description for the list of available levels.
      Specified by:
      log in interface SessionLog
      Parameters:
      level - the log level
      message - the message string
      param1 - the 1st message parameter
      param2 - the 2nd message parameter
      param3 - the 3rd message parameter
      param4 - the 4th message parameter
    • log

      public void log(int level, String category, String message, Object param1, Object param2, Object param3, Object param4)
      Description copied from interface: SessionLog
      Log a message with four parameters for provided category. The message will be translated. See class description for the list of available levels and categories.
      Specified by:
      log in interface SessionLog
      Parameters:
      level - the log level
      category - the log category
      message - the message string
      param1 - the 1st message parameter
      param2 - the 2nd message parameter
      param3 - the 3rd message parameter
      param4 - the 4th message parameter
    • log

      public void log(int level, String message, Object[] params)
      Description copied from interface: SessionLog
      Log a message with parameters array. The message will be translated. See class description for the list of available levels.
      Specified by:
      log in interface SessionLog
      Parameters:
      level - the log level
      message - the message string
      params - array of the message parameters
    • log

      public void log(int level, String category, String message, Object[] params)
      Description copied from interface: SessionLog
      Log a message with parameters array for provided category. The message will be translated. See class description for the list of available levels and categories.
      Specified by:
      log in interface SessionLog
      Parameters:
      level - the log level
      category - the log category
      message - the message string
      params - array of the message parameters
    • log

      @Deprecated(forRemoval=true, since="4.0.9") public void log(int level, String message, Object[] params, boolean shouldTranslate)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Description copied from interface: SessionLog
      Log a message with parameters array and translation flag. The message will be translated when shouldTranslate is set to true. See class description for the list of available levels.
      Specified by:
      log in interface SessionLog
      Parameters:
      level - the log level
      message - the message string
      params - array of the message parameters
      shouldTranslate - value of true if the message needs to be translated or false otherwise
    • log

      @Deprecated(forRemoval=true, since="4.0.9") public void log(int level, String category, String message, Object[] params, boolean shouldTranslate)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Description copied from interface: SessionLog
      Log a message with parameters array and translation flag for provided category. The message will be translated when shouldTranslate is set to true. See class description for the list of available levels and categories.
      Specified by:
      log in interface SessionLog
      Parameters:
      level - the log level
      category - the log category
      message - the message string
      params - array of the message parameters
      shouldTranslate - value of true if the message needs to be translated or false otherwise
    • shouldPrintSession

      public boolean shouldPrintSession()
      Whether the session should be printed as part of the log messages. By default, the session is always printed, but can be explicitly turned off or on.
      Specified by:
      shouldPrintSession in interface SessionLog
      Returns:
      value of true when the session should be printed as part of the log messages or false otherwise
    • setShouldPrintSession

      public void setShouldPrintSession(boolean shouldPrintSession)
      Turn printing of the session as part of the log messages on or off explicitly.
      Specified by:
      setShouldPrintSession in interface SessionLog
      Parameters:
      shouldPrintSession - value of true when the session should be printed as part of the log messages or false otherwise
    • shouldPrintConnection

      public boolean shouldPrintConnection()
      Whether the connection should be printed as part of the log messages. By default, the connection is always printed when available, but can be explicitly turned off or on.
      Specified by:
      shouldPrintConnection in interface SessionLog
      Returns:
      value of true when the connection should be printed as part of the log messages or false otherwise
    • setShouldPrintConnection

      public void setShouldPrintConnection(boolean shouldPrintConnection)
      Turn printing of the connection as part of the log messages on or off explicitly.
      Specified by:
      setShouldPrintConnection in interface SessionLog
      Parameters:
      shouldPrintConnection - value of true when the connection should be printed as part of the log messages or false otherwise
    • shouldLogExceptionStackTrace

      public boolean shouldLogExceptionStackTrace()
      Whether the Exception stack trace should be logged. By default, the stack is logged for FINER or less (finest). The logging of the stack can be explicitly turned on or off.
      Specified by:
      shouldLogExceptionStackTrace in interface SessionLog
      Returns:
      value of true when the Exception stack trace should be logged or false otherwise
    • setShouldLogExceptionStackTrace

      public void setShouldLogExceptionStackTrace(boolean shouldLogExceptionStackTrace)
      Turn Exception stack trace logging on or off explicitly.
      Specified by:
      setShouldLogExceptionStackTrace in interface SessionLog
      Parameters:
      shouldLogExceptionStackTrace - value of true when the Exception stack trace should be logged or false otherwise
    • shouldDisplayData

      public boolean shouldDisplayData()
      Whether the SQL logging should log visible the bind parameters. By default, the bind parameters are printed for FINE or less (finer, etc.). The printing of the bind parameters can be explicitly turned on or off.
      Specified by:
      shouldDisplayData in interface SessionLog
      Returns:
      value of true when the bind parameters should be printed as part of the SQL log messages or false otherwise
    • setShouldDisplayData

      public void setShouldDisplayData(Boolean shouldDisplayData)
      Turn printing of the bind parameters as part of the SQL log messages on or off explicitly.
      Specified by:
      setShouldDisplayData in interface SessionLog
      Parameters:
      shouldDisplayData - value of true when the bind parameters should be printed as part of the SQL log messages or false otherwise
    • shouldPrintDate

      public boolean shouldPrintDate()
      Whether the date should be printed as part of the log messages. By default, the date is always printed, but can be explicitly turned off or on.
      Specified by:
      shouldPrintDate in interface SessionLog
      Returns:
      value of true when the date should be printed as part of the log messages or false otherwise
    • setShouldPrintDate

      public void setShouldPrintDate(boolean shouldPrintDate)
      Turn printing of the date as part of the log messages on or off explicitly.
      Specified by:
      setShouldPrintDate in interface SessionLog
      Parameters:
      shouldPrintDate - value of true when the date should be printed as part of the log messages or false otherwise
    • shouldPrintThread

      public boolean shouldPrintThread()
      Whether the thread should be printed as part of the log messages. By default, the thread is printed for FINE or less (finer, etc.). The printing of the thread can be explicitly turned on or off.
      Specified by:
      shouldPrintThread in interface SessionLog
      Returns:
      value of true when the thread should be printed as part of the log messages or false otherwise
    • setShouldPrintThread

      public void setShouldPrintThread(boolean shouldPrintThread)
      Turn printing of the thread as part of the log messages on or off explicitly.
      Specified by:
      setShouldPrintThread in interface SessionLog
      Parameters:
      shouldPrintThread - value of true when the thread should be printed as part of the log messages or false otherwise
    • getWriter

      public Writer getWriter()
      Return the writer that will receive the formatted log entries.
      Specified by:
      getWriter in interface SessionLog
      Returns:
      the log writer
    • setWriter

      public void setWriter(Writer writer)
      Set the writer that will receive the formatted log entries.
      Specified by:
      setWriter in interface SessionLog
      Parameters:
      writer - the log writer
    • setWriter

      public void setWriter(OutputStream outputstream)
      Set the writer that will receive the formatted log entries.
      Parameters:
      outputstream - the log writer
    • getTimeStampFormatter

      public DateTimeFormatter getTimeStampFormatter()
      Return the specified date and/or time information in string. The format will be determined by the DateTimeFormatter settings. By default, the value of the DATE_FORMAT_STR pattern is used.
    • getTimeStampString

      protected String getTimeStampString(TemporalAccessor temporalAccessor)
    • getSupplementDetailString

      protected String getSupplementDetailString(SessionLogEntry entry)
      Return the supplement detail information including date, session, thread, connection, source class name and source method name.
    • getConnectionString

      protected String getConnectionString(int connectionId)
      Return the specified connection information.
      Parameters:
      connectionId - the identifier of the datasource connection
      Returns:
      connection string to be printed to the logs
    • getThreadString

      protected String getThreadString(Thread thread)
      Return the specified thread information.
    • printPrefixString

      protected void printPrefixString(int level, String category)
      Print the prefix string representing EclipseLink logging
    • getPrefixString

      protected String getPrefixString(int level, String category)
      Get the prefix string for the EclipseLink logging
    • setTimeStampFormatter

      public void setTimeStampFormatter(DateTimeFormatter timeStampFormatter)
      Set the date-time format to be used when printing a log entry date.
      Parameters:
      timeStampFormatter - Formatter for printing time stamp in the log entry.
    • formatMessage

      protected String formatMessage(SessionLogEntry entry)
      Return the formatted message based on the information from the given SessionLogEntry. The message will either be translated and formatted or formatted only depending on if the shouldTranslate flag is set to true of false.
    • translateStringToLoggingLevel

      public static int translateStringToLoggingLevel(String loggingLevel)
      Translate the string value of the log level to the constant value. If value is null or invalid use the default.
      Returns:
      the constant value of the provided log level String
    • throwing

      public void throwing(Throwable throwable)
      Log a throwable at FINER level.
      Specified by:
      throwing in interface SessionLog
      Parameters:
      throwable - a Throwable
    • severe

      public void severe(String message)
      Description copied from interface: SessionLog
      Log a SessionLog.SEVERE level message. The message will be translated.
      Specified by:
      severe in interface SessionLog
      Parameters:
      message - the message key
    • severe

      public void severe(Supplier<String> messageSupplier)
      Description copied from interface: SessionLog
      Log a SessionLog.SEVERE level message. Logs a message with message content supplier.
      Specified by:
      severe in interface SessionLog
      Parameters:
      messageSupplier - the message string supplier
    • warning

      public void warning(String message)
      Description copied from interface: SessionLog
      Log a SessionLog.WARNING level message. The message will be translated.
      Specified by:
      warning in interface SessionLog
      Parameters:
      message - the message key
    • warning

      public void warning(Supplier<String> messageSupplier)
      Description copied from interface: SessionLog
      Log a SessionLog.WARNING level message. Logs a message with message content supplier.
      Specified by:
      warning in interface SessionLog
      Parameters:
      messageSupplier - the message string supplier
    • info

      public void info(String message)
      Description copied from interface: SessionLog
      Log an SessionLog.INFO level message. The message will be translated.
      Specified by:
      info in interface SessionLog
      Parameters:
      message - the message key
    • info

      public void info(Supplier<String> messageSupplier)
      Description copied from interface: SessionLog
      Log an SessionLog.INFO level message. Logs a message with message content supplier.
      Specified by:
      info in interface SessionLog
      Parameters:
      messageSupplier - the message string supplier
    • config

      public void config(String message)
      Description copied from interface: SessionLog
      Log a SessionLog.CONFIG level message. The message will be translated.
      Specified by:
      config in interface SessionLog
      Parameters:
      message - the message key
    • config

      public void config(Supplier<String> messageSupplier)
      Description copied from interface: SessionLog
      Log a SessionLog.CONFIG level message. Logs a message with message content supplier.
      Specified by:
      config in interface SessionLog
      Parameters:
      messageSupplier - the message string supplier
    • fine

      public void fine(String message)
      Description copied from interface: SessionLog
      Log a SessionLog.FINE level message. The message will be translated.
      Specified by:
      fine in interface SessionLog
      Parameters:
      message - the message key
    • fine

      public void fine(Supplier<String> messageSupplier)
      Description copied from interface: SessionLog
      Log a SessionLog.FINE level message. Logs a message with message content supplier.
      Specified by:
      fine in interface SessionLog
      Parameters:
      messageSupplier - the message string supplier
    • finer

      public void finer(String message)
      Description copied from interface: SessionLog
      Log a SessionLog.FINER level message. The message will be translated.
      Specified by:
      finer in interface SessionLog
      Parameters:
      message - the message key
    • finer

      public void finer(Supplier<String> messageSupplier)
      Description copied from interface: SessionLog
      Log a SessionLog.FINER level message. Logs a message with message content supplier.
      Specified by:
      finer in interface SessionLog
      Parameters:
      messageSupplier - the message string supplier
    • finest

      public void finest(String message)
      Description copied from interface: SessionLog
      Log a SessionLog.FINEST level message. The message will be translated.
      Specified by:
      finest in interface SessionLog
      Parameters:
      message - the message key
    • finest

      public void finest(Supplier<String> messageSupplier)
      Description copied from interface: SessionLog
      Log a SessionLog.FINEST level message. Logs a message with message content supplier.
      Specified by:
      finest in interface SessionLog
      Parameters:
      messageSupplier - the message string supplier
    • logThrowable

      public void logThrowable(int level, Throwable throwable)
      Log a throwable with level.
      Specified by:
      logThrowable in interface SessionLog
      Parameters:
      level - the log request level value
      throwable - a Throwable
    • logThrowable

      public void logThrowable(int level, String category, Throwable throwable)
      Log a throwable with level.
      Specified by:
      logThrowable in interface SessionLog
      Parameters:
      level - the log request level value
      category - the log category
      throwable - a Throwable
    • isOff

      public boolean isOff()
      INTERNAL: Check if the log level is set to off.
    • clone

      public Object clone()
      INTERNAL: Each session owns its own session log because session is stored in the session log
      Specified by:
      clone in interface SessionLog
      Overrides:
      clone in class Object
      Returns:
      the cloned log