Package com.illumon.iris.db.util.logging
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
.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 <workspace>/../logs/DbInternal/AuditEventLog|ProcessEventLog/<hostname>.bin.*
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
IrisLogCreator.LoggerType
The type of Logger to be created -
Field Summary
Fields Modifier and Type Field Description static String
ALIVE_TIME_PROP_SUFFIX
static String
CAPTURE_DELEGATING_LOGGER_PROP_SUFFIX
static String
CAPTURE_LOG4J_PROP_SUFFIX
static String
CAPTURE_SYSERR_PROP_SUFFIX
static String
LOG_LEVEL_PROP_SUFFIX
static String
LOG_TYPE_PROP_SUFFIX
static String
SHUTDOWN_WAIT_MILLISECONDS_SUFFIX
static String
TAKE_TIMEOUT_MILLIS_SUFFIX
static String
TIME_ZONE_SUFFIX
static String
USE_DYNAMIC_PARTITIONS_SUFFIX
static String
USE_LAS_PROP_SUFFIX
static String
USE_MAIN_CLASS_NAME_PROP_SUFFIX
static String
WRITE_AUDIT_LOGS_PROP_SUFFIX
static String
WRITE_DATABASE_PROCESS_LOGS_PROP_SUFFIX
static String
WRITE_PROCESS_INFO_PROP_SUFFIX
static String
WRITE_PROCESS_METRICS_PROP_SUFFIX
-
Constructor Summary
Constructors Constructor Description IrisLogCreator(com.fishlib.configuration.Configuration configuration, String mainClassName)
Create the standard Iris logs using the default process and audit log parameter namesIrisLogCreator(com.fishlib.configuration.Configuration configuration, String mainClassName, String eventLogHostName, String eventLogProcessName, String eventLogProcessInfoId, com.fishlib.auth.UserContext userContext, IrisLogCreator.LoggerType loggerType, boolean forceUseLas, boolean createEventLogs)
Create Deephaven logger instances. -
Method Summary
Modifier and Type Method Description AuditEventLoggerBasic
asAuditEventLoggerBasic()
void
awaitShutdown()
Await shutdown, creating our own OnetimeShutdownTask to log Alive message as appropriate.void
awaitShutdown(com.fishlib.util.process.OnetimeShutdownTask onetimeShutdownTask)
Await shutdown, logging Alive messages as appropriate.void
createEventLoggers(boolean forceUseLas)
Create the process event log, and audit event log, and process metrics log loggers, if specified by the properties.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.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.static IrisLogCreator
createIrisLogCreatorSingleton(com.fishlib.configuration.Configuration configuration, String mainClassName)
Create the standard Iris logs using the default process and audit log parameter names and register it as the singletonAuditEventLogFormat2Logger
getAuditEventLogger()
Return the AuditEventLog loggerString
getBinaryLogTimeZoneName()
Return the binary log time zone nameString
getEventLogHostName()
Return the host name being used for the event logsString
getEventLogProcessInfoId()
Return the unique process info id used for the event logsString
getEventLogProcessName()
Return the process name being used for the event logsString
getFallbackLogFilename()
com.fishlib.io.logger.Logger
getLogger()
Return the Logger instancestatic IrisLogCreator
getOrCreateIrisLogCreatorSingleton(com.fishlib.configuration.Configuration configuration, 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 singletonProcessEventLogFormat2Logger
getProcessEventLogger()
Return the ProcessEventLog loggerTableWriterLogInterceptor
getProcessLogInterceptor()
Return the ProcessEventLog interceptorstatic IrisLogCreator
getSingleton()
com.fishlib.stats.StatsIntradayLogger
getStatsIntradayLogger()
void
logProcessRunning()
Processes should call this method to indicate that they have finished initialization and are now running.void
registerShutdownMessageTask()
void
registerShutdownMessageTask(AuditEventBuilder auditEventBuilder)
Register the shutdown task that logs the shutting down message.static void
safeLogPelEntry(ProcessEventLogFormat2Logger pelLogger, long timestamp, String host, String level, String process, String processInfoId, com.fishlib.auth.UserContext userContext, String logEntry)
Safely log a PEL entry.static IrisLogCreator
setSingleton(IrisLogCreator instance)
void
setUserContext(com.fishlib.auth.UserContext userContext)
Allow the user context (used inasAuditEventLoggerBasic()
to be set after initialization.void
startKeepAliveTask()
Start the keep-alive reporting.
-
Field Details
-
USE_MAIN_CLASS_NAME_PROP_SUFFIX
- See Also:
- Constant Field Values
-
LOG_LEVEL_PROP_SUFFIX
- See Also:
- Constant Field Values
-
LOG_TYPE_PROP_SUFFIX
- See Also:
- Constant Field Values
-
CAPTURE_LOG4J_PROP_SUFFIX
- See Also:
- Constant Field Values
-
CAPTURE_DELEGATING_LOGGER_PROP_SUFFIX
- See Also:
- Constant Field Values
-
CAPTURE_SYSERR_PROP_SUFFIX
- See Also:
- Constant Field Values
-
ALIVE_TIME_PROP_SUFFIX
- See Also:
- Constant Field Values
-
SHUTDOWN_WAIT_MILLISECONDS_SUFFIX
- See Also:
- Constant Field Values
-
WRITE_AUDIT_LOGS_PROP_SUFFIX
- See Also:
- Constant Field Values
-
WRITE_DATABASE_PROCESS_LOGS_PROP_SUFFIX
- See Also:
- Constant Field Values
-
WRITE_PROCESS_INFO_PROP_SUFFIX
- See Also:
- Constant Field Values
-
WRITE_PROCESS_METRICS_PROP_SUFFIX
- See Also:
- Constant Field Values
-
USE_LAS_PROP_SUFFIX
- See Also:
- Constant Field Values
-
USE_DYNAMIC_PARTITIONS_SUFFIX
- See Also:
- Constant Field Values
-
TIME_ZONE_SUFFIX
- See Also:
- Constant Field Values
-
TAKE_TIMEOUT_MILLIS_SUFFIX
- See Also:
- Constant Field Values
-
-
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 instancemainClassName
- 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 instancemainClassName
- The main class for the processeventLogHostName
- 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 logsloggerType
- If provided, the type of Logger desired based on the LoggerType enumforceUseLas
- If true, always use the LogAggregatorService for AEL and PEL instead of relying on the propertiescreateEventLogs
- 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 callingcreateEventLoggers(boolean, boolean)
-
-
Method Details
-
setSingleton
-
getSingleton
-
getAuditEventLogger
Return the AuditEventLog logger- Returns:
- the AuditEventLog logger or null if none was created
-
getProcessEventLogger
Return the ProcessEventLog logger- Returns:
- the ProcessEventLog logger or null if none was created
-
getStatsIntradayLogger
public com.fishlib.stats.StatsIntradayLogger getStatsIntradayLogger() -
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
Return the host name being used for the event logs- Returns:
- the event log host name
-
getEventLogProcessName
Return the process name being used for the event logs- Returns:
- the event log process name
-
getEventLogProcessInfoId
Return the unique process info id used for the event logs- Returns:
- the process info id for the event logs
-
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 propertiesstandalone
- 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 propertiesstandalone
- if true, don't verify the logger checksums against the schema servicecaptureStdoutEarly
- 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 instancemainClassName
- 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 instancemainClassName
- the main class for the process
-
registerShutdownMessageTask
public void registerShutdownMessageTask() -
registerShutdownMessageTask
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
-
setUserContext
public void setUserContext(com.fishlib.auth.UserContext userContext)Allow the user context (used inasAuditEventLoggerBasic()
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 IOExceptionSafely 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 loggertimestamp
- the event's timestamphost
- the hostlevel
- the log entry's levelprocess
- the process nameprocessInfoId
- the unique identifier for the processuserContext
- the user context if availablelogEntry
- the log entry, which will be broken up if needed- Throws:
IOException
-
getFallbackLogFilename
-