logs.LogException
Overview¶
The "LogException" method of the "logs Object". It displays and outputs logs as type Exception in "Server Script".
Syntax¶
Parameters¶
| Parameters | Type | Required | Description |
|---|---|---|---|
| message | string | Yes | Specifies the error content 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. |
Output Column in System Log¶
| Destination column | Output content | Notes |
|---|---|---|
| ErrMessage | The string set in the message | |
| Method | Combines the original method string with:methodformat | |
| SysLogType | 90 | Fixed at 90(Exception) |
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. If an exception occurs, the log is output.
JavaScript¶
try {
const siteId = 2;
const item = items.NewIssue();
item.Title = 'About the Version Upgrade of Pleasanter';
const ret = items.Create(siteId, item);
} catch(e) {
// Exceptionログ
logs.LogException(`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 each method of the logs object so that log output can be switched between debugging and production.
Functional requirements¶
-
Output control by a debug flag
logger.debug()is output only whenDEBUG_MODE(bool) is set totrue. When it isfalse, the output is completely suppressed. -
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 levels
The following 6 methods are provided, and each delegates to the corresponding
logsmethod.Method Delegates to Always output logger.debug() LogInfo ✗ (debugging only) logger.info() LogInfo ✓ logger.warn() LogWarning ✓ logger.userError() LogUserError ✓ logger.systemError() LogSystemError ✓ logger.exception() LogException ✓
JavaScript¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
Supported Versions¶
| Supported Versions | Body |
|---|---|
| 1.4.12.0 or later | Added function |