From ea23268460284787ce8f63bb37a29c448b206fb2 Mon Sep 17 00:00:00 2001 From: Geoff Wagstaff Date: Thu, 26 Nov 2020 12:32:06 +0000 Subject: [PATCH] events --- CHANGELOG.md | 12 ++++++++++++ README.md | 2 +- main.ts | 2 ++ test/limits.ts | 21 +++++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md create mode 100644 test/limits.ts diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..c7ff9f2 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,12 @@ +* Changed the way to access the events handler: + +```js +// new way +import { events } from '@gosquared/logs2'; + +// commonjs +const { events } = require('@gosquared/logs2'); + +// old way (avoid) +const events = require('@gosquared/logs2/dist/src/events'); +``` diff --git a/README.md b/README.md index 44fb85a..89ed0f3 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ async function stop() { Errors are emitted as events: ```javascript -const events = require('@gosquared/logs2/dist/src/events'); +const { events } = require('@gosquared/logs2'); events.on('error', e => { console.error(e); }); diff --git a/main.ts b/main.ts index 7dbd6e6..203e744 100644 --- a/main.ts +++ b/main.ts @@ -1,6 +1,7 @@ import { get as getCw } from './src/aws'; import Logger from "./src/logger"; import { Settings } from './types'; +import events from './src/events'; const loggers: Map = new Map(); @@ -22,3 +23,4 @@ export async function stop() { } } +export { events }; diff --git a/test/limits.ts b/test/limits.ts new file mode 100644 index 0000000..92d36e5 --- /dev/null +++ b/test/limits.ts @@ -0,0 +1,21 @@ +import assert from 'assert'; +import { getLogger, events } from '../main'; + +describe('limits', () => { + it('clears queue when messsage limit reached', done => { + const group = 'test'; + const settings = {}; + const logger = getLogger(group, settings); + logger.limit = 1; + + events.once('error', e => { + assert.strictEqual( + e.message, + 'message limit reached' + ); + done(); + }); + + logger.log('test', {}); + }); +})