-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
199 additions
and
160 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -48,6 +48,7 @@ web_modules/ | |
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
.tsimp/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
This file contains 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 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 |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
"name": "@byu-oit/logger", | ||
"version": "0.4.2", | ||
"description": "Default configuration for pino logger", | ||
"engines": { | ||
"node": ">=18" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Scott Hutching", | ||
|
@@ -12,56 +15,79 @@ | |
"email": "[email protected]" | ||
} | ||
], | ||
"main": "dist/logger.js", | ||
"types": "dist/logger.d.ts", | ||
"type": "module", | ||
"main": "./dist/cjs/index.js", | ||
"types": "./dist/cjs/index.d.ts", | ||
"exports": { | ||
"./package.json": "./package.json", | ||
".": { | ||
"import": { | ||
"types": "./dist/esm/index.d.ts", | ||
"default": "./dist/esm/index.js" | ||
}, | ||
"require": { | ||
"types": "./dist/cjs/index.d.ts", | ||
"default": "./dist/cjs/index.js" | ||
} | ||
} | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "npx rimraf dist && tsc", | ||
"coverage": "npm run test -- --coverage || exit 0", | ||
"build": "rimraf dist && concurrently \"npm:build:*\" -c cyanBright", | ||
"build:cjs": "tsc -p tsconfig.cjs.json && echo-cli \"{\\\"type\\\": \\\"commonjs\\\"}\" > dist/cjs/package.json", | ||
"build:esm": "tsc -p tsconfig.json && echo-cli \"{\\\"type\\\": \\\"module\\\"}\" > dist/esm/package.json", | ||
"clean": "rimraf dist", | ||
"coverage": "c8 ava", | ||
"lint": "npx ts-standard | snazzy", | ||
"lint:fix": "npx ts-standard --fix | snazzy", | ||
"test": "jest", | ||
"test": "ava", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"author": "Brigham Young University - Office of Information Technology", | ||
"license": "Apache-2.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/byu-oit/logger.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/byu-oit/logger/issues" | ||
}, | ||
"dependencies": { | ||
"deepmerge": "^4.2.2", | ||
"pino": "^8.11.0", | ||
"pino-http": "^6.6.0" | ||
}, | ||
"devDependencies": { | ||
"@tsconfig/node12": "^1.0.11", | ||
"@tsconfig/node18": "^18.2.4", | ||
"@types/jest": "^29.5.0", | ||
"@types/node": "^16.9.1", | ||
"jest": "^29.5.0", | ||
"@types/node": "^18.19.42", | ||
"@types/sinon": "^17.0.3", | ||
"ava": "^6.1.3", | ||
"c8": "^10.1.2", | ||
"concurrently": "^8.2.2", | ||
"echo-cli": "^2.0.0", | ||
"lint-staged": "^12.0.2", | ||
"pino-pretty": "^10.0.0", | ||
"rimraf": "^6.0.1", | ||
"sinon": "^18.0.0", | ||
"snazzy": "^9.0.0", | ||
"ts-jest": "^29.1.0", | ||
"tsimp": "^2.0.11", | ||
"typescript": "^5.0.3" | ||
}, | ||
"optionalDependencies": { | ||
"pino-pretty": ">=7" | ||
}, | ||
"engines": { | ||
"node": ">=12" | ||
}, | ||
"jest": { | ||
"transform": { | ||
"^.+\\.(ts|tsx)$": "ts-jest" | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.ts": "npm run lint:fix" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/byu-oit/logger.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/byu-oit/logger/issues" | ||
"ava": { | ||
"extensions": { | ||
"ts": "module" | ||
}, | ||
"nodeArguments": [ | ||
"--import=tsimp" | ||
] | ||
} | ||
} |
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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,80 @@ | ||
import ava, { TestFn } from 'ava' | ||
import sinon, { SinonFakeTimers } from 'sinon' | ||
import { Logger } from 'pino' | ||
import { ByuLogger } from '../src/logger.js' | ||
|
||
type Context = { | ||
logged: string | ||
logger: Logger | ||
clock: SinonFakeTimers | ||
now: Date | ||
} | ||
|
||
const test = ava as TestFn<Context> | ||
|
||
test.beforeEach((t) => { | ||
/* Capture the stdout pipe */ | ||
process.stdout.write = (buffer: string) => { | ||
t.context.logged += buffer | ||
return true | ||
} | ||
|
||
/* Stub the date time */ | ||
const jan1st = new Date(2021, 0, 1) | ||
t.context.now = jan1st | ||
t.context.clock = sinon.useFakeTimers(jan1st.getTime()) | ||
|
||
process.env.NODE_ENV = 'production' | ||
t.context.logged = '' | ||
t.context.logger = ByuLogger() | ||
}) | ||
|
||
test.afterEach((t) => { | ||
t.context.clock.restore() | ||
}) | ||
|
||
test.serial('default logger should default to info level', (t) => { | ||
t.context.logger.debug('debug does not work') | ||
|
||
t.is(t.context.logger.level, 'info') | ||
t.is(t.context.logged, '') // no logs should have happened | ||
}) | ||
|
||
test.serial('default logger displays logs in JSON format', (t) => { | ||
t.context.logger.info('json works') | ||
|
||
try { | ||
const parsedLog = JSON.parse(t.context.logged) | ||
t.truthy(parsedLog.message) | ||
t.truthy(parsedLog.level) | ||
t.truthy(parsedLog.time) | ||
} catch (e) { | ||
t.log(e) | ||
t.fail(`The log format should be stringified JSON but parsing failed. See the logged error for details.`) | ||
} | ||
}) | ||
|
||
test.serial('default logger should display info logs', (t) => { | ||
t.context.logger.info('info works') | ||
|
||
try { | ||
const parsedLog = JSON.parse(t.context.logged) | ||
t.is(parsedLog.message, 'info works') | ||
t.is(parsedLog.level, 'info') | ||
} catch (e) { | ||
t.log(e) | ||
t.fail(`The log format should be stringified JSON but parsing failed. See the logged error for details.`) | ||
} | ||
}) | ||
|
||
test.serial('default logger displays logs with epoch datetime format', (t) => { | ||
t.context.logger.info('iso date works') | ||
|
||
try { | ||
const parsedLog = JSON.parse(t.context.logged) | ||
t.is(parsedLog.time, t.context.now.getTime()) | ||
} catch (e) { | ||
t.log(e) | ||
t.fail(`The log format should be stringified JSON but parsing failed. See the logged error for details.`) | ||
} | ||
}) |
This file contains 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,47 @@ | ||
import ava, { TestFn } from 'ava' | ||
import sinon, { SinonFakeTimers } from 'sinon' | ||
import { Logger } from 'pino' | ||
import { ByuLogger } from '../src/logger.js' | ||
|
||
type Context = { | ||
logged: string | ||
logger: Logger | ||
clock: SinonFakeTimers | ||
now: Date | ||
} | ||
|
||
const test = ava as TestFn<Context> | ||
|
||
test.beforeEach((t) => { | ||
/* Capture the stdout pipe */ | ||
process.stdout.write = (buffer: string) => { | ||
t.context.logged += buffer | ||
return true | ||
} | ||
|
||
/* Stub the date time */ | ||
const jan1st = new Date(2021, 0, 1) | ||
t.context.now = jan1st | ||
t.context.clock = sinon.useFakeTimers(jan1st.getTime()) | ||
|
||
process.env.NODE_ENV = 'test' | ||
t.context.logged = '' | ||
t.context.logger = ByuLogger() | ||
}) | ||
|
||
test.afterEach((t) => { | ||
t.context.clock.restore() | ||
}) | ||
|
||
test.serial('default logger should default to silent level', (t) => { | ||
t.context.logger.debug('debug does not work') | ||
|
||
t.is(t.context.logger.level, 'silent') | ||
t.is(t.context.logged, '') // no logs should have happened | ||
}) | ||
|
||
test.serial('default logger should not display logs', (t) => { | ||
t.context.logger.info('info works') | ||
|
||
t.is(t.context.logged, '') | ||
}) |
Oops, something went wrong.