"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.MessageConversion = void 0; var _ansiRegex = _interopRequireDefault(require("ansi-regex")); /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0 and the Server Side Public License, v 1; you may not use this file except * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ // Defining it globally because it's more performant than creating for each log entry // We can reuse the same global RegExp here because `.replace()` automatically resets the `.lastIndex` of the RegExp. const ANSI_ESCAPE_CODES_REGEXP = (0, _ansiRegex.default)(); const MessageConversion = { pattern: /%message/g, convert(record) { var _record$error; // Error stack is much more useful than just the message. const str = ((_record$error = record.error) === null || _record$error === void 0 ? void 0 : _record$error.stack) || record.message; // We need to validate it's a string because, despite types, there are use case where it's not a string :/ return typeof str === 'string' ? str.replace(ANSI_ESCAPE_CODES_REGEXP, '') : str; } }; exports.MessageConversion = MessageConversion;