Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change way to access events handler #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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');
```
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 2 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
@@ -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<string, Logger> = new Map();

Expand All @@ -22,3 +23,4 @@ export async function stop() {
}
}

export { events };
21 changes: 21 additions & 0 deletions test/limits.ts
Original file line number Diff line number Diff line change
@@ -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<string>(
e.message,
'message limit reached'
);
done();
});

logger.log('test', {});
});
})