-
Notifications
You must be signed in to change notification settings - Fork 2
chore: upgrade pino to v10.1.0 and pino-http to v11.0.0 #41
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
Open
erickhun
wants to merge
3
commits into
main
Choose a base branch
from
upgrade-pino
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| import BuffLog, { middleware } from './bufflog' | ||
| import pino from 'pino' | ||
|
|
||
| describe('BuffLog', () => { | ||
| const logger = BuffLog.getLogger() | ||
| beforeEach(() => { | ||
| jest.restoreAllMocks() | ||
| }) | ||
|
|
||
| it('getLogger returns the logger instance', () => { | ||
| expect(logger).toBeDefined() | ||
| expect(typeof logger.info).toBe('function') | ||
| }) | ||
|
|
||
| it('debug calls logger.debug', () => { | ||
| const spy = jest.spyOn(logger, 'debug') | ||
| BuffLog.debug('test debug', { foo: 'bar' }) | ||
| expect(spy).toHaveBeenCalledWith({ context: { foo: 'bar' } }, 'test debug') | ||
| }) | ||
|
|
||
| it('info calls logger.info', () => { | ||
| const spy = jest.spyOn(logger, 'info') | ||
| BuffLog.info('test info', { foo: 'bar' }) | ||
| expect(spy).toHaveBeenCalledWith({ context: { foo: 'bar' } }, 'test info') | ||
| }) | ||
|
|
||
| it('notice calls logger.notice', () => { | ||
| const spy = jest.spyOn(logger, 'notice') | ||
| BuffLog.notice('test notice', { foo: 'bar' }) | ||
| expect(spy).toHaveBeenCalledWith({ context: { foo: 'bar' } }, 'test notice') | ||
| }) | ||
|
|
||
| it('warning calls logger.warn', () => { | ||
| const spy = jest.spyOn(logger, 'warn') | ||
| BuffLog.warning('test warn', { foo: 'bar' }) | ||
| expect(spy).toHaveBeenCalledWith({ context: { foo: 'bar' } }, 'test warn') | ||
| }) | ||
|
|
||
| it('error calls logger.error', () => { | ||
| const spy = jest.spyOn(logger, 'error') | ||
| BuffLog.error('test error', { foo: 'bar' }) | ||
| expect(spy).toHaveBeenCalledWith({ context: { foo: 'bar' } }, 'test error') | ||
| }) | ||
|
|
||
| it('critical calls logger.fatal', () => { | ||
| const spy = jest.spyOn(logger, 'fatal') | ||
| BuffLog.critical('test critical', { foo: 'bar' }) | ||
| expect(spy).toHaveBeenCalledWith( | ||
| { context: { foo: 'bar' } }, | ||
| 'test critical', | ||
| ) | ||
| }) | ||
|
|
||
| it('middleware returns a function', () => { | ||
| const mw = middleware() | ||
| expect(typeof mw).toBe('function') | ||
| }) | ||
| }) | ||
|
|
||
| describe('BuffLog Redaction', () => { | ||
| let logs: any[] = [] | ||
| let testLogger: any | ||
|
|
||
| beforeEach(() => { | ||
| logs = [] | ||
| // Create a test logger with the same config but capture output | ||
| const stream = { | ||
| write: (line: string) => { | ||
| logs.push(JSON.parse(line)) | ||
| } | ||
| } | ||
|
|
||
| testLogger = pino({ | ||
| level: 'debug', | ||
| messageKey: 'message', | ||
| customLevels: { | ||
| debug: 100, | ||
| info: 200, | ||
| notice: 250, | ||
| warn: 300, | ||
| error: 400, | ||
| fatal: 500 | ||
| }, | ||
| useOnlyCustomLevels: true, | ||
| redact: { | ||
| paths: [ | ||
| 'req.body.password', | ||
| 'req.headers', | ||
| 'req.cookies', | ||
| 'context.req.body.password', | ||
| 'context.req.headers', | ||
| 'context.req.cookies', | ||
| ], | ||
| censor: '[ REDACTED ]', | ||
| }, | ||
| }, stream) | ||
| }) | ||
|
|
||
| it('redacts sensitive req fields (headers, cookies, passwords)', () => { | ||
| testLogger.info({ | ||
| context: { | ||
| req: { | ||
| headers: { | ||
| authorization: 'Bearer secret-token', | ||
| cookie: 'session=secret-session' | ||
| }, | ||
| body: { | ||
| username: 'testuser', | ||
| password: 'secret-password', | ||
| email: '[email protected]' | ||
| }, | ||
| cookies: { | ||
| session: 'secret-session-id' | ||
| }, | ||
| method: 'POST', | ||
| path: '/api/login' | ||
| }, | ||
| userId: 'user-123' | ||
| } | ||
| }, 'Test with sensitive data') | ||
|
|
||
| expect(logs).toHaveLength(1) | ||
| expect(logs[0].context.req.headers).toBe('[ REDACTED ]') | ||
| expect(logs[0].context.req.body.password).toBe('[ REDACTED ]') | ||
| expect(logs[0].context.req.cookies).toBe('[ REDACTED ]') | ||
| expect(logs[0].context.req.body.username).toBe('testuser') | ||
| expect(logs[0].context.req.body.email).toBe('[email protected]') | ||
| expect(logs[0].context.req.method).toBe('POST') | ||
| expect(logs[0].context.req.path).toBe('/api/login') | ||
| expect(logs[0].context.userId).toBe('user-123') | ||
| }) | ||
|
|
||
| it('does not redact non-sensitive data', () => { | ||
| testLogger.info({ | ||
| context: { | ||
| userId: 'user-123', | ||
| action: 'login', | ||
| metadata: { | ||
| ip: '192.168.1.1', | ||
| userAgent: 'Mozilla/5.0' | ||
| } | ||
| } | ||
| }, 'Test without sensitive data') | ||
|
|
||
| expect(logs).toHaveLength(1) | ||
| expect(logs[0].context.userId).toBe('user-123') | ||
| expect(logs[0].context.action).toBe('login') | ||
| expect(logs[0].context.metadata.ip).toBe('192.168.1.1') | ||
| expect(logs[0].context.metadata.userAgent).toBe('Mozilla/5.0') | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| module.exports = { | ||
| preset: 'ts-jest', | ||
| testEnvironment: 'node', | ||
| testMatch: ['**/*.test.ts'], | ||
| collectCoverageFrom: [ | ||
| 'bufflog.ts', | ||
| '!**/*.d.ts', | ||
| ], | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.