Comparing version 0.7.0 to 0.8.0
@@ -24,2 +24,3 @@ module.exports = { | ||
"@typescript-eslint/no-explicit-any": [0], | ||
"import/prefer-default-export": [0], | ||
"jest/no-disabled-tests": [2], | ||
@@ -30,4 +31,4 @@ "jest/no-focused-tests": [2], | ||
"jest/valid-expect": [2], | ||
"security/detect-object-injection": [0] | ||
"security/detect-object-injection": [0], | ||
} | ||
}; |
# Changelog | ||
### 0.8.0 | ||
- Breaking: LevelEnum renamed to LevelType | ||
- Breaking: timeEnd() no longer has level log methods on it. | ||
- Breaking: timeEnd() now has 3 params - inserted a 2nd param | ||
### 0.7.0 | ||
### 0.6.0 | ||
@@ -4,0 +12,0 @@ |
@@ -1,4 +0,4 @@ | ||
import debug from 'debug'; | ||
declare type LevelEnum = 'trace' | 'info' | 'warn' | 'error' | 'fatal' | 'security'; | ||
interface LogPresets { | ||
declare const levels: readonly ["trace", "info", "warn", "error", "fatal", "security"]; | ||
export declare type LevelType = typeof levels[number]; | ||
export interface LogPresets { | ||
[key: string]: string | undefined; | ||
@@ -8,3 +8,3 @@ module?: string; | ||
} | ||
interface LaLogOptions { | ||
export interface LaLogOptions { | ||
addTrackId?: boolean; | ||
@@ -16,13 +16,4 @@ moduleName?: string; | ||
} | ||
declare type LogFunction = (logData: any, response?: any) => Promise<any>; | ||
declare type TimeLogFunction = (label: string, extraLogDat?: any) => Promise<any>; | ||
interface TimeEndLog { | ||
(label: string, extraLogDat?: any): Promise<any>; | ||
trace?: TimeLogFunction; | ||
info?: TimeLogFunction; | ||
warn?: TimeLogFunction; | ||
error?: TimeLogFunction; | ||
fatal?: TimeLogFunction; | ||
security?: TimeLogFunction; | ||
} | ||
export declare type LogFunction = (logData: any, response?: any) => Promise<any>; | ||
export declare type TimeLogFunction = (label: string, level?: LevelType, extraLogDat?: any) => Promise<any>; | ||
export default class Logger { | ||
@@ -32,5 +23,4 @@ isTransient: boolean; | ||
presets: LogPresets; | ||
debug: debug.Debugger; | ||
tag: string; | ||
timeEnd: TimeEndLog; | ||
timeEnd: TimeLogFunction; | ||
trace: LogFunction; | ||
@@ -53,11 +43,11 @@ info: LogFunction; | ||
*/ | ||
static allLevels(): LevelEnum[]; | ||
static allLevels(): ReadonlyArray<LevelType>; | ||
/** | ||
* Get the current log level | ||
*/ | ||
static getLevel(): LevelEnum; | ||
static getLevel(): LevelType; | ||
/** | ||
* Change the minimum level to write logs | ||
*/ | ||
static setLevel(newLevelName: LevelEnum): LevelEnum; | ||
static setLevel(newLevelName: LevelType): LevelType; | ||
/** | ||
@@ -74,3 +64,3 @@ * Parse the Express request (req) object for logging | ||
*/ | ||
writeTimeEnd(levelIndex: number, label: string, extraLogDat?: any): Promise<any>; | ||
writeTimeEnd(label: string, level?: LevelType, extraLogDat?: any): Promise<any>; | ||
/** | ||
@@ -77,0 +67,0 @@ * Write log to destination |
@@ -6,5 +6,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const isObject_1 = __importDefault(require("lodash/isObject")); | ||
const debug_1 = __importDefault(require("debug")); | ||
const uuid_1 = __importDefault(require("uuid")); | ||
const utils_1 = require("./utils"); | ||
const loggly_wrapper_1 = require("./loggly-wrapper"); | ||
@@ -26,12 +25,8 @@ const levels = ['trace', 'info', 'warn', 'error', 'fatal', 'security']; | ||
this.logCollector = isTransient ? [] : null; | ||
this.presets = Object.assign({ module: moduleName }, (isObject_1.default(presets) ? presets : {})); | ||
this.presets = Object.assign({ module: moduleName }, (utils_1.isObject(presets) ? presets : {})); | ||
if (addTrackId && !this.presets.trackId) { | ||
this.presets.trackId = uuid_1.default.v4(); | ||
} | ||
this.debug = debug_1.default(`${serviceName}:${moduleName}`); | ||
this.tag = `${serviceName}-${process.env.NODE_ENV}`; | ||
// Setup timeEnd so that it can be called without a level and when that happens the | ||
// level will default to info: | ||
const defaultTimeEndLevel = levels.indexOf('info'); | ||
this.timeEnd = this.writeTimeEnd.bind(this, defaultTimeEndLevel); | ||
this.timeEnd = this.writeTimeEnd.bind(this); | ||
// Listed like this so that Typescript can type each log level. | ||
@@ -45,8 +40,2 @@ // Previously this was setup using a loop but Typescript couldn't type it | ||
this.security = this.write.bind(this, levels.indexOf('security')); | ||
this.timeEnd.trace = this.writeTimeEnd.bind(this, levels.indexOf('trace')); | ||
this.timeEnd.info = this.writeTimeEnd.bind(this, levels.indexOf('info')); | ||
this.timeEnd.warn = this.writeTimeEnd.bind(this, levels.indexOf('warn')); | ||
this.timeEnd.error = this.writeTimeEnd.bind(this, levels.indexOf('error')); | ||
this.timeEnd.fatal = this.writeTimeEnd.bind(this, levels.indexOf('fatal')); | ||
this.timeEnd.security = this.writeTimeEnd.bind(this, levels.indexOf('security')); | ||
this.timers = {}; | ||
@@ -116,3 +105,4 @@ /** | ||
*/ | ||
writeTimeEnd(levelIndex, label, extraLogDat) { | ||
writeTimeEnd(label, level, extraLogDat) { | ||
const levelIndex = levels.indexOf((level !== null && level !== void 0 ? level : 'info')); | ||
const extraLogData = extraLogDat || {}; | ||
@@ -125,3 +115,3 @@ const time = this.timers[label]; | ||
msg = msg ? `Timer - ${msg}` : 'Timer'; | ||
const logData = Object.assign({}, extraLogData, { msg, timerLabel: label, duration }); | ||
const logData = Object.assign(Object.assign({}, extraLogData), { msg, timerLabel: label, duration }); | ||
return this.write(levelIndex, logData); | ||
@@ -133,3 +123,3 @@ } | ||
async write(levelIndex, logData, response) { | ||
if (!isObject_1.default(logData)) { | ||
if (!utils_1.isObject(logData)) { | ||
// eslint-disable-next-line no-console | ||
@@ -139,3 +129,3 @@ console.error(`Expecting an object in logger write method but got "${typeof logData}"`); | ||
} | ||
const logObj = Object.assign({}, this.presets, logData); | ||
const logObj = Object.assign(Object.assign({}, this.presets), logData); | ||
if (response) { | ||
@@ -198,3 +188,2 @@ // If the response object has been included with the call then it means we need to | ||
else { | ||
this.debug(logObj); | ||
return loggly_wrapper_1.logSingle({ tag: this.tag, logObj }); | ||
@@ -201,0 +190,0 @@ } |
@@ -6,4 +6,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const node_fetch_1 = __importDefault(require("node-fetch")); | ||
const utils_1 = require("./utils"); | ||
const log = async (options, bulk) => { | ||
@@ -48,3 +48,3 @@ const { tag, logglyToken = process.env.LOGGLY_TOKEN, logObj: body, } = options; | ||
const { logObj } = options; | ||
if (!lodash_1.default.isObject(logObj)) { | ||
if (!utils_1.isObject(logObj)) { | ||
// eslint-disable-next-line no-console | ||
@@ -55,7 +55,7 @@ console.error(`Expected an Object in logSingle but got ${typeof logObj}`); | ||
const body = JSON.stringify(logObj); | ||
return log(Object.assign({}, options, { logObj: body }), false); | ||
return log(Object.assign(Object.assign({}, options), { logObj: body }), false); | ||
}; | ||
exports.logBatch = async (options) => { | ||
const { logObj } = options; | ||
if (!lodash_1.default.isArray(logObj)) { | ||
if (!Array.isArray(logObj)) { | ||
// eslint-disable-next-line no-console | ||
@@ -66,4 +66,4 @@ console.error(`Expected an Array in logBatch but got ${typeof logObj}`); | ||
const body = logObj.map((a) => JSON.stringify(a)).join('\n'); | ||
return log(Object.assign({}, options, { logObj: body }), true); | ||
return log(Object.assign(Object.assign({}, options), { logObj: body }), true); | ||
}; | ||
//# sourceMappingURL=loggly-wrapper.js.map |
@@ -0,4 +1,6 @@ | ||
const collectCoverage = !process.env.SKIP_COVERAGE; | ||
/** @type {jest.InitialOptions} */ | ||
module.exports = { | ||
verbose: false, | ||
collectCoverage, | ||
collectCoverageFrom: [ | ||
@@ -42,2 +44,3 @@ '!**/.vscode/**', | ||
}, | ||
verbose: false, | ||
}; |
@@ -1,4 +0,3 @@ | ||
import isObject from 'lodash/isObject'; | ||
import debug from 'debug'; | ||
import uuid from 'uuid'; | ||
import { isObject } from './utils'; | ||
@@ -10,12 +9,6 @@ import { | ||
const levels = ['trace', 'info', 'warn', 'error', 'fatal', 'security'] as const; | ||
export type LevelType = typeof levels[number]; | ||
type LevelEnum = | ||
'trace'| | ||
'info'| | ||
'warn'| | ||
'error'| | ||
'fatal'| | ||
'security'; | ||
interface LogPresets { | ||
export interface LogPresets { | ||
[key: string]: string | undefined; | ||
@@ -26,3 +19,3 @@ module?: string; | ||
interface LaLogOptions { | ||
export interface LaLogOptions { | ||
addTrackId?: boolean; | ||
@@ -35,42 +28,9 @@ moduleName?: string; | ||
type LogFunction = (logData: any, response?: any) => Promise<any>; | ||
type TimeLogFunction = (label: string, extraLogDat?: any) => Promise<any>; | ||
export type LogFunction = (logData: any, response?: any) => Promise<any>; | ||
export type TimeLogFunction = (label: string, level?: LevelType, extraLogDat?: any) => Promise<any>; | ||
interface TimeEndLog { | ||
(label: string, extraLogDat?: any): Promise<any>; | ||
trace?: TimeLogFunction; | ||
info?: TimeLogFunction; | ||
warn?: TimeLogFunction; | ||
error?: TimeLogFunction; | ||
fatal?: TimeLogFunction; | ||
security?: TimeLogFunction; | ||
} | ||
interface LaLog{ | ||
new(options: LaLogOptions): void; | ||
// Static methods | ||
create: (options: LaLogOptions) => LaLog; | ||
setLevel: (level: LevelEnum) => LevelEnum; | ||
getLevel: () => LevelEnum; | ||
allLevels: () => Array<LevelEnum>; | ||
// Instance methods | ||
time: (label: string) => void; | ||
// TODO: timeEnd has all the log methods on it. | ||
timeEnd: (label: string, extraLogData?: object) => Promise<undefined>; | ||
trace: (logObj: object) => Promise<undefined>; | ||
info: (logObj: object) => Promise<undefined>; | ||
warn: (logObj: object) => Promise<undefined>; | ||
error: (logObj: object) => Promise<undefined>; | ||
fatal: (logObj: object) => Promise<undefined>; | ||
security: (logObj: object) => Promise<undefined>; | ||
} | ||
const levels: LevelEnum[] = ['trace', 'info', 'warn', 'error', 'fatal', 'security']; | ||
const errorLevel = levels.indexOf('error'); | ||
const getInitialLogLevel = (): number => { | ||
const laLogLevel = process.env.LALOG_LEVEL as LevelEnum; | ||
const laLogLevel = process.env.LALOG_LEVEL as LevelType; | ||
if (levels.includes(laLogLevel || '')) { | ||
@@ -91,7 +51,5 @@ return levels.indexOf(laLogLevel); | ||
debug: debug.Debugger; | ||
tag: string; | ||
timeEnd: TimeEndLog; | ||
timeEnd: TimeLogFunction; | ||
@@ -138,11 +96,6 @@ trace: LogFunction; | ||
this.debug = debug(`${serviceName}:${moduleName}`); | ||
this.tag = `${serviceName}-${process.env.NODE_ENV}`; | ||
// Setup timeEnd so that it can be called without a level and when that happens the | ||
// level will default to info: | ||
const defaultTimeEndLevel = levels.indexOf('info'); | ||
this.timeEnd = this.writeTimeEnd.bind(this); | ||
this.timeEnd = this.writeTimeEnd.bind(this, defaultTimeEndLevel); | ||
// Listed like this so that Typescript can type each log level. | ||
@@ -157,9 +110,2 @@ // Previously this was setup using a loop but Typescript couldn't type it | ||
this.timeEnd.trace = this.writeTimeEnd.bind(this, levels.indexOf('trace')); | ||
this.timeEnd.info = this.writeTimeEnd.bind(this, levels.indexOf('info')); | ||
this.timeEnd.warn = this.writeTimeEnd.bind(this, levels.indexOf('warn')); | ||
this.timeEnd.error = this.writeTimeEnd.bind(this, levels.indexOf('error')); | ||
this.timeEnd.fatal = this.writeTimeEnd.bind(this, levels.indexOf('fatal')); | ||
this.timeEnd.security = this.writeTimeEnd.bind(this, levels.indexOf('security')); | ||
this.timers = {}; | ||
@@ -185,3 +131,3 @@ /** | ||
*/ | ||
static allLevels(): LevelEnum[] { | ||
static allLevels(): ReadonlyArray<LevelType> { | ||
return levels; | ||
@@ -193,3 +139,3 @@ } | ||
*/ | ||
static getLevel(): LevelEnum { | ||
static getLevel(): LevelType { | ||
return levels[currentLevelIndex]; | ||
@@ -201,3 +147,3 @@ } | ||
*/ | ||
static setLevel(newLevelName: LevelEnum): LevelEnum { | ||
static setLevel(newLevelName: LevelType): LevelType { | ||
const previousLevel = Logger.getLevel(); | ||
@@ -239,3 +185,4 @@ const newLevelIndex = levels.indexOf(newLevelName); | ||
*/ | ||
writeTimeEnd(levelIndex: number, label: string, extraLogDat?: any): Promise<any> { | ||
writeTimeEnd(label: string, level?: LevelType, extraLogDat?: any): Promise<any> { | ||
const levelIndex = levels.indexOf(level ?? 'info'); | ||
const extraLogData = extraLogDat || {}; | ||
@@ -334,3 +281,2 @@ const time = this.timers[label]; | ||
} else { | ||
this.debug(logObj); | ||
return logSingle({ tag: this.tag, logObj }); | ||
@@ -337,0 +283,0 @@ } |
@@ -1,3 +0,3 @@ | ||
import _ from 'lodash'; | ||
import fetch, { RequestInit, Response } from 'node-fetch'; | ||
import { isObject } from './utils'; | ||
@@ -65,3 +65,3 @@ interface LogOptions { | ||
const { logObj } = options; | ||
if (!_.isObject(logObj)) { | ||
if (!isObject(logObj)) { | ||
// eslint-disable-next-line no-console | ||
@@ -87,3 +87,3 @@ console.error(`Expected an Object in logSingle but got ${typeof logObj}`); | ||
const { logObj } = options; | ||
if (!_.isArray(logObj)) { | ||
if (!Array.isArray(logObj)) { | ||
// eslint-disable-next-line no-console | ||
@@ -90,0 +90,0 @@ console.error(`Expected an Array in logBatch but got ${typeof logObj}`); |
@@ -7,4 +7,2 @@ { | ||
"dependencies": { | ||
"debug": "4.1.1", | ||
"lodash": "4.17.15", | ||
"node-fetch": "2.6.0", | ||
@@ -15,13 +13,12 @@ "uuid": "3.3.3" | ||
"devDependencies": { | ||
"@types/debug": "4.1.5", | ||
"@types/jest": "24.0.19", | ||
"@types/lodash": "4.14.144", | ||
"@types/node-fetch": "2.5.2", | ||
"@types/uuid": "3.4.5", | ||
"@typescript-eslint/eslint-plugin": "2.5.0", | ||
"@typescript-eslint/parser": "2.5.0", | ||
"eslint": "6.5.1", | ||
"@types/jest": "24.0.23", | ||
"@types/node": "12.12.14", | ||
"@types/node-fetch": "2.5.4", | ||
"@types/uuid": "3.4.6", | ||
"@typescript-eslint/eslint-plugin": "2.9.0", | ||
"@typescript-eslint/parser": "2.9.0", | ||
"eslint": "6.7.1", | ||
"eslint-config-airbnb-base": "14.0.0", | ||
"eslint-plugin-import": "2.18.2", | ||
"eslint-plugin-jest": "22.19.0", | ||
"eslint-plugin-jest": "23.0.5", | ||
"eslint-plugin-security": "1.4.0", | ||
@@ -31,4 +28,4 @@ "jest": "24.9.0", | ||
"pre-commit": "1.2.2", | ||
"ts-jest": "24.1.0", | ||
"typescript": "3.5.3" | ||
"ts-jest": "24.2.0", | ||
"typescript": "3.7.2" | ||
}, | ||
@@ -63,6 +60,6 @@ "engines": { | ||
"lintfix": "eslint --ext .js . --fix", | ||
"test": "npm run lint && npm run coverage && tsc --incremental" | ||
"test": "npm run lint && npm run coverage && tsc" | ||
}, | ||
"types": "dist/index.d.ts", | ||
"version": "0.7.0" | ||
"version": "0.8.0" | ||
} |
@@ -73,5 +73,2 @@ # lalog | ||
- `lalog` uses `debug` as one of its destinations. The `serviceName` and `moduleName` props allow | ||
you to filter `debug` messages. A `debug` name of the form `serviceName:moduleName` will be created | ||
which can be used for debugging. | ||
- `presets` is an optional object that will have its contents merged with any object that's logged. Useful for putting in data that you want logged with every message. | ||
@@ -78,0 +75,0 @@ - If `addTrackId` is truthy then a `trackId` (uuid) will be added to `presets`. |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
127574
2
16
0
25
782
152
- Removeddebug@4.1.1
- Removedlodash@4.17.15
- Removeddebug@4.1.1(transitive)
- Removedlodash@4.17.15(transitive)
- Removedms@2.1.3(transitive)