Centralize logging for your App. This service allows different levels e.g. info, debug, fatal, error etc. to log a message and query the messages based on different parameters. You can fetch logs based on module, level, message, date range etc.
In order to use the various functions available under a particular API, a developer will have to create an instance of ServiceAPI by passing the apiKey and the secretKey which has been received while creating an app.
ServiceAPI api = new ServiceAPI("<API_KEY>","<SECRET_KEY>");
After initialization, developer needs to call the buildXXXService method on ServiceAPI instance to get the instance of the particular API that you wish to build. For example, To build an instance of LogService, buildLogService() method needs to be called.
LogService logService = api.buildLogService();
Once the API instance has been retrieved, You are ready to use the functions available for that particular API.
The methods available under a particular API will return the domain object (like Log in this case) as a response which will have the accessor / mutator to access the available properties for that object. You can get the response in the form of JSON as well. We have provided the JSON response with every function detail which can be retrieved by calling the toString() on the returned object.
String msg = "Info logs";
String module = "testmod";
Log log = logService.info(msg,module); /* returns the Log object. */
ArrayList<Log.Message> messageList = log.getMessageList();
for(Log.Message message : messageList)
{
System.out.println("msg is " + message.getMessage());
System.out.println("module is " + message.getModule());
System.out.println("type is " + message.getType());
System.out.println("logTime is " + message.getLogTime());
}
String jsonResponse = log.toString(); /* returns the response in JSON format. */
The functions available under Logging API can throw some exceptions in abnormal conditions. Example of the same has been given below.
E.g. If App developer is requesting the logs for the module which is not in the database, the function will throw the App42Exception (as shown below) with message as "Not Found" and the appErrorCode as "2700" and the details as "Logs for the module '<module>' does not exist".
String moduleName = "testmod";
try
{
Log log = logService.fetchLogsByModule(moduleName);
}
catch(App42Exception ex)
{
int appErrorCode = ex.getAppErrorCode();
int httpErrorCode = ex.getHttpErrorCode();
if(appErrorCode == 2700)
{
// Handle here for Not Found (Logs for the module '<module>' does not exist.)
}
else if(appErrorCode == 1401)
{
// handle here for Client is not authorized
}
else if(appErrorCode == 1500)
{
// handle here for Internal Server Error
}
String jsonText = ex.getMessage(); /* returns the Exception text in JSON format. (as shown below)*/
}
{
"app42Fault": {
"httpErrorCode": 404,
"appErrorCode": 2700,
"message": "Not Found",
"details": "Logs for the module 'testmod' does not exist"
}
}
Below are the HTTP Error Codes and their description, the function under the Logging API can throw.
/* 1400 - BAD REQUEST - The Request parameters are invalid 1401 - UNAUTHORIZED - Client is not authorized 1500 - INTERNAL SERVER ERROR - Internal Server Error. Please try again */
Below are the Application Error Codes and their description, the function under the Logging API can throw.
/* 2700 - NOT FOUND - Logs for the module '<module>' does not exist. 2701 - NOT FOUND - Logs for the type '<type>' does not exist. 2702 - Not Found - Logs betweem startDate '<startDate>' and endDate '<endDate>' does not exist. 2703 - NOT FOUND - Logs for the module '<module>' with text '<text>' does not exist. 2704 - NOT FOUND - The number of logs for the module '<module>' are less than the specified offset : <offset>. 2705 - NOT FOUND - The number of logs for the module '<module>' are less thanThe number of logs for the type '<type>' are less than the specified offset : <offset>.he specified offset : <offset>. 2706 - NOT FOUND - The number of logs betweem startDate '<startDate>' and endDate '<endDate>' are less than the specified offset : <offset>. 2707 - NOT FOUND - The number of logs for the module '<module>' with text '<text>' are less than the specified offset : <offset>. */
Various functions available under Logging API has been explained below.
Logs the info message
Parameters:
Returns:
Response: Log Object
String msg = "Info logs";
String module = "testmod";
Log log = logService.info(msg,module); /* returns the Log object. */
ArrayList<Log.Message> messageList = log.getMessageList();
for(Log.Message message : messageList)
{
System.out.println("msg is " + message.getMessage());
System.out.println("module is " + message.getModule());
System.out.println("type is " + message.getType());
System.out.println("logTime is " + message.getLogTime());
}
String jsonResponse = log.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"logs": {
"log": {
"message": "Info logs",
"type": "INFO",
"logTime": "2012-05-09T12:38:17.437Z",
"module": "testmod"
}
}
}
}
} Logs the debug message
Parameters:
Returns:
Response: Log Object
String msg = "Debug logs";
String module = "testmod";
Log log = logService.debug(msg,module); /* returns the Log object. */
ArrayList<Log.Message> messageList = log.getMessageList();
for(Log.Message message : messageList)
{
System.out.println("msg is " + message.getMessage());
System.out.println("module is " + message.getModule());
System.out.println("type is " + message.getType());
System.out.println("logTime is " + message.getLogTime());
}
String jsonResponse = log.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"logs": {
"log": {
"message": "Debug logs",
"type": "DEBUG",
"logTime": "2012-05-09T12:39:33.237Z",
"module": "testmod"
}
}
}
}
}Logs the fatal message
Parameters:
Returns:
Response: Log Object
String msg = "Fatal logs";
String module = "testmod";
Log log = logService.fatal(msg,module); /* returns the Log object. */
ArrayList<Log.Message> messageList = log.getMessageList();
for(Log.Message message : messageList)
{
System.out.println("msg is " + message.getMessage());
System.out.println("module is " + message.getModule());
System.out.println("type is " + message.getType());
System.out.println("logTime is " + message.getLogTime());
}
String jsonResponse = log.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"logs": {
"log": {
"message": "Fatal logs",
"type": "FATAL",
"logTime": "2012-05-09T12:40:49.678Z",
"module": "testmod"
}
}
}
}
}Logs the error message
Parameters:
Returns:
Response: Log Object
String msg = "Error logs";
String module = "testmod";
Log log = logService.error(msg,module); /* returns the Log object. */
ArrayList<Log.Message> messageList = log.getMessageList();
for(Log.Message message : messageList)
{
System.out.println("msg is " + message.getMessage());
System.out.println("module is " + message.getModule());
System.out.println("type is " + message.getType());
System.out.println("logTime is " + message.getLogTime());
}
String jsonResponse = log.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"logs": {
"log": {
"message": "Error logs",
"type": "ERROR",
"logTime": "2012-05-09T12:45:47.435Z",
"module": "testmod"
}
}
}
}
}Fetch the log messages based on the Module
Parameters:
Returns:
Response: Log Object
Exception:
/* 2700 - NOT FOUND - Logs for the module '<module>' does not exist. */
String moduleName = "testmod";
Log log = logService.fetchLogsByModule(moduleName); /* returns the Log object. */
ArrayList<Log.Message> messageList = log.getMessageList();
for(Log.Message message : messageList)
{
System.out.println("msg is " + message.getMessage());
System.out.println("module is " + message.getModule());
System.out.println("type is " + message.getType());
System.out.println("logTime is " + message.getLogTime());
}
String jsonResponse = log.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"logs": {
"log": [
{
"message": "Info logs",
"logTime": "2012-05-09T12:37:57.000Z",
"module": "testmod",
"type": "INFO"
},
{
"message": "Info logs",
"logTime": "2012-05-09T12:38:17.000Z",
"module": "testmod",
"type": "INFO"
},
{
"message": "Debug logs",
"logTime": "2012-05-09T12:39:33.000Z",
"module": "testmod",
"type": "DEBUG"
},
{
"message": "Fatal logs",
"logTime": "2012-05-09T12:40:49.000Z",
"module": "testmod",
"type": "FATAL"
},
{
"message": "Error logs",
"logTime": "2012-05-09T12:45:47.000Z",
"module": "testmod",
"type": "ERROR"
}
]
}
}
}
}Fetch the count of log messages based on the Module
Parameters:
Returns:
Response: App42Response Object
String moduleName = "testmod"; App42Response response = logService.fetchLogsCountByModule(moduleName); /* returns the App42Response objects. */ boolean success = response.isResponseSuccess(); int totalRecords = response.getTotalRecords(); String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"totalRecords": 3
}
}
}Fetch the log messages based on the Module by paging
Parameters:
Returns:
Response: Log Object
Exception:
/* 2700 - NOT FOUND - Logs for the module '<module>' does not exist. 2704 - NOT FOUND - The number of logs for the module '<module>' are less than the specified offset : <offset>. */
String moduleName = "testmod";
int max = 1;
int offset = 0;
Log log = logService.fetchLogsByModule(moduleName,max,offset); /* returns the Log object. */
ArrayList<Log.Message> messageList = log.getMessageList();
for(Log.Message message : messageList)
{
System.out.println("msg is " + message.getMessage());
System.out.println("module is " + message.getModule());
System.out.println("type is " + message.getType());
System.out.println("logTime is " + message.getLogTime());
}
String jsonResponse = log.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"logs": {
"log": {
"message": "debug logs",
"logTime": "2012-06-02T14:08:26.000Z",
"module": "testmod",
"type": "DEBUG"
}
}
}
}
}Fetch log messages based on the Module and Message Text.
Parameters:
Returns:
Response: Log Object
Exception:
/* 2703 - NOT FOUND - Logs for the module '<module>' with text '<text>' does not exist. */
String moduleName = "testmod";
String text = "Info logs";
Log log = logService.fetchLogsByModuleAndText(moduleName, text); /* returns the Log object. */
ArrayList<Log.Message> messageList = log.getMessageList();
for(Log.Message message : messageList)
{
System.out.println("msg is " + message.getMessage());
System.out.println("module is " + message.getModule());
System.out.println("type is " + message.getType());
System.out.println("logTime is " + message.getLogTime());
}
String jsonResponse = log.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"logs": {
"log": [
{
"message": "Info logs",
"logTime": "2012-05-09T12:37:57.000Z",
"module": "testmod",
"type": "INFO"
},
{
"message": "Info logs",
"logTime": "2012-05-09T12:38:17.000Z",
"module": "testmod",
"type": "INFO"
}
]
}
}
}
}Fetch count of log messages based on the Module and Message Text
Parameters:
Returns:
Response: App42Response Object
String moduleName = "testmod"; String text = "debug logs"; App42Response response = logService.fetchLogsCountByModuleAndText(moduleName,text); /* returns the App42Response objects. */ boolean success = response.isResponseSuccess(); int totalRecords = response.getTotalRecords(); String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"totalRecords": 3
}
}
}Fetch log messages based on the Module and Message Text by paging.
Parameters:
Returns:
Response: Log Object
Exception:
/* 2707 - NOT FOUND - The number of logs for the module '<module>' with text '<text>' are less than the specified offset : <offset>. */
String moduleName = "testmod";
String text = "debug logs";
int max = 1;
int offset = 0;
Log log = logService.fetchLogsByModuleAndText(moduleName,text,max,offset); /* returns the Log object. */
ArrayList<Log.Message> messageList = log.getMessageList();
for(Log.Message message : messageList)
{
System.out.println("msg is " + message.getMessage());
System.out.println("module is " + message.getModule());
System.out.println("type is " + message.getType());
System.out.println("logTime is " + message.getLogTime());
}
String jsonResponse = log.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"logs": {
"log": {
"message": "debug logs",
"logTime": "2012-06-02T14:08:22.000Z",
"module": "testmod",
"type": "DEBUG"
}
}
}
}
}
Fetch log messages based on Info Level.
Parameters:
Returns:
Response: Log Object
Exception:
/* 2701 - NOT FOUND - Logs for the type '<type>' does not exist. */
Log log = logService.fetchLogsByInfo(); /* returns the Log object. */
ArrayList<Log.Message> messageList = log.getMessageList();
for(Log.Message message : messageList)
{
System.out.println("msg is " + message.getMessage());
System.out.println("module is " + message.getModule());
System.out.println("type is " + message.getType());
System.out.println("logTime is " + message.getLogTime());
}
String jsonResponse = log.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"logs": {
"log": [
{
"message": "Info logs",
"logTime": "2012-05-09T12:37:57.000Z",
"module": "testmod",
"type": "INFO"
},
{
"message": "Info logs",
"logTime": "2012-05-09T12:38:17.000Z",
"module": "testmod",
"type": "INFO"
}
]
}
}
}
}
Fetch count of log messages based on Info Level
Parameters:
Returns:
Response: App42Response Object
App42Response response = logService.fetchLogsCountByInfo(); /* returns the App42Response objects. */ boolean success = response.isResponseSuccess(); int totalRecords = response.getTotalRecords(); String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"totalRecords":3
}
}
}
Fetch log messages based on Info Level by paging
Parameters:
Returns:
Response: Log Object
Exception:
/* 2705 - NOT FOUND - The number of logs for the module '<module>' are less thanThe number of logs for the type '<type>' are less than the specified offset : <offset>.he specified offset : <offset>. */
int max = 1;
int offset = 0;
Log log = logService.fetchLogsByInfo(max,offset); /* returns the Log object. */
ArrayList<Log.Message> messageList = log.getMessageList();
for(Log.Message message : messageList)
{
System.out.println("msg is " + message.getMessage());
System.out.println("module is " + message.getModule());
System.out.println("type is " + message.getType());
System.out.println("logTime is " + message.getLogTime());
}
String jsonResponse = log.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"logs": {
"log": {
"message": "info logs",
"logTime": "2012-06-02T14:14:54.000Z",
"module": "testmod",
"type": "INFO"
}
}
}
}
}Fetch log messages based on Debug Level.
Parameters:
Returns:
Response: Log Object
Exception:
/* 2701 - NOT FOUND - Logs for the type '<type>' does not exist. */
Log log = logService.fetchLogsByDebug(); /* returns the Log object. */
ArrayList<Log.Message> messageList = log.getMessageList();
for(Log.Message message : messageList)
{
System.out.println("msg is " + message.getMessage());
System.out.println("module is " + message.getModule());
System.out.println("type is " + message.getType());
System.out.println("logTime is " + message.getLogTime());
}
String jsonResponse = log.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"logs": {
"log": {
"message": "Debug logs",
"logTime": "2012-05-09T12:39:33.000Z",
"module": "testmod",
"type": "DEBUG"
}
}
}
}
}Fetch count of log messages based on Debug Level
Parameters:
Returns:
Response: App42Response Object
App42Response response = logService.fetchLogsCountByDebug(); /* returns the App42Response objects. */ boolean success = response.isResponseSuccess(); int totalRecords = response.getTotalRecords(); String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"totalRecords": 3
}
}
}Fetch log messages based on Debug Level by paging.
Parameters:
Returns:
Response: Log Object
Exception:
/* 2705 - NOT FOUND - The number of logs for the module '<module>' are less thanThe number of logs for the type '<type>' are less than the specified offset : <offset>.he specified offset : <offset>. */
int max = 1;
int offset = 0;
Log log = logService.fetchLogsByDebug(max,offset); /* returns the Log object. */
ArrayList<Log.Message> messageList = log.getMessageList();
for(Log.Message message : messageList)
{
System.out.println("msg is " + message.getMessage());
System.out.println("module is " + message.getModule());
System.out.println("type is " + message.getType());
System.out.println("logTime is " + message.getLogTime());
}
String jsonResponse = log.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"logs": {
"log": {
"message": "debug logs",
"logTime": "2012-06-02T14:08:22.000Z",
"module": "testmod",
"type": "DEBUG"
}
}
}
}
}Fetch log messages based on Error Level.
Parameters:
Returns:
Response: Log Object
Exception:
/* 2701 - NOT FOUND - Logs for the type '<type>' does not exist. */
Log log = logService.fetchLogsByError(); /* returns the Log object. */
ArrayList<Log.Message> messageList = log.getMessageList();
for(Log.Message message : messageList)
{
System.out.println("msg is " + message.getMessage());
System.out.println("module is " + message.getModule());
System.out.println("type is " + message.getType());
System.out.println("logTime is " + message.getLogTime());
}
String jsonResponse = log.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"logs": {
"log": {
"message": "Error logs",
"logTime": "2012-05-09T12:45:47.000Z",
"module": "testmod",
"type": "ERROR"
}
}
}
}
}Fetch count of log messages based on Error Level
Parameters:
Returns:
Response: App42Response Object
App42Response response = logService.fetchLogsCountByError(); /* returns the App42Response objects. */ boolean success = response.isResponseSuccess(); int totalRecords = response.getTotalRecords(); String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"totalRecords": 3
}
}
} Fetch log messages based on Error Level by paging.
Parameters:
Returns:
Response: Log Object
Exception:
/* 2705 - NOT FOUND - The number of logs for the module '<module>' are less thanThe number of logs for the type '<type>' are less than the specified offset : <offset>.he specified offset : <offset>. */
int max = 1;
int offset = 0;
Log log = logService.fetchLogsByError(max,offset); /* returns the Log object. */
ArrayList<Log.Message> messageList = log.getMessageList();
for(Log.Message message : messageList)
{
System.out.println("msg is " + message.getMessage());
System.out.println("module is " + message.getModule());
System.out.println("type is " + message.getType());
System.out.println("logTime is " + message.getLogTime());
}
String jsonResponse = log.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"logs": {
"log": {
"message": "error logs",
"logTime": "2012-06-02T14:17:14.000Z",
"module": "testmod",
"type": "ERROR"
}
}
}
}
}Fetch log messages based on Fatal Level.
Parameters:
Returns:
Response: Log Object
Exception:
/* 2701 - NOT FOUND - Logs for the type '<type>' does not exist. */
Log log = logService.fetchLogsByFatal(); /* returns the Log object. */
ArrayList<Log.Message> messageList = log.getMessageList();
for(Log.Message message : messageList)
{
System.out.println("msg is " + message.getMessage());
System.out.println("module is " + message.getModule());
System.out.println("type is " + message.getType());
System.out.println("logTime is " + message.getLogTime());
}
String jsonResponse = log.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"logs": {
"log": {
"message": "Fatal logs",
"logTime": "2012-05-09T12:40:49.000Z",
"module": "testmod",
"type": "FATAL"
}
}
}
}
}Fetch count of log messages based on Fatal Level
Parameters:
Returns:
Response: App42Response Object
App42Response response = logService.fetchLogsCountByFatal(); /* returns the App42Response objects. */ boolean success = response.isResponseSuccess(); int totalRecords = response.getTotalRecords(); String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"totalRecords": 3
}
}
}Fetch log messages based on Fatal Level by paging.
Parameters:
Returns:
Response: Log Object
Exception:
/* 2705 - NOT FOUND - The number of logs for the module '<module>' are less thanThe number of logs for the type '<type>' are less than the specified offset : <offset>.he specified offset : <offset>. */
int max = 1;
int offset = 0;
Log log = logService.fetchLogsByFatal(max,offset); /* returns the Log object. */
ArrayList<Log.Message> messageList = log.getMessageList();
for(Log.Message message : messageList)
{
System.out.println("msg is " + message.getMessage());
System.out.println("module is " + message.getModule());
System.out.println("type is " + message.getType());
System.out.println("logTime is " + message.getLogTime());
}
String jsonResponse = log.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"logs": {
"log": {
"message": "fatal logs",
"logTime": "2012-06-02T14:18:00.000Z",
"module": "testmod",
"type": "FATAL"
}
}
}
}
}Fetch log messages based on Date range.
Parameters:
Returns:
Response: Log Object
Exception:
/* 2702 - Not Found - Logs betweem startDate '<startDate>' and endDate '<endDate>' does not exist. */
Date startDate = new Date(new Date().getTime() - 60 * 60 * 1000) ;
Date endDate = new Date(new Date().getTime()) ;
Log log = logService.fetchLogByDateRange(startDate, endDate); /* returns the Log object. */
ArrayList<Log.Message> messageList = log.getMessageList();
for(Log.Message message : messageList)
{
System.out.println("msg is " + message.getMessage());
System.out.println("module is " + message.getModule());
System.out.println("type is " + message.getType());
System.out.println("logTime is " + message.getLogTime());
}
String jsonResponse = log.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"logs": {
"log": [
{
"message": "Fatal logs",
"logTime": "2012-05-13T05:42:37.000Z",
"module": "testmod",
"type": "FATAL"
},
{
"message": "Hello",
"logTime": "2012-05-13T05:43:05.000Z",
"module": "Module",
"type": "DEBUG"
},
{
"message": "Hello",
"logTime": "2012-05-13T05:43:48.000Z",
"module": "Module",
"type": "DEBUG"
}
]
}
}
}
}Fetch count of log messages based on Date range
Parameters:
Returns:
Response: App42Response Object
Date startDate = new Date(new Date().getTime() - 60 * 60 * 1000) ; Date endDate = new Date(new Date().getTime()) ; App42Response response = logService.fetchLogCountByDateRange(startDate,endDate); /* returns the App42Response objects. */ boolean success = response.isResponseSuccess(); int totalRecords = response.getTotalRecords(); String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"totalRecords": 3
}
}
}Fetch log messages based on Date range by paging.
Parameters:
Returns:
Response: Log Object
Exception:
/* 2706 - NOT FOUND - The number of logs betweem startDate '<startDate>' and endDate '<endDate>' are less than the specified offset : <offset>. */
Date startDate = new Date((new Date().getTime() - 30 * 30 * 1000) - 86400000);
Date endDate = new Date(new Date().getTime() - 86400000);
int max = 1;
int offset = 0;
Log log = logService.fetchLogByDateRange(startDate,endDate,max,offset); /* returns the Log object. */
ArrayList<Log.Message> messageList = log.getMessageList();
for(Log.Message message : messageList)
{
System.out.println("msg is " + message.getMessage());
System.out.println("module is " + message.getModule());
System.out.println("type is " + message.getType());
System.out.println("logTime is " + message.getLogTime());
}
String jsonResponse = log.toString(); /* returns the response in JSON format. (as shown below)*/
{
"app42": {
"response": {
"success": true,
"logs": {
"log": {
"message": "info logs",
"logTime": "2012-06-05T10:59:27.000Z",
"module": "testmod",
"type": "INFO"
}
}
}
}
}