Logs of a system can be stored in many ways. For example, they can be stored in a file system, an sql server such as MySQL, a no-sql server like Cassandra, etc. According to the default configurations in a Carbon product, the logs are stored in the
<PRODUCT_HOME>/repository/logs/ directory as
To view and download the logs using the management console, the following configurations are required: the Logging Management feature should be installed, the log4j properties should be configured and the LogProvider and LogFileProvider interfaces should be implemented and configured for the server as described below.
Implementing the LogProvider interface
org.wso2.carbon.logging.service.provider.api.LogProvider interface is used for viewing logs in the management console. It is introduced as an extension point to provide logs to the "Log Viewer" (in the management console). Any log provider can implement this interface to fetch logs from any mechanism, and the Log Viewer will use this interface to retrieve and show logs in the management console.
LogProvider interface has the following methods:
init(LoggingConfig loggingConfig)- Initialize the log provider by reading the properties defined in the logging configuration file. This will be called immediately after creating a new instance of LogProvider.
- getApplicationNames(String tenantDomain, String serverKey) - Return list of all application names deployed under provided tenant domain and server key.
- getSystemLogs() - Return a list of system LogEvents.
- getAllLogs(String tenantDomain, String serverKey) - Return list of all the logs available under given domain and server key
- getLogsByAppName(String appName, String tenantDomain, String serverKey) - Return list of all the LogEvents belonging to the application, which is deployed under given tenant domain and server key.
- getLogs(String type, String keyword, String appName, String tenantDomain, String serverKey) - Returns list of all LogEvents related to the given application, which match to given type and LogEvent message has given key word with it. User can use this api for search operations.
- logsCount(String tenantDomain, String serverKey) - Return LogEvent count
- clearLogs() - Clear operation. For example, if it is an "in memory" log provider, this method can be used to clear the memory.
Implementing the LogFileProvider interface
org.wso2.carbon.logging.service.provider.api.LogFileProvider interface is used to list and download the archived log files using the management console. It is introduced as an extension point providing the list of log file names and the ability to download these logs to the "Log Viewer".
LogFileProvider interface has the following methods:
- init(LoggingConfig loggingConfig)- Initialize the file log provider by reading the properties defined in the logging configuration file. This will be called immediately after creating a new instance of LogFileProvider.
- getLogFileInfoList(String tenantDomain, String serviceName)- Return information about the log files, which is available under given tenant domain and serviceName. For example, info about logs: log name, log date, log size.
- downloadLogFile(String logFile, String tenantDomain, String serviceName)- Download the file.
Default log provider in Carbon products
A default "in memory" log provider, which implements the
LogProvider interface has been created both as a sample and as the default log provider option in carbon. Main task of this class is to read the carbon logs available in the
<PRODUCT_HOME>/repository/logs/ directory to a buffer stored in memory and enable the LogViewer to fetch and view these logs in the management console.
A default log file provider that implements the
LogFileProvider interface has also been implemented as a sample and as the default log file provider option in carbon. The main task of this class is to read the log file names (including the size and date of these files) from the
<PRODUCT_HOME>/repository/logs/ directory and to enable the download of these logs.
Configuring Carbon to plug the log provider
After implementing the above interfaces, update the
logging-config.xml file stored in the
Shown below is the configuration for the the default log provider and the default log file provider of a Carbon product:
The default "InMemoryLogProvider" uses the CarbonMemoryAppender. Therefore the log4j.properties file stored in <PRODUCT_HOME>/repository/conf/ directory should be updated with the following log4j.appender.CARBON_MEMORY property:
If the implemented class requires additional properties to initialise the class, the
<properties>element in the
logging-config.xmlfile can be used. For example, a cassandra based log provider may need information on keyspace, column family, etc. You can configure these details in the
logging-config.xmlfile and access them at runtime using the
LoggingConfigclass, which contains all configuration parameters. For a Cassandra based log provider, the following properties can be defined in the
logging-config.xmlfile and later used in the implementation using the
LoggingConfigclass, which is assigned when initializing the class.
The following properties can be configured in the
logging-config.xmlfile for a Cassandra based log provider: