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

[WIP] Add Tests #3

Open
wants to merge 4 commits into
base: main
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
11 changes: 11 additions & 0 deletions bufflog.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {BuffLog}from './bufflog';

it('Testing jest', () => {
expect(1).toBe(1)
});


it('Test Bufflog', () => {
var logger = new BuffLog();
logger.info("test");
});
25 changes: 17 additions & 8 deletions bufflog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import formats from "dd-trace/ext/formats";
export class BuffLog {
pinoLogger: any;
defaultLevel = 'notice';
dest: any;

constructor() {
this.dest = require('pino').destination('/tmp/test.log')
this.dest[Symbol.for('pino.metadata')] = true

this.pinoLogger = require('pino')({
level: this.defaultLevel,

Expand All @@ -16,6 +20,10 @@ export class BuffLog {
// soon: remove the `v` field https://github.com/pinojs/pino/issues/620
base: {},

// notice doesn't exist in pino, let's add it
customLevels: {
notice: 35
},
mixin () {
// Check here if a current trace exist to inject it in the log
// `tracer` is a singleton, will no-op if no tracer was initialized
Expand All @@ -27,14 +35,9 @@ export class BuffLog {
} else {
return {}
}
},

// notice doesn't exist in pino, let's add it
customLevels: {
notice: 35
}
});
}
}
}, this.dest)
};

debug(message: string) {
this.pinoLogger.debug(message);
Expand All @@ -46,6 +49,11 @@ export class BuffLog {

notice(message: string) {
this.pinoLogger.notice(message);
const { lastMsg, lastLevel, lastObj, lastTime} = this.dest
console.log(
'Logged message "%s" at level %d with object %o at time %s',
lastMsg, lastLevel, lastObj, lastTime
);
}

warning(message: string) {
Expand All @@ -60,5 +68,6 @@ export class BuffLog {
critical(message: string) {
this.pinoLogger.fatal(message);
}


}
9 changes: 4 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ tracer.init({
logInjection: false
});

let logger = new BuffLog();
var logger = new BuffLog();

logger.info('hello info');
logger.debug('hello debug');
logger.notice('hello notice');
logger.debug('hello info');
logger.notice('hello notice');
logger.warning('hello warning');
logger.error('hello error');
logger.critical('hello critical');
Expand All @@ -31,4 +30,4 @@ app.get('/', (req, res) => {
logger.warning('hello warning');
logger.error('hello error');
logger.critical('hello critical');
});
});
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html

module.exports = {
preset: 'ts-jest',
testEnvironment: "node",
};
Loading