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

Improve types for context #31

Open
wants to merge 3 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
12 changes: 6 additions & 6 deletions bufflog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@ export function getLogger() {
return pinoLogger;
}

export function debug(message: string, context?: object) {
export function debug<T extends object>(message: string, context?: T) {
pinoLogger.debug({context: context}, message);
}

export function info(message: string, context?: object) {
export function info<T extends object>(message: string, context?: T) {
pinoLogger.info({context: context}, message);
}

export function notice(message: string, context?: object) {
export function notice<T extends object>(message: string, context?: T) {
pinoLogger.notice({context: context}, message);
}

export function warning(message: string, context?: object) {
export function warning<T extends object>(message: string, context?: T) {
pinoLogger.warn({context: context}, message);
}

export function error(message: string, context?: object) {
export function error<T extends object>(message: string, context?: T) {
pinoLogger.error({context: context}, message);
}

// for consistency with php-bufflog, critical == fatal
export function critical(message: string, context?: object) {
export function critical<T extends object>(message: string, context?: T) {
pinoLogger.fatal({context: context}, message);
}

Expand Down
1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ BuffLog.warning('hello warning');
BuffLog.error('hello error');
BuffLog.critical('hello critical');
BuffLog.critical('hello critical', {"some":"stuff"});
BuffLog.critical<{type: string}>('hello critical', {"type":"with type enforced context"});

const app = express();

Expand Down