logs.Log
Overview¶
The Log method of the "logs Object". It displays and outputs logs of the specified type in "Server Script".
Syntax¶
Parameters¶
| Parameters | Type | Required | Description |
|---|---|---|---|
| type | int | Yes | Specifies the type of log. Possible values are as follows: 10:Info 50:Warning 60:UserError 80:SystemError 90:Exception |
| message | string | Yes | Specifies the content of the error to display and output. |
| method | string | Optional. Default value is an empty string. | |
| console | bool | Optional. Default value is true. Set to true to display in the browser developer tools console. | |
| syslogs | bool | Optional. Default value is true. Set to true to output to the system log. |
Return Value¶
Returns true if the log is successfully displayed and output, otherwise returns false.
Display Format in Console¶
Display Format:¶
| Display column | Display content | Notes |
|---|---|---|
| Message | The string set in the message | |
| Method | The string set in the method | Brackets ([]) are not displayed if the method is not specified. |
| SysLogType | The string displayed based on the type: 10:Info 50:Warning 60:UserError 80:SystemError 90:Exception |
Output Column in System Log¶
| Output destination column | Output content | Notes |
|---|---|---|
| Comments | The string set in the message | For types 10(Info)、50(Warning)、60(UserError) |
| ErrMessage | The string set in the message | For types 80(SystemError)、90(Exception) |
| Method | Combines the original method string with :method format.:methodformat | |
| SysLogType | type |
Usage Examples¶
In the following example, a record with the title "About the Version Upgrade of Pleasanter" is created in a "temporary table" under Site ID 2. Based on the result, logs are output using logs.Log.
JavaScript¶
try {
const siteId = 2;
const item = items.NewIssue();
item.Title = 'About the Version Upgrade of Pleasanter';
const ret = items.Create(siteId, item);
if (ret) {
// Info log
logs.Log(10, `Record created. Record ID:${item.IssueId}`);
} else {
// SystemError log
logs.Log(80, `Failed to create the record. Site ID:${siteId}`);
}
} catch(e) {
// Exception log
logs.Log(90, `Exception occurred\n ${e.stack}`);
}
Code Samples¶
1. A general-purpose logging function
This is a sample code of a general-purpose logger that wraps the logs.Log method so that log output can be switched between debugging and production.
Functional requirements¶
-
Output control by a debug flag
DEBUG_MODE(bool) controls the output of Info (type=10). When it isfalse, Info is suppressed, and when it istrue, Info is output. Warning (50) and above are always output regardless ofDEBUG_MODE. -
Centralized management of output destinations
With
LOG_TARGET(bool values for console / syslogs), output to the console and to the system log can each be turned on or off individually. The settings apply to the whole script at once. -
Log type constants
A constant object
LOG_TYPEcorresponding to thetypeargument oflogs.Logis provided to prevent mistakes caused by writing numbers directly.Constant Value Log type LOG_TYPE.INFO 10 Info LOG_TYPE.WARNING 50 Warning LOG_TYPE.USER_ERROR 60 UserError LOG_TYPE.SYSTEM_ERROR 80 SystemError LOG_TYPE.EXCEPTION 90 Exception -
Two methods
Method Description DEBUG_MODE=false DEBUG_MODE=true logEx.log(type, message, method) A thin wrapper of logs.Log. Only type=10 is suppressed Only Warning and above are output All are output logEx.debug(message, method) For debugging only. Output as Info (10) Not output Output -
Passing the method parameter through
The method argument of each method can be passed as it is to the method parameter of logs.Log.
JavaScript¶
Supported Versions¶
| Supported Versions | Body |
|---|---|
| 1.4.12.0 or later | Added function |