|
11.1 Logging Service : An Overview
11.2 Logging ServiceMBean
11.3 Logging Levels
11.5 Viewing Log Files
11.6 Printing of log messages to module specific log files
11.7 Dynamically adding new logging modules and loggers at runtime
11.8 Archive Support
11.9 Customizing Logging Service
11.1 Logging Service : An Overview
At run time, agent generates log messages for the user to know about the agent processing. These log messages are stored in a text file . Each log message has an associated log Level. The Level gives a rough idea about the importance and urgency of a log message. The user can select the level of log message to be recorded in the log file. Log messages with log level less than that chosen by the user are discarded and are not recorded in the log file.
Salient features of AdventNet Logging Service :
Pinpointing bugs, configuration errors, performance blockades, etc.
Printing of log and error messages of various modules.
Printing of log messages to module-specific log files can be availed by specifying the log filename, logging levels, etc.
Enabling/disabling Logging for various modules at run time.
Dynamically adding new Logging modules and Loggers at run time.
Smart Archiving Support for Log files.
AdventNet Multi-Protocol agent has implemented Logging Service as an MBean so that it may be registered in an agent and configured by remote applications. The LogFactoryController is the MBean used to configure and customize logging. The MBean enables one to configure logging at run time. The following code snippet generated in the main file is used to register this MBean.
|
//Registering the LogFactoryController MBean. |
The AdventNet Logging Service supports the following logging levels:
Disabled (0) : This level indicates that the log messages do not get stored in the text file.
Fatal (1) : Fatal level indicates that the application has encountered a severe error that may make the system unstable. These errors need to be attended to immediately. When this level is chosen, only critical messages such as details on Agent crash, Authentication errors, Agent already open in another session, etc., get stored in the log file.
Error (2) : Error level indicates that an error has occurred and the application cannot handle the request as designed. This may automatically be corrected during execution or the application should be capable of handling those situations when a similar request comes again. Selecting this level stores all the Error and Exception messages in the log file along with the fatal messages.
Warn (3) : Warning messages indicate that the application has met with an expected error. All Warning messages get stored in the log file when debug level is Warn. Log messages corresponding to log levels 1 and 2 are also stored in the log file.
Debug (4) : On choosing this log level, the application moves into the debug mode. It will be used for generating debugging information and should not be used in general cases.
Info (5) : The Info level does not signify the occurrence of any error but logs all important events. Any information that might be required for reference gets stored in the log file under this info level.
Trace (6) : In this mode, the application logs every activity from entering a method to exiting. Hence, selecting this level may affect performance. The Trace level should be used only to solve any complex problem.
You can specify the required logging level using JMX Compiler UI or using API.
Using JMX Compiler UI
|
Using API
The logging level can also be specified by adding the relevant code directly in the generated main file. The following code snippet will set the log level to debug level.
|
LogFactory.setLoggingLevel(debugLevel); |
The log messages get stored in a text file named agent.log.
This file gets created as soon as the Agent is started and produces reports based on the specified debug level . Log messages include debug levels equal to and lesser than the level specified.
These messages can be viewed from the logs folder in <Agent Toolkit Home>/jmxprojects/projectName/agent/bin/logs directory.
Once the Agent is stopped and restarted ,the older log messages get shifted to agent1.log and the newly started Agent transfers its log messages to agent.log. This keeps continuing until agent9.log.
Later, the log messages are zipped and placed under the archives folder of the logs directory excepting for the latest one. Please refer to Archive support to know more about this feature.
Thus, agent.log always shows the log messages of the recently started Agent.
11.6 Printing of log messages to module specific log files
To write log messages to module specific log files, get the corresponding logger. For example, if you want to write the logging related to JMX core, to be in a file called JMX.log, please use LogFactory.getInstance("JMX","JMX.log","."). Then use this logger for logging purposes.
11.7 Dynamically adding new logging modules and loggers at runtime
LogFactory.getInstance(String loggerName) will yield a new logger with the specified loggername.
Each time the agent is restarted, a separate log file is created. In some cases, we may need to keep these log files for future reference. In order to achieve this, the Archiving support has been added. This feature gives you the option to preserve the log files, if you wish.
The log files will be stored in a zip file bearing archive file name in the format <filename>.zip. The individual log file will be stored with the name in the format <filename>_date_in_desired_format.txt. For example, if the filename is agent.txt then archive file name would be agent.zip.
11.9 Customizing the Logging Service
You can customize logging services such as changing the debug level, changing the filename/directory name, enabling/disabling logging support, etc., at agent run time. This can be done from MBean Browser/HTTP Console or using the API methods.
|
|
Note: To customize using MBean Browser, the browser must be started and connected to the server. |
11.9.1 To Set Logging Level for the Multi-Protocol agent
You can set a logging level for the Multi-Protocol agent. This can be done either using the MBean Browser/ HTTP Console or by calling the appropriate methods.
11.9.1.1 Using MBean Browser/ HTTP Console
Select Service, type = logging, from the Domain tree structure.
Select the Operation -> SetLoggingLevel.
Specify the logging level.
Click OK button.
11.9.1.2 Using API
The following method must be called inside the agent. The parameter int level should be any one of the logging levels explained above.
|
LogFactory.setLoggingLevel(int level) |
11.9.2 To Change Log File Name and Directory
You can change the default log file name and logging directory as per your requirement. This can be done either using the MBean Browser or by calling the appropriate methods.
11.9.2.2.1 Using MBean Browser
Select Service, type = logging , from the Domain tree structure.
Select the Operation -> changeLoggingLocation.
Specify the filename and the Directory Name in the options provided. You must specify the absolute path of the directory.
Click OK button.
11.9.2.2.2 Using API
The following method must be called inside the agent. The parameter to be passed are Log file name and the directory name.
|
LogFactory.changeLoggingLocation(java.lang.String name, java.lang.String location) |
11.9.3 To Disable Logging for a Specific Adaptor / Client
You can disable logging service for a specific adaptor/client. This can be done either using the MBean Browser or by calling the appropriate methods.
11.9.3.1 Using MBean Browser
Select Service, type = logging , from the Domain tree structure.
Select the Operation -> stoplogging.
Specify the name of the adaptor in which logging service is not required.
Click OK button.
11.9.3.2 Using API
The following method must be called inside the agent. The adaptor name should be passed as the adaptor.
|
stopLogging(java.lang.String name) |
11.9.4 To Start and Stop the Logging Service
You can stop and restart the logging service at agent run time. This can be done either using the MBean Browser or by calling the appropriate methods.
11.9.4.1 Using MBean Browser
Select Service, type = logging , from the Domain tree structure.
Select the Operation -> stoplogging, for stopping the logging service.
Select the Operation -> startlogging, for restarting the logging service.
11.9.4.2 Using API
The following method must be called inside the agent.
|
stopLogging() |
|