Logging
You can customize the content of logs as well as enable audit logging.
Management Center uses Log4j 2 for its logging. By default, Management Center prints all logs except audit logs to standard output. This behavior is defined by the following Spring Boot configuration properties:
logging.pattern.console=%d [%highlight{%5p}{FATAL=red, ERROR=red, WARN=yellow, INFO=green, DEBUG=magenta}] [%style{%t{1.}}{cyan}] [%style{%c{1.}}{blue}]: %m%n%xwEx
logging.level.root=${hazelcast.mc.log.level:INFO}
logging.level.com.hazelcast=${hazelcast.mc.log.level:ERROR}
logging.level.com.hazelcast.webmonitor=${hazelcast.mc.log.level:INFO}
logging.level.org.springframework=${hazelcast.mc.log.level:WARN}
logging.level.org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver=${hazelcast.mc.log.level:ERROR}
logging.level.MetricsTrace=TRACE
logging.level.com.zaxxer.hikari=${hazelcast.mc.log.level:WARN}
logging.level.liquibase=${hazelcast.mc.log.level:WARN}
logging.level.org.hibernate.validator=${hazelcast.mc.log.level:WARN}
logging.level.org.eclipse.jetty=WARN
Changing the Log Level
To change the logging level for all loggers, start
Management Center with the hazelcast.mc.log.level
property. For example, to use the debug logging level, start Management Center with the following line:
-Dhazelcast.mc.log.level=debug
To change the logging level for the specific logger, start Management Center with the system property of the following format:
logging.level.<logger-name>=<level>
, where level
is one of TRACE
, DEBUG
, INFO
, WARN
, ERROR
, FATAL
, or OFF
. The root
logger can be configured by using logging.level.root
.
For example,
-Dlogging.level.root=DEBUG
-Dlogging.level.web=TRACE
-Dlogging.level.org.springframework=INFO
Customizing the Logging Configuration
To further customize the logging configuration, you can create a custom
Log4j 2 configuration file and start Management Center with
the logging.config
property.
For example, you can create a file named log4j2-custom.properties
with the following
content and write log messages into rolling log files.
To use this file as the logging configuration, you would start Management Center with the
-Dlogging.config=/path/to/your/log4j2-custom.properties
command line parameter:
appender.console.type=Console
appender.console.name=STDOUT
appender.console.layout.type=PatternLayout
appender.console.layout.pattern=%d [%highlight{${LOG_LEVEL_PATTERN:-%5p}}{FATAL=red, ERROR=red, WARN=yellow, INFO=green, DEBUG=magenta}] [%style{%t{1.}}{cyan}] [%style{%c{1.}}{blue}]: %m%n
appender.rolling.type=RollingFile
appender.rolling.name=RollingFile
appender.rolling.fileName=${sys:user.home}/mc-logs/mc.log
appender.rolling.filePattern=${sys:user.home}/mc-logs/mc.%d{yyyy-MM-dd}.log
appender.rolling.layout.type=PatternLayout
appender.rolling.layout.pattern=%d [%5p] [%t] [%c{.1}]: %m%n
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
rootLogger.level=info
rootLogger.appenderRef.stdout.ref=STDOUT
rootLogger.appenderRef.rolling.ref=RollingFile
To enable JSON logging, you can activate json-logging
profile by starting Management Center with the following parameter:
-Dspring.profiles.active=json-logging
By default, Management Center uses a JSON logging template compliant with Elastic Common Schema (ECS) specification. You can change the logging template by providing a JSON logging template file as follows:
-Dlogging.json.template=<json-file-path>
To use a custom JSON logging template, you must activate the json-logging profile as described above.
|
For more information about the JSON logging templates, see the Log4j2 JSON Layout documentation.
Audit Logging
To make it easier to examine suspicious activity and troubleshoot issues, you can use audit logging to keep a record of events that happen in Management Center such as user logins.
To enable audit logging, start Management Center with the hazelcast.mc.auditlog.enabled
property set to true
.
Log entries from the audit logging will be marked with the
hazelcast.auditlog
logging category, abbreviated as h.auditlog
in logs.
An example log entry looks like the following:
2020-10-13 09:57:54,803 [ INFO] [qtp973576304-35] [h.auditlog]: MC-2001 [Auth]:User logged in:{username=JohnHallaign}
MC-2001 [Auth]
you see in this example represents the log’s type.
Audit Logging Event Types
The following table lists the current log categories along with their types:
Event Category | Log Type/Description |
---|---|
Management Center Configuration Logs |
|
Cluster Configuration Logs |
|
Authentication Logs |
|
Scripting Logs |
|
Console Logs |
|
Map/Cache Logs |
|
Persistence Logs |
|
WAN Replication Logs |
|
CP Subsystem Logs |
|
Streaming Job Logs |
|
Writing Audit Logs to Rolling Files
To write audit logs to separate rolling log files, you can use a Log4j 2 configuration file such as the following:
appender.console.type=Console
appender.console.name=STDOUT
appender.console.layout.type=PatternLayout
appender.console.layout.pattern=%d [%highlight{${LOG_LEVEL_PATTERN:-%5p}}{FATAL=red, ERROR=red, WARN=yellow, INFO=green, DEBUG=magenta}] [%style{%t{1.}}{cyan}] [%style{%c{1.}}{blue}]: %m%n
appender.audit.type=RollingFile
appender.audit.name=AuditFile
appender.audit.fileName=${sys:user.home}/mc-logs/audit.log
appender.audit.filePattern=${sys:user.home}/mc-logs/audit.%d{yyyy-MM-dd}.log
appender.audit.layout.type=PatternLayout
appender.audit.layout.pattern=%d [%5p] [%t] [%c{.1}]: %m%n
appender.audit.policies.type = Policies
appender.audit.policies.time.type = TimeBasedTriggeringPolicy
logger.audit.name=hazelcast.auditlog
logger.audit.level=info
logger.audit.additivity=false
logger.audit.appenderRef.audit.ref=AuditFile
rootLogger.level=info
rootLogger.appenderRef.stdout.ref=STDOUT