Skip to content

logs.LogSystemError

Overview

This is the "LogSystemError" method of the "logs Object". It displays and outputs the log in the "Server Script" as log type: SystemError.

Syntax

logs.LogSystemError(message, method, console, syslogs)

Parameters

Parameter Type Required Description
message string Yes Specifies the error content to be displayed and output.
method string Optional. Default is an empty string.
console bool Optional. Default is true. Specify true to display in the browser's developer tool console
syslogs bool Optional. Default is true. Specify true to output to the system log

Return Value

Returns true if the log can be displayed and output, or false if it cannot be displayed or output.

Display content when displayed on console

Display format
(SystemError):[Method]Message
Display column Display content Notes
Message String set in message
Method String set in method If method is not specified, square brackets ([]) are not displayed either

Output destination column when outputting system log

Output destination column Output content Notes
ErrMessage String set in message
Method String combined with the original string recorded in Method in the format of ":method"
SysLogType 80 Fixed to 80 (SystemError)

Usage Examples

In the example below, the title of the "Limited table" for site ID 2 is "About upgrading Pleasanter" Creates a record and outputs a log if creation fails.

JavaScript
const siteId = 2;
const item = items.NewIssue();
item.Title = 'About upgrading Pleasanter';
const ret = items.Create(siteId, item);
if (!ret) {
    logs.LogSystemError(`Failed to create record. Site ID: ${siteId}`);
}

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
  1. Output control by a debug flag
    logger.debug() is output only when DEBUG_MODE (bool) is set to true. When it is false, the output is completely suppressed.

  2. 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.

  3. Log levels

    The following 6 methods are provided, and each delegates to the corresponding logs method.

    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
// ============================================================
// Debug mode. Set to true to output debug() logs
// ============================================================
const DEBUG_MODE = false;
/**
 * Control of output destinations
 *   console : whether to output to the console of the browser's developer tools
 *   syslogs : whether to output to the system log (SysLogs table)
 */
const LOG_TARGET = {
    console: true,
    syslogs: true,
};
// ============================================================
// Logger
// ============================================================
const logger = (function (debugMode, target) {
    /**
     * Internal common output function
     * @param {Function} logFn   - Method of the logs object
     * @param {string}   message - Log message
     * @param {string}   method  - Method name (optional)
     * @param {boolean}  forceOutput - Whether to always output regardless of debug mode
     */
    function _write(logFn, message, method, forceOutput) {
        if (!forceOutput && !debugMode) return;
        const m = method || '';
        logFn(message, m, target.console, target.syslogs);
    }
    return {
        /**
         * Debug log (output as Info only when DEBUG_MODE=true)
         * @param {string} message
         * @param {string} [method]
         */
        debug: function (message, method) {
            _write(
                function (msg, mth, con, sys) {
                    logs.LogInfo(msg, mth, con, sys);
                },
                '[DEBUG] ' + message,
                method,
                false, // Output only in debug mode
            );
        },
        /**
         * Information log (always output as Info)
         * @param {string} message
         * @param {string} [method]
         */
        info: function (message, method) {
            _write(
                function (msg, mth, con, sys) {
                    logs.LogInfo(msg, mth, con, sys);
                },
                message,
                method,
                true, // Always output
            );
        },
        /**
         * Warning log (always output as Warning)
         * @param {string} message
         * @param {string} [method]
         */
        warn: function (message, method) {
            _write(
                function (msg, mth, con, sys) {
                    logs.LogWarning(msg, mth, con, sys);
                },
                message,
                method,
                true,
            );
        },
        /**
         * User error log (always output as UserError)
         * @param {string} message
         * @param {string} [method]
         */
        userError: function (message, method) {
            _write(
                function (msg, mth, con, sys) {
                    logs.LogUserError(msg, mth, con, sys);
                },
                message,
                method,
                true,
            );
        },
        /**
         * System error log (always output as SystemError)
         * @param {string} message
         * @param {string} [method]
         */
        systemError: function (message, method) {
            _write(
                function (msg, mth, con, sys) {
                    logs.LogSystemError(msg, mth, con, sys);
                },
                message,
                method,
                true,
            );
        },
        /**
         * Exception log (always output as Exception)
         * Intended to be used in a catch block.
         * @param {Error|string} error   - Error object or message string
         * @param {string}       [method]
         */
        exception: function (error, method) {
            var message;
            if (error && typeof error === 'object' && error.stack) {
                message = error.message + '\n' + error.stack;
            } else {
                message = String(error);
            }
            _write(
                function (msg, mth, con, sys) {
                    logs.LogException(msg, mth, con, sys);
                },
                message,
                method,
                true,
            );
        },
    };
})(DEBUG_MODE, LOG_TARGET);
// ===============
// Usage examples
// ===============
// ─── Example 1: Debug information (output only when DEBUG_MODE=true) ───
logger.debug('Processing started: siteId=' + 1000, 'MyScript');
// ─── Example 2: Normal information log (always output) ───
logger.info('Record created. Record ID: ' + 9999, 'CreateIssue');
// ─── Example 3: Warning log ───
logger.warn('The target record was not found.', 'FetchRecord');
// ─── Example 4: Error caused by the user ───
logger.userError('A required item has not been entered.', 'Validate');
// ─── Example 5: System error ───
logger.systemError('Failed to connect to the API.', 'CallApi');
// ─── Example 6: Exception handling (used together with catch) ───
try {
    const item = items.NewIssue();
    item.Title = 'Test';
    items.Create(2, abcd); // Force an exception
    logger.info('Created successfully', 'CreateIssue');
} catch (e) {
    logger.exception(e, 'CreateIssue');
}

Supported Versions

Suported versions Body
1.4.12.0 or later Added function