From c758872eae23b5e3cad9b83c56035406e934b470 Mon Sep 17 00:00:00 2001 From: Adarsh Madrecha Date: Sun, 30 Jul 2023 20:45:41 +0530 Subject: [PATCH] reverted back from esm to commonjs --- lib/winston-loggly.js | 84 ++++++++++++++++++------------------- package.json | 1 - test/winston-loggly.test.js | 4 +- 3 files changed, 44 insertions(+), 45 deletions(-) diff --git a/lib/winston-loggly.js b/lib/winston-loggly.js index afb0cc9..e5a6bc9 100644 --- a/lib/winston-loggly.js +++ b/lib/winston-loggly.js @@ -6,15 +6,16 @@ * */ -import cloneDeep from 'module'; -import LogglyBulk from '@adarshmadrecha/node-loggly-bulk'; -import util from 'node:util'; -import winston from 'winston'; -import Transport from 'winston-transport'; -import { Stream } from 'node:stream'; - -// Remove the ANSI escape codes from the log messages before they are sent to Loggly. -// This ensures that the log messages are displayed correctly in the Loggly web interface. +const cloneDeep = require('lodash.clonedeep') +const loggly = require('@adarshmadrecha/node-loggly-bulk') +const util = require('node:util') +const winston = require('winston') +const Transport = require('winston-transport') +const { Stream } = require('stream') + +// +// Remark: This should be at a higher level. +// const code = /\u001b\[(\d+(;\d+)*)?m/g; let timerFunctionForProcessExit = null; @@ -25,52 +26,51 @@ let timerFunctionForProcessExit = null; // Constructor function for the Loggly transport object responsible // for persisting log messages and metadata to Loggly; 'LaaS'. // +var Loggly = (exports.Loggly = function (options) { + options = options || {}; + + Transport.call(this, options); + if (!options.subdomain) { + throw new Error('Loggly Subdomain is required'); + } else if (!options || !options.token) { + throw new Error('Loggly Customer token is required.'); + } -export const Loggly = class { - constructor(options = {}) { - Transport.call(this, options); - if (!options.subdomain) { - throw new Error('Loggly Subdomain is required'); - } else if (!options || !options.token) { - throw new Error('Loggly Customer token is required.'); - } - - this.name = 'loggly'; - let tags = options.tags || options.tag || options.id; - if (tags && !Array.isArray(tags)) { - tags = [tags]; - } + this.name = 'loggly'; + var tags = options.tags || options.tag || options.id; + if (tags && !Array.isArray(tags)) { + tags = [tags]; + } - this.client = LogglyBulk.createClient({ - subdomain: options.subdomain, - json: options.json || false, - proxy: options.proxy || null, - token: options.token, - tags: tags, - isBulk: options.isBulk || false, - bufferOptions: options.bufferOptions || { - size: 500, - retriesInMilliSeconds: 30 * 1000 - }, - networkErrorsOnConsole: options.networkErrorsOnConsole || false - }); + this.client = loggly.createClient({ + subdomain: options.subdomain, + json: options.json || false, //TODO: should be false + proxy: options.proxy || null, + token: options.token, + tags: tags, + isBulk: options.isBulk || false, + bufferOptions: options.bufferOptions || { + size: 500, + retriesInMilliSeconds: 30 * 1000 + }, + networkErrorsOnConsole: options.networkErrorsOnConsole || false + }); - this.timestamp = options.timestamp === false ? false : true; - this.stripColors = options.stripColors || false; - } -} + this.timestamp = options.timestamp === false ? false : true; + this.stripColors = options.stripColors || false; +}); // // Helper function to call process.exit() after waiting // 10 seconds. // -export const flushLogsAndExit = function () { +const flushLogsAndExit = (exports.flushLogsAndExit = function () { if (timerFunctionForProcessExit === null) { timerFunctionForProcessExit = setInterval(function () { process.exit(); }, 10000); } -}; +}); // // Inherit from `winston.Transport`. diff --git a/package.json b/package.json index ad0025c..ce47073 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,6 @@ "description": "A Loggly transport for winston", "version": "3.2.5", "author": "Adarsh Madrecha", - "type": "module", "contributors": [ { "name": "Adarsh Madrecha", diff --git a/test/winston-loggly.test.js b/test/winston-loggly.test.js index fba3ad3..c392c1f 100644 --- a/test/winston-loggly.test.js +++ b/test/winston-loggly.test.js @@ -1,5 +1,5 @@ -import { Loggly } from '../lib/winston-loggly'; -import winston from 'winston'; +const { Loggly } = require('../lib/winston-loggly'); +const winston = require('winston'); const client = { log: () => { }