@gradientedge/logger
Advanced tools
Comparing version 3.1.0 to 4.0.0
@@ -11,3 +11,4 @@ import { LoggerLevelValue } from './types'; | ||
export declare const DEFAULT_LOG_LEVEL: LoggerLevelValue; | ||
export declare const LOG_BUFFER_ENABLED: boolean; | ||
export declare const VALID_LOGGER_LEVEL_VALUES: ("debug" | "info" | "warn" | "error")[]; | ||
//# sourceMappingURL=constants.d.ts.map |
"use strict"; | ||
var _a, _b; | ||
var _a, _b, _c; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.VALID_LOGGER_LEVEL_VALUES = exports.DEFAULT_LOG_LEVEL = exports.LogLevelNumber = void 0; | ||
exports.VALID_LOGGER_LEVEL_VALUES = exports.LOG_BUFFER_ENABLED = exports.DEFAULT_LOG_LEVEL = exports.LogLevelNumber = void 0; | ||
const types_1 = require("./types"); | ||
@@ -33,3 +33,4 @@ /** | ||
exports.DEFAULT_LOG_LEVEL = logLevel; | ||
exports.LOG_BUFFER_ENABLED = ((_c = process === null || process === void 0 ? void 0 : process.env) === null || _c === void 0 ? void 0 : _c.LOG_BUFFER_ENABLED) !== '0'; | ||
exports.VALID_LOGGER_LEVEL_VALUES = Object.values(types_1.LoggerLevel); | ||
//# sourceMappingURL=constants.js.map |
import { Logger } from './logger'; | ||
declare const systemLogger: Logger; | ||
export default systemLogger; | ||
export { generateOutput } from './output'; | ||
export { LogLevelNumber } from './constants'; | ||
export { LoggerLevelValue, LoggerLevel, LoggerOptions, LoggerTransportFn, LoggerTransport, LoggerOutput } from './types'; | ||
export { Logger } from './logger'; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Logger = exports.LoggerLevel = void 0; | ||
exports.Logger = exports.LoggerLevel = exports.LogLevelNumber = exports.generateOutput = void 0; | ||
const logger_1 = require("./logger"); | ||
const systemLogger = new logger_1.Logger(); | ||
exports.default = systemLogger; | ||
var output_1 = require("./output"); | ||
Object.defineProperty(exports, "generateOutput", { enumerable: true, get: function () { return output_1.generateOutput; } }); | ||
var constants_1 = require("./constants"); | ||
Object.defineProperty(exports, "LogLevelNumber", { enumerable: true, get: function () { return constants_1.LogLevelNumber; } }); | ||
var types_1 = require("./types"); | ||
@@ -8,0 +12,0 @@ Object.defineProperty(exports, "LoggerLevel", { enumerable: true, get: function () { return types_1.LoggerLevel; } }); |
import { LoggerOptions, LoggerTransport, LoggerLevelValue } from './types'; | ||
export interface LogBuffer { | ||
method: (...args: any[]) => any; | ||
level: LoggerLevelValue; | ||
timestamp: string; | ||
args: any[]; | ||
} | ||
export declare class Logger { | ||
@@ -7,2 +13,5 @@ baseData: Record<string, any> | null; | ||
readonly transport: LoggerTransport; | ||
buffer: LogBuffer[]; | ||
bufferEnabled: boolean; | ||
bufferInitiallyEnabled: boolean; | ||
constructor(options?: LoggerOptions); | ||
@@ -14,4 +23,9 @@ debug(...args: any[]): void; | ||
text(input: string): void; | ||
process(method: (...args: any[]) => any, level: LoggerLevelValue, args: any[]): void; | ||
process(method: (...args: any[]) => any, level: LoggerLevelValue, args: any[], timestamp?: string, forceOutput?: boolean): void; | ||
processWithBuffer(method: (...args: any[]) => any, level: LoggerLevelValue, args: any[]): void; | ||
flushBuffer(): void; | ||
clearBuffer(): void; | ||
enableBuffering(): void; | ||
disableBuffering(): void; | ||
} | ||
//# sourceMappingURL=logger.d.ts.map |
@@ -14,2 +14,3 @@ "use strict"; | ||
var _a; | ||
this.buffer = []; | ||
this.baseData = (_a = options === null || options === void 0 ? void 0 : options.baseData) !== null && _a !== void 0 ? _a : null; | ||
@@ -32,5 +33,10 @@ if ((options === null || options === void 0 ? void 0 : options.level) && constants_1.VALID_LOGGER_LEVEL_VALUES.includes(options.level)) { | ||
} | ||
this.bufferEnabled = constants_1.LOG_BUFFER_ENABLED; | ||
if ((options === null || options === void 0 ? void 0 : options.bufferEnabled) !== undefined) { | ||
this.bufferEnabled = options === null || options === void 0 ? void 0 : options.bufferEnabled; | ||
} | ||
this.bufferInitiallyEnabled = this.bufferEnabled; | ||
} | ||
debug(...args) { | ||
this.process(this.transport.debug, 'debug', args); | ||
this.processWithBuffer(this.transport.debug, 'debug', args); | ||
} | ||
@@ -44,2 +50,5 @@ info(...args) { | ||
error(...args) { | ||
// Turn off further buffering. | ||
this.disableBuffering(); | ||
this.flushBuffer(); | ||
this.process(this.transport.error, 'error', args); | ||
@@ -50,12 +59,42 @@ } | ||
} | ||
process(method, level, args) { | ||
process(method, level, args, timestamp, forceOutput) { | ||
const levelNumber = constants_1.LogLevelNumber[level]; | ||
if (levelNumber < this.levelNumber || !Array.isArray(args) || args.length === 0) { | ||
if ((levelNumber < this.levelNumber || !Array.isArray(args) || args.length === 0) && !forceOutput) { | ||
return; | ||
} | ||
const output = (0, output_1.generateOutput)(level, this.baseData, args); | ||
if (!timestamp) { | ||
timestamp = new Date().toISOString(); | ||
} | ||
const output = (0, output_1.generateOutput)(level, timestamp, this.baseData, args); | ||
method((0, json_stringify_safe_1.default)(output)); | ||
} | ||
processWithBuffer(method, level, args) { | ||
if (this.levelNumber > constants_1.LogLevelNumber[level] && level === 'debug' && this.bufferEnabled) { | ||
this.buffer.push({ method, level, timestamp: new Date().toISOString(), args }); | ||
} | ||
else { | ||
this.process(method, level, args); | ||
} | ||
} | ||
flushBuffer() { | ||
while (this.buffer.length) { | ||
const log = this.buffer.shift(); | ||
if (log) { | ||
this.process(log.method, log.level, log.args, log.timestamp, true); | ||
} | ||
} | ||
} | ||
clearBuffer() { | ||
this.buffer = []; | ||
// Restore buffering to its initial state. | ||
this.bufferEnabled = this.bufferInitiallyEnabled; | ||
} | ||
enableBuffering() { | ||
this.bufferEnabled = true; | ||
} | ||
disableBuffering() { | ||
this.bufferEnabled = false; | ||
} | ||
} | ||
exports.Logger = Logger; | ||
//# sourceMappingURL=logger.js.map |
import { LoggerLevelValue, LoggerOutput } from '../types'; | ||
export declare function generateOutput(level: LoggerLevelValue, baseData: Record<string, any> | null, args: any[]): LoggerOutput; | ||
export declare function generateOutput(level: LoggerLevelValue, timestamp: string, baseData: Record<string, any> | null, args: any[]): LoggerOutput; | ||
//# sourceMappingURL=generate.d.ts.map |
@@ -5,5 +5,6 @@ "use strict"; | ||
const transform_1 = require("../transform/transform"); | ||
function generateOutput(level, baseData, args) { | ||
function generateOutput(level, timestamp, baseData, args) { | ||
const output = { | ||
level, | ||
timestamp, | ||
}; | ||
@@ -10,0 +11,0 @@ let outputData = args; |
@@ -5,8 +5,6 @@ "use strict"; | ||
const error_1 = require("./error"); | ||
const mask_1 = require("../mask"); | ||
function transformData(data) { | ||
// Step 1 - filter out any fields we don't want | ||
// - How are we going to avoid massive log output when someone tries | ||
// to output a response object for example? | ||
// Step 2 - mask sensitive fields | ||
// filter out any fields we don't want | ||
// How are we going to avoid massive log output when someone tries | ||
// to output a response object for example? | ||
let transformedData; | ||
@@ -24,5 +22,5 @@ data.forEach((item) => { | ||
} | ||
return (0, mask_1.maskSensitiveData)(transformedData); | ||
return transformedData; | ||
} | ||
exports.transformData = transformData; | ||
//# sourceMappingURL=transform.js.map |
@@ -18,2 +18,3 @@ export type LoggerLevelValue = (typeof LoggerLevel)[keyof typeof LoggerLevel]; | ||
transport?: LoggerTransport; | ||
bufferEnabled?: boolean; | ||
} | ||
@@ -31,2 +32,3 @@ /** | ||
level: LoggerLevelValue; | ||
timestamp: string; | ||
message?: string; | ||
@@ -33,0 +35,0 @@ base?: Record<string, any>; |
{ | ||
"name": "@gradientedge/logger", | ||
"version": "3.1.0", | ||
"version": "4.0.0", | ||
"description": "Request-context sensitive logger package", | ||
@@ -22,10 +22,6 @@ "author": "Jimmy Thomson <jimmy@gradientedge.com>", | ||
"dependencies": { | ||
"json-stringify-safe": "^5.0.1", | ||
"lodash.clonedeep": "^4.5.0", | ||
"traverse": "^0.6.7" | ||
"json-stringify-safe": "^5.0.1" | ||
}, | ||
"devDependencies": { | ||
"@types/json-stringify-safe": "^5.0.0", | ||
"@types/lodash.clonedeep": "^4.5.7", | ||
"@types/traverse": "^0.6.32" | ||
"@types/json-stringify-safe": "^5.0.0" | ||
}, | ||
@@ -32,0 +28,0 @@ "scripts": { |
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
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
36651
1
1
435
42
7
- Removedlodash.clonedeep@^4.5.0
- Removedtraverse@^0.6.7
- Removedarray-buffer-byte-length@1.0.1(transitive)
- Removedarraybuffer.prototype.slice@1.0.3(transitive)
- Removedavailable-typed-arrays@1.0.7(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removeddata-view-buffer@1.0.1(transitive)
- Removeddata-view-byte-length@1.0.1(transitive)
- Removeddata-view-byte-offset@1.0.0(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddefine-properties@1.2.1(transitive)
- Removedes-abstract@1.23.3(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.0.0(transitive)
- Removedes-set-tostringtag@2.0.3(transitive)
- Removedes-to-primitive@1.2.1(transitive)
- Removedfor-each@0.3.3(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedfunction.prototype.name@1.1.6(transitive)
- Removedfunctions-have-names@1.2.3(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedget-symbol-description@1.0.2(transitive)
- Removedglobalthis@1.0.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-bigints@1.0.2(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhas-tostringtag@1.0.2(transitive)
- Removedhasown@2.0.2(transitive)
- Removedinternal-slot@1.0.7(transitive)
- Removedis-array-buffer@3.0.4(transitive)
- Removedis-bigint@1.0.4(transitive)
- Removedis-boolean-object@1.1.2(transitive)
- Removedis-callable@1.2.7(transitive)
- Removedis-data-view@1.0.1(transitive)
- Removedis-date-object@1.0.5(transitive)
- Removedis-negative-zero@2.0.3(transitive)
- Removedis-number-object@1.0.7(transitive)
- Removedis-regex@1.1.4(transitive)
- Removedis-shared-array-buffer@1.0.3(transitive)
- Removedis-string@1.0.7(transitive)
- Removedis-symbol@1.0.4(transitive)
- Removedis-typed-array@1.1.13(transitive)
- Removedis-weakref@1.0.2(transitive)
- Removedisarray@2.0.5(transitive)
- Removedlodash.clonedeep@4.5.0(transitive)
- Removedobject-inspect@1.13.2(transitive)
- Removedobject-keys@1.1.1(transitive)
- Removedobject.assign@4.1.5(transitive)
- Removedpossible-typed-array-names@1.0.0(transitive)
- Removedregexp.prototype.flags@1.5.3(transitive)
- Removedsafe-array-concat@1.1.2(transitive)
- Removedsafe-regex-test@1.0.3(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedset-function-name@2.0.2(transitive)
- Removedside-channel@1.0.6(transitive)
- Removedstring.prototype.trim@1.2.9(transitive)
- Removedstring.prototype.trimend@1.0.8(transitive)
- Removedstring.prototype.trimstart@1.0.8(transitive)
- Removedtraverse@0.6.10(transitive)
- Removedtyped-array-buffer@1.0.2(transitive)
- Removedtyped-array-byte-length@1.0.1(transitive)
- Removedtyped-array-byte-offset@1.0.2(transitive)
- Removedtyped-array-length@1.0.6(transitive)
- Removedtypedarray.prototype.slice@1.0.3(transitive)
- Removedunbox-primitive@1.0.2(transitive)
- Removedwhich-boxed-primitive@1.0.2(transitive)
- Removedwhich-typed-array@1.1.15(transitive)