Skip to content
This repository has been archived by the owner on Oct 22, 2023. It is now read-only.

Commit

Permalink
reverted back from esm to commonjs
Browse files Browse the repository at this point in the history
  • Loading branch information
adarshmadrecha committed Jul 30, 2023
1 parent 4d439c2 commit c758872
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 45 deletions.
84 changes: 42 additions & 42 deletions lib/winston-loggly.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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`.
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"description": "A Loggly transport for winston",
"version": "3.2.5",
"author": "Adarsh Madrecha",
"type": "module",
"contributors": [
{
"name": "Adarsh Madrecha",
Expand Down
4 changes: 2 additions & 2 deletions test/winston-loggly.test.js
Original file line number Diff line number Diff line change
@@ -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: () => { }
Expand Down

0 comments on commit c758872

Please sign in to comment.