Class IrisLogCreator

java.lang.Object
com.illumon.iris.db.util.logging.IrisLogCreator

public class IrisLogCreator
extends Object
Class to create the standard Iris log objects. It uses a standard set of configuration parameters based on the main class name that is passed in to the constructor. First it retrieves the process.name property value (this is usually defined by the host configuration). All property retrieval use a three-tier check:
  • First the value is checked with the retrieved process name: <process name>.<property name>
  • Next the value is checked with the passed-in class name: <mainClassName>.<property name>
  • Finally the value is checked for the general value: IrisLogCreator.<property name>
  • If no entries are found for the property an exception will be thrown
The following properties are provided (all following the three-tier check for retrieval - just the suffixes are listed here):
  • .useMainClassNameForLogs - whether to use the class name for log filenames; if false, then the retrieved property name will be used
  • .logLevel - the minimum event level to be logged, defaults to INFO
  • .logType - the type of log, used to determine the type of Logger log that is created, assuming that the code doesn't override this in the constructor. Options include:
    • STANDARD_LOG_CREATOR - uses the ProcessUnsafeLogCreator to create the Logger instance, this is the default
    • CONSOLE - creates a StreamLoggerImpl that sends logs to sysout
    • NULL - creates a null Logger implementation that calls any interceptors but doesn't log anything itself
  • .captureDelegatingLogger - indicates whether to capture delegating logger output to the Logger instance, defaults to true
  • .captureLog4j - indicates whether to capture the log4j output to the Logger instance, defaults to false
  • .captureSysout - indicates whether to capture the sysout output to the Logger instance, defaults to true. Note that if this is true, then the tee interceptor can not be used to send logs to sysout.
  • .captureSyserr - indicates whether to capture the syserr output to the Logger instance, defaults to true
  • .aliveMessageSeconds - indicates the time in seconds between ALIVE log messages, 0 means no ALIVE messages
  • .writeDatabaseAuditLogs - if true, use the Iris AuditEventLog
  • .writeDatabaseProcessLogs - if true, use the Iris ProcessEventLog and send any Logger messages to this log
  • .writeDatabaseProcessInfo - if true, use the Iris ProcessInfoLog and write the process info to the ProcessInfo table
  • .writeDatabaseProcessMetrics - if true, use the Iris ProcessMetricsLog and write the process metrics to the ProcessMetrics table
  • .useLogAggregatorService - if true, use the LogAggregatorService, otherwise log the audit/process events directly to disk
  • .useDynamicPartitions - if true, use row-based column partition evaluation when logging
  • .logTimeZone - if set, then use the specified time zone for binary log file names

If using the LogAggregatorService, the standard options for host and port as defined by the LogAggregatorServiceBinaryStoreWriterFactory (i.e. logAggregatorService.host and logAggregatorService.port, with options for different LAS instances based on namespace and table). If not using the LogAggregatorService, then the logs are written to &lt;workspace&gt;/../logs/DbInternal/AuditEventLog|ProcessEventLog/&lt;hostname&gt;.bin.*

  • Field Details

  • Constructor Details

    • IrisLogCreator

      public IrisLogCreator​(@NotNull com.fishlib.configuration.Configuration configuration, @NotNull String mainClassName)
      Create the standard Iris logs using the default process and audit log parameter names
      Parameters:
      configuration - a Configuration instance
      mainClassName - the main class for the process
    • IrisLogCreator

      public IrisLogCreator​(@NotNull com.fishlib.configuration.Configuration configuration, @NotNull String mainClassName, @Nullable String eventLogHostName, @Nullable String eventLogProcessName, @Nullable String eventLogProcessInfoId, @Nullable com.fishlib.auth.UserContext userContext, @Nullable IrisLogCreator.LoggerType loggerType, boolean forceUseLas, boolean createEventLogs)
      Create Deephaven logger instances.
      Parameters:
      configuration - A Configuration instance
      mainClassName - The main class for the process
      eventLogHostName - if provided, the host name to be used in the event logs (ProcessEventLog and AuditEventLog). If not provided, then the local host name will be used.
      eventLogProcessName - if provided, the process name to be used for the event logs. If not provided, then the process name as derived will be used.
      eventLogProcessInfoId - The unique process id to be used for the event logs. If not provided, one will be generated.
      userContext - If provided, the user context for any event logs
      loggerType - If provided, the type of Logger desired based on the LoggerType enum
      forceUseLas - If true, always use the LogAggregatorService for AEL and PEL instead of relying on the properties
      createEventLogs - If true, create audit event logger, process event logger, and process metrics logger instances in this constructor as specified by the properties; if false, creating them and capturing stdout/stderr requires calling createEventLoggers(boolean, boolean)
  • Method Details

    • setSingleton

      public static IrisLogCreator setSingleton​(@Nullable IrisLogCreator instance)
    • getSingleton

      public static IrisLogCreator getSingleton()
    • getAuditEventLogger

      public AuditEventLogFormat2Logger getAuditEventLogger()
      Return the AuditEventLog logger
      Returns:
      the AuditEventLog logger or null if none was created
    • getProcessEventLogger

      public ProcessEventLogFormat2Logger getProcessEventLogger()
      Return the ProcessEventLog logger
      Returns:
      the ProcessEventLog logger or null if none was created
    • getStatsIntradayLogger

      public com.fishlib.stats.StatsIntradayLogger getStatsIntradayLogger()
    • getProcessLogInterceptor

      public TableWriterLogInterceptor getProcessLogInterceptor()
      Return the ProcessEventLog interceptor
      Returns:
      the ProcessEventLog interceptor or null if none was created
    • getLogger

      public com.fishlib.io.logger.Logger getLogger()
      Return the Logger instance
      Returns:
      the Logger instance
    • getEventLogHostName

      public String getEventLogHostName()
      Return the host name being used for the event logs
      Returns:
      the event log host name
    • getEventLogProcessName

      public String getEventLogProcessName()
      Return the process name being used for the event logs
      Returns:
      the event log process name
    • getEventLogProcessInfoId

      public String getEventLogProcessInfoId()
      Return the unique process info id used for the event logs
      Returns:
      the process info id for the event logs
    • getBinaryLogTimeZoneName

      public String getBinaryLogTimeZoneName()
      Return the binary log time zone name
      Returns:
      the binary log time zone name
    • createEventLoggers

      public void createEventLoggers​(boolean forceUseLas)
      Create the process event log, and audit event log, and process metrics log loggers, if specified by the properties. These instances are created in parallel.
      Parameters:
      forceUseLas - if true, always use the LogAggregatorService for AEL and PEL instead of relying on the properties
    • createEventLoggers

      public void createEventLoggers​(boolean forceUseLas, boolean standalone)
      Create the process event log, and audit event log, and process metrics log loggers, if specified by the properties. These instances are created in parallel.
      Parameters:
      forceUseLas - if true, always use the LogAggregatorService for AEL and PEL instead of relying on the properties
      standalone - if true, don't verify the logger checksums against the schema service
    • createEventLoggers

      public void createEventLoggers​(boolean forceUseLas, boolean standalone, boolean captureStdoutEarly)
      Create the process event log, and audit event log, and process metrics log loggers, if specified by the properties. These instances are created in parallel.
      Parameters:
      forceUseLas - if true, always use the LogAggregatorService for AEL and PEL instead of relying on the properties
      standalone - if true, don't verify the logger checksums against the schema service
      captureStdoutEarly - if true, capture stdout/stderr/log4j early - like to prevent noise on a command line tool. if false, delay a little to make debugging regular processes easier
    • startKeepAliveTask

      public void startKeepAliveTask()
      Start the keep-alive reporting. This should not be called when the awaitShutdown methods are being used.
    • awaitShutdown

      public void awaitShutdown​(com.fishlib.util.process.OnetimeShutdownTask onetimeShutdownTask)
      Await shutdown, logging Alive messages as appropriate. This should not be called if startKeepAliveTask has been called.
      Parameters:
      onetimeShutdownTask - the OnetimeShutdownTask
    • awaitShutdown

      public void awaitShutdown()
      Await shutdown, creating our own OnetimeShutdownTask to log Alive message as appropriate. This should not be called if startKeepAliveTask has been called.
    • createIrisLogCreatorSingleton

      public static IrisLogCreator createIrisLogCreatorSingleton​(@NotNull com.fishlib.configuration.Configuration configuration, @NotNull String mainClassName)
      Create the standard Iris logs using the default process and audit log parameter names and register it as the singleton
      Parameters:
      configuration - a Configuration instance
      mainClassName - the main class for the process
    • getOrCreateIrisLogCreatorSingleton

      public static IrisLogCreator getOrCreateIrisLogCreatorSingleton​(@NotNull com.fishlib.configuration.Configuration configuration, @NotNull String mainClassName)
      Return the registered singleton, or create the standard Iris logs using the default process and audit log parameter names and register it as the singleton
      Parameters:
      configuration - a Configuration instance
      mainClassName - the main class for the process
    • registerShutdownMessageTask

      public void registerShutdownMessageTask()
    • registerShutdownMessageTask

      public void registerShutdownMessageTask​(@Nullable AuditEventBuilder auditEventBuilder)
      Register the shutdown task that logs the shutting down message. This must be done after the ProcessEnvironment has been initialized or an IllegalStateException will be thrown. This is not done automatically in the constructor as it's not desirable to enforce creation of the ProcessEnvironment there.
      Parameters:
      auditEventBuilder - if provided, log the specified event before stopping the audit event logger
    • logProcessRunning

      public void logProcessRunning()
      Processes should call this method to indicate that they have finished initialization and are now running. A log entry will be written, and if the process is logging to the audit event log then an entry will be added to that table.
    • asAuditEventLoggerBasic

      public AuditEventLoggerBasic asAuditEventLoggerBasic()
    • setUserContext

      public void setUserContext​(com.fishlib.auth.UserContext userContext)
      Allow the user context (used in asAuditEventLoggerBasic() to be set after initialization.
      Parameters:
      userContext - the new userContext to use in logging.
    • safeLogPelEntry

      public static void safeLogPelEntry​(ProcessEventLogFormat2Logger pelLogger, long timestamp, String host, String level, String process, String processInfoId, com.fishlib.auth.UserContext userContext, String logEntry) throws IOException
      Safely log a PEL entry. Binary rows are not allowed to be larger than specified by the property BinaryStoreMaxEntrySize, and if they are, they crash the process. This method will break up entries that are too long into multiple PEL entries.
      Parameters:
      pelLogger - the process event logger
      timestamp - the event's timestamp
      host - the host
      level - the log entry's level
      process - the process name
      processInfoId - the unique identifier for the process
      userContext - the user context if available
      logEntry - the log entry, which will be broken up if needed
      Throws:
      IOException
    • getFallbackLogFilename

      public String getFallbackLogFilename()