Comparing version 1.0.1 to 1.0.2
@@ -29,3 +29,3 @@ import { Request, Response } from 'express'; | ||
export declare type LogFunction = (logData: LogData, response?: ResponseWrapper) => Promise<any>; | ||
export declare type TimeLogFunction = (label: string, level?: LevelType, extraLogDat?: LogData) => Promise<any>; | ||
export declare type TimeLogFunction = (label: string, level: LevelType, extraLogDat?: LogData) => Promise<any>; | ||
export default class Logger { | ||
@@ -76,3 +76,3 @@ isTransient: boolean; | ||
*/ | ||
writeTimeEnd(label: string, level?: LevelType, extraLogDat?: LogData): Promise<any>; | ||
writeTimeEnd(label: string, level: LevelType, extraLogDat?: LogData): Promise<any>; | ||
/** | ||
@@ -79,0 +79,0 @@ * Write log to destination |
@@ -21,6 +21,6 @@ "use strict"; | ||
const laLogLevel = process.env.LALOG_LEVEL; | ||
if (levels.includes(laLogLevel || '')) { | ||
if (levels.includes(laLogLevel)) { | ||
return levels.indexOf(laLogLevel); | ||
} | ||
return levels.indexOf('error'); | ||
return errorLevel; | ||
}; | ||
@@ -33,5 +33,5 @@ let currentLevelIndex = getInitialLogLevel(); | ||
this.logCollector = isTransient ? [] : null; | ||
this.presets = Object.assign({ module: moduleName }, (utils_1.isObject(presets) ? presets : {})); | ||
this.presets = Object.assign({ module: moduleName }, ((0, utils_1.isObject)(presets) ? presets : {})); | ||
if (addTrackId && !this.presets.trackId) { | ||
this.presets.trackId = uuid_1.v4(); | ||
this.presets.trackId = (0, uuid_1.v4)(); | ||
} | ||
@@ -118,3 +118,3 @@ this.tag = `${serviceName}-${process.env.NODE_ENV}`; | ||
writeTimeEnd(label, level, extraLogDat) { | ||
const levelIndex = levels.indexOf(level !== null && level !== void 0 ? level : 'info'); | ||
const levelIndex = levels.indexOf(level); | ||
const extraLogData = extraLogDat || {}; | ||
@@ -136,3 +136,3 @@ const time = this.timers[label]; | ||
var _a; | ||
if (!utils_1.isObject(logData)) { | ||
if (!(0, utils_1.isObject)(logData)) { | ||
// eslint-disable-next-line no-console | ||
@@ -150,3 +150,3 @@ console.error(`Expecting an object in logger write method but got "${typeof logData}"`); | ||
// that can be provided to the user and links back to the error log. | ||
const errorId = logObj.errorId || uuid_1.v4(); | ||
const errorId = logObj.errorId || (0, uuid_1.v4)(); | ||
logObj.errorId = errorId; | ||
@@ -203,3 +203,3 @@ const { res, code } = response; | ||
this.isTransientTriggered = true; | ||
await loggly_wrapper_1.logBatch({ logObj: this.logCollector, tag: this.tag }); | ||
await (0, loggly_wrapper_1.logBatch)({ logObj: this.logCollector, tag: this.tag }); | ||
this.logCollector = null; // Can GC right away now that this array is no longer needed | ||
@@ -209,3 +209,3 @@ } | ||
else { | ||
return loggly_wrapper_1.logSingle({ logObj, tag: this.tag }); | ||
return (0, loggly_wrapper_1.logSingle)({ logObj, tag: this.tag }); | ||
} | ||
@@ -212,0 +212,0 @@ } |
@@ -25,3 +25,3 @@ "use strict"; | ||
}; | ||
const result = await node_fetch_1.default(url, fetchOptions); | ||
const result = await (0, node_fetch_1.default)(url, fetchOptions); | ||
if (result.status !== 200) { | ||
@@ -35,7 +35,11 @@ const { stack } = new Error(); | ||
} | ||
catch (err) { | ||
catch (error) { | ||
// Typescript requires the instanceof syntax which is why we have | ||
// this istanbul ignore directive. | ||
/* istanbul ignore next */ | ||
const err = error instanceof Error ? error : new Error('unknown'); | ||
// eslint-disable-next-line no-console | ||
console.error(`fetch() threw an error: ${err.message} | ||
url: ${url} | ||
options: ${utils_1.safeJsonStringify(fetchOptions)}`); | ||
options: ${(0, utils_1.safeJsonStringify)(fetchOptions)}`); | ||
return {}; | ||
@@ -50,3 +54,3 @@ } | ||
const { logObj } = options; | ||
if (!utils_1.isObject(logObj)) { | ||
if (!(0, utils_1.isObject)(logObj)) { | ||
// eslint-disable-next-line no-console | ||
@@ -56,3 +60,3 @@ console.error(`Expected an Object in logSingle but got ${typeof logObj}`); | ||
} | ||
const body = utils_1.safeJsonStringify(logObj); | ||
const body = (0, utils_1.safeJsonStringify)(logObj); | ||
return log(Object.assign(Object.assign({}, options), { logObj: body }), false); | ||
@@ -59,0 +63,0 @@ }; |
@@ -62,3 +62,3 @@ import { v4 } from 'uuid'; | ||
export type TimeLogFunction = ( | ||
label: string, level?: LevelType, extraLogDat?: LogData, | ||
label: string, level: LevelType, extraLogDat?: LogData, | ||
) => Promise<any>; | ||
@@ -70,6 +70,6 @@ | ||
const laLogLevel = process.env.LALOG_LEVEL as LevelType; | ||
if (levels.includes(laLogLevel || '')) { | ||
if (levels.includes(laLogLevel)) { | ||
return levels.indexOf(laLogLevel); | ||
} | ||
return levels.indexOf('error'); | ||
return errorLevel; | ||
}; | ||
@@ -219,4 +219,4 @@ | ||
*/ | ||
writeTimeEnd(label: string, level?: LevelType, extraLogDat?: LogData): Promise<any> { | ||
const levelIndex = levels.indexOf(level ?? 'info'); | ||
writeTimeEnd(label: string, level: LevelType, extraLogDat?: LogData): Promise<any> { | ||
const levelIndex = levels.indexOf(level); | ||
const extraLogData = extraLogDat || {}; | ||
@@ -223,0 +223,0 @@ const time = this.timers[label]; |
@@ -45,3 +45,7 @@ import fetch, { RequestInit, Response } from 'node-fetch'; | ||
return result.json(); | ||
} catch (err) { | ||
} catch (error: unknown) { | ||
// Typescript requires the instanceof syntax which is why we have | ||
// this istanbul ignore directive. | ||
/* istanbul ignore next */ | ||
const err = error instanceof Error ? error : new Error('unknown'); | ||
// eslint-disable-next-line no-console | ||
@@ -48,0 +52,0 @@ console.error(`fetch() threw an error: ${err.message} |
@@ -14,3 +14,3 @@ { | ||
"@types/jest": "27.0.1", | ||
"@types/node": "16.7.2", | ||
"@types/node": "16.7.4", | ||
"@types/node-fetch": "2.5.12", | ||
@@ -26,6 +26,6 @@ "@types/uuid": "8.3.1", | ||
"eslint-plugin-sort-keys-fix": "1.1.2", | ||
"jest": "27.0.6", | ||
"jest": "27.1.0", | ||
"pre-commit": "1.2.2", | ||
"ts-jest": "27.0.5", | ||
"typescript": "4.3.5" | ||
"typescript": "4.4.2" | ||
}, | ||
@@ -59,3 +59,3 @@ "homepage": "https://github.com/guyellis/lalog#readme", | ||
"types": "dist/index.d.ts", | ||
"version": "1.0.1" | ||
"version": "1.0.2" | ||
} |
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
71870
926