Comparing version 0.8.4 to 1.0.0
# Changelog | ||
### 1.0.0 (2021-08-25) | ||
- Breaking | ||
- Drop support for Node 12 and 14. | ||
- Changes | ||
- Support Node 16 | ||
- Upgrade all dependencies to the latest | ||
### 0.8.4 (2021-01-24) | ||
@@ -4,0 +12,0 @@ |
@@ -0,1 +1,2 @@ | ||
import { Request, Response } from 'express'; | ||
declare const levels: readonly ["trace", "info", "warn", "error", "fatal", "security"]; | ||
@@ -17,2 +18,12 @@ export declare type LevelType = typeof levels[number]; | ||
export declare type TimeLogFunction = (label: string, level?: LevelType, extraLogDat?: any) => Promise<any>; | ||
export declare type ParseReqInOut = Request & { | ||
user?: unknown; | ||
}; | ||
interface LogData extends Record<string, unknown> { | ||
msg?: string; | ||
} | ||
interface ResponseWrapper { | ||
res: Response; | ||
code: number; | ||
} | ||
export default class Logger { | ||
@@ -55,3 +66,3 @@ isTransient: boolean; | ||
*/ | ||
static parseReq(req: any): object; | ||
static parseReq(req: ParseReqInOut): Partial<ParseReqInOut>; | ||
/** | ||
@@ -64,8 +75,8 @@ * Format milliseconds to a string for logging | ||
*/ | ||
writeTimeEnd(label: string, level?: LevelType, extraLogDat?: any): Promise<any>; | ||
writeTimeEnd(label: string, level?: LevelType, extraLogDat?: LogData): Promise<any>; | ||
/** | ||
* Write log to destination | ||
*/ | ||
write(levelIndex: number, logData: any, response?: any): Promise<any>; | ||
write(levelIndex: number, logData: LogData, response?: ResponseWrapper): Promise<any>; | ||
} | ||
export {}; |
@@ -6,3 +6,3 @@ export interface LogSingleOptions { | ||
} | ||
export declare const logSingle: (options: LogSingleOptions) => object; | ||
export declare const logSingle: (options: LogSingleOptions) => Promise<Record<string, unknown> | void>; | ||
export interface LogBatchOptions { | ||
@@ -13,2 +13,2 @@ tag: string; | ||
} | ||
export declare const logBatch: (options: LogBatchOptions) => Promise<object | void>; | ||
export declare const logBatch: (options: LogBatchOptions) => Promise<Record<string, unknown> | void>; |
@@ -46,3 +46,3 @@ "use strict"; | ||
}; | ||
exports.logSingle = (options) => { | ||
const logSingle = (options) => { | ||
const { logObj } = options; | ||
@@ -57,3 +57,4 @@ if (!utils_1.isObject(logObj)) { | ||
}; | ||
exports.logBatch = async (options) => { | ||
exports.logSingle = logSingle; | ||
const logBatch = async (options) => { | ||
const { logObj } = options; | ||
@@ -68,2 +69,3 @@ if (!Array.isArray(logObj)) { | ||
}; | ||
exports.logBatch = logBatch; | ||
//# sourceMappingURL=loggly-wrapper.js.map |
@@ -1,2 +0,2 @@ | ||
export declare const isObject: (obj?: object | null | undefined) => boolean; | ||
export declare const safeJsonStringify: (obj: any) => string; | ||
export declare const isObject: (obj?: Record<string, unknown> | null | undefined) => boolean; | ||
export declare const safeJsonStringify: (obj: Record<string, unknown>) => string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.safeJsonStringify = exports.isObject = void 0; | ||
exports.isObject = (obj) => !!obj && obj.toString() === '[object Object]' && !Array.isArray(obj); | ||
const isObject = (obj) => !!obj && obj.toString() === '[object Object]' && !Array.isArray(obj); | ||
exports.isObject = isObject; | ||
// From MDN: | ||
@@ -19,3 +20,4 @@ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value | ||
}; | ||
exports.safeJsonStringify = (obj) => JSON.stringify(obj, getCircularReplacer()); | ||
const safeJsonStringify = (obj) => JSON.stringify(obj, getCircularReplacer()); | ||
exports.safeJsonStringify = safeJsonStringify; | ||
//# sourceMappingURL=utils.js.map |
@@ -34,9 +34,2 @@ const collectCoverage = !process.env.SKIP_COVERAGE; | ||
testMatch: ['**/test/**/*.test.[t|j]s?(x)'], | ||
// Jasmine, jest's default test-runner, fails silently on afterAll within | ||
// a describe block. This is a bug that the jest team is not going to fix | ||
// because they plan to use jest-circus/runner by default in the near future. | ||
// https://github.com/facebook/jest/issues/6692 | ||
// TODO: Remove the testRunner option and the previous comment when jest | ||
// updates the default test-runner to jest-circus. | ||
testRunner: 'jest-circus/runner', | ||
transform: { | ||
@@ -43,0 +36,0 @@ '.+\\.[j|t]sx?$': 'ts-jest', |
import { v4 } from 'uuid'; | ||
import { Request, Response } from 'express'; | ||
import { isObject } from './utils'; | ||
@@ -41,2 +42,13 @@ | ||
export type ParseReqInOut = Request & { user?: unknown }; | ||
interface LogData extends Record<string, unknown> { | ||
msg?: string; | ||
} | ||
interface ResponseWrapper { | ||
res: Response; | ||
code: number; | ||
} | ||
export default class Logger { | ||
@@ -157,3 +169,3 @@ isTransient: boolean; | ||
*/ | ||
static parseReq(req: any): object { | ||
static parseReq(req: ParseReqInOut): Partial<ParseReqInOut> { | ||
return { | ||
@@ -183,3 +195,3 @@ body: req.body, | ||
*/ | ||
writeTimeEnd(label: string, level?: LevelType, extraLogDat?: any): Promise<any> { | ||
writeTimeEnd(label: string, level?: LevelType, extraLogDat?: LogData): Promise<any> { | ||
const levelIndex = levels.indexOf(level ?? 'info'); | ||
@@ -207,3 +219,3 @@ const extraLogData = extraLogDat || {}; | ||
*/ | ||
async write(levelIndex: number, logData: any, response?: any): Promise<any> { | ||
async write(levelIndex: number, logData: LogData, response?: ResponseWrapper): Promise<any> { | ||
if (!isObject(logData)) { | ||
@@ -210,0 +222,0 @@ // eslint-disable-next-line no-console |
@@ -10,3 +10,5 @@ import fetch, { RequestInit, Response } from 'node-fetch'; | ||
const log = async (options: LogOptions, bulk: boolean): Promise<object> => { | ||
const log = async ( | ||
options: LogOptions, bulk: boolean, | ||
): Promise<Record<string, unknown>> => { | ||
const { | ||
@@ -48,3 +50,3 @@ tag, | ||
url: ${url} | ||
options: ${safeJsonStringify(fetchOptions)}`); | ||
options: ${safeJsonStringify(fetchOptions as Record<string, unknown>)}`); | ||
return {}; | ||
@@ -65,3 +67,5 @@ } | ||
export const logSingle = (options: LogSingleOptions): object => { | ||
export const logSingle = ( | ||
options: LogSingleOptions, | ||
): Promise<Record<string, unknown> | void> => { | ||
const { logObj } = options; | ||
@@ -87,3 +91,5 @@ if (!isObject(logObj)) { | ||
export const logBatch = async (options: LogBatchOptions): Promise<object|void> => { | ||
export const logBatch = async ( | ||
options: LogBatchOptions, | ||
): Promise<Record<string, unknown> | void> => { | ||
const { logObj } = options; | ||
@@ -90,0 +96,0 @@ if (!Array.isArray(logObj)) { |
export const isObject = ( | ||
obj?: object | null, | ||
obj?: Record<string, unknown> | null, | ||
): boolean => !!obj && obj.toString() === '[object Object]' && !Array.isArray(obj); | ||
@@ -22,2 +22,4 @@ | ||
export const safeJsonStringify = (obj: any): string => JSON.stringify(obj, getCircularReplacer()); | ||
export const safeJsonStringify = ( | ||
obj: Record<string, unknown>, | ||
): string => JSON.stringify(obj, getCircularReplacer()); |
@@ -12,24 +12,20 @@ { | ||
"devDependencies": { | ||
"@types/jest": "26.0.20", | ||
"@types/node": "14.14.22", | ||
"@types/node-fetch": "2.5.8", | ||
"@types/uuid": "8.3.0", | ||
"@typescript-eslint/eslint-plugin": "2.34.0", | ||
"@typescript-eslint/parser": "2.34.0", | ||
"eslint": "6.8.0", | ||
"@types/express": "4.17.13", | ||
"@types/jest": "27.0.1", | ||
"@types/node": "16.7.2", | ||
"@types/node-fetch": "2.5.12", | ||
"@types/uuid": "8.3.1", | ||
"@typescript-eslint/eslint-plugin": "4.29.3", | ||
"@typescript-eslint/parser": "4.29.3", | ||
"eslint": "7.32.0", | ||
"eslint-config-airbnb-base": "14.2.1", | ||
"eslint-plugin-import": "2.22.1", | ||
"eslint-plugin-jest": "24.1.3", | ||
"eslint-plugin-import": "2.24.2", | ||
"eslint-plugin-jest": "24.4.0", | ||
"eslint-plugin-security": "1.4.0", | ||
"eslint-plugin-sort-keys-fix": "1.1.1", | ||
"jest": "25.5.4", | ||
"jest-circus": "26.6.3", | ||
"eslint-plugin-sort-keys-fix": "1.1.2", | ||
"jest": "27.0.6", | ||
"pre-commit": "1.2.2", | ||
"ts-jest": "25.5.1", | ||
"typescript": "3.9.7" | ||
"ts-jest": "27.0.5", | ||
"typescript": "4.3.5" | ||
}, | ||
"engines": { | ||
"node": ">=14", | ||
"npm": ">=6" | ||
}, | ||
"homepage": "https://github.com/guyellis/lalog#readme", | ||
@@ -62,3 +58,3 @@ "keywords": [ | ||
"types": "dist/index.d.ts", | ||
"version": "0.8.4" | ||
"version": "1.0.0" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
27
860
0
67927