@aircall/logger
Advanced tools
Comparing version 3.2.1 to 3.4.1
@@ -1,8 +0,5 @@ | ||
import { Context } from '@datadog/browser-core'; | ||
import { StatusType, LogsInitConfiguration } from '@datadog/browser-logs'; | ||
export { StatusType as LOGGER_LEVEL } from '@datadog/browser-logs'; | ||
import { LogsInitConfiguration } from '@datadog/browser-logs'; | ||
import { LoggerLevel, BaseLogger, LoggerContext } from '@aircall/base-logger'; | ||
export { LoggerLevel as LOGGER_LEVEL } from '@aircall/base-logger'; | ||
interface LoggerContext extends Context { | ||
service: string; | ||
} | ||
declare enum LOGGER_ENVIRONMENT { | ||
@@ -13,8 +10,7 @@ DEVELOPMENT = "development", | ||
BETA = "beta", | ||
PRODUCTION = "production", | ||
QA = "qa" | ||
PRODUCTION = "production" | ||
} | ||
interface LoggerOptions { | ||
token: string; | ||
level: StatusType; | ||
level: LoggerLevel; | ||
debug?: boolean; | ||
@@ -25,7 +21,5 @@ } | ||
} | ||
declare class Logger { | ||
declare class Logger extends BaseLogger { | ||
readonly options: LoggerOptions; | ||
level: StatusType | undefined; | ||
initialized: boolean; | ||
queue: Array<() => void>; | ||
level: LoggerLevel | undefined; | ||
logSchemaValidator: any; | ||
@@ -35,7 +29,6 @@ compiledLogSchema: any; | ||
init(initOptions?: LoggerInitOptions): void; | ||
setContext<T extends LoggerContext>(context: T): void; | ||
private logOrEnqueue; | ||
setLevel(level: StatusType): void; | ||
cleanProperties(properties?: {}): object; | ||
log(level: StatusType, message: string, properties?: {}): void; | ||
reset(): void; | ||
setContext<T extends Partial<LoggerContext>>(context: T): void; | ||
setLevel(level: LoggerLevel): void; | ||
log(level: LoggerLevel, message: string, properties?: {}): void; | ||
debug(message: string, properties?: {}): void; | ||
@@ -47,2 +40,2 @@ info(message: string, properties?: {}): void; | ||
export { LOGGER_ENVIRONMENT, Logger, LoggerContext, LoggerInitOptions, LoggerOptions }; | ||
export { LOGGER_ENVIRONMENT, Logger, LoggerInitOptions, LoggerOptions }; |
'use strict'; | ||
var browserLogs = require('@datadog/browser-logs'); | ||
var baseLogger = require('@aircall/base-logger'); | ||
// src/Logger.ts | ||
// src/constants.ts | ||
var SENSITIVE_KEYS = [ | ||
"password", | ||
"Authorization", | ||
"confirmationPassword", | ||
"newPassword", | ||
"currentPassword", | ||
"idToken", | ||
"token" | ||
]; | ||
var DEFAULT_SENSITIVE_TEXT = "<sensitive>"; | ||
// src/utils.ts | ||
var isArray = (value) => Array.isArray(value); | ||
var isObject = (value) => value !== null && typeof value === "object"; | ||
var mapObject = (object, iteratee) => { | ||
const source = {}; | ||
for (const key in object) { | ||
if (Object.hasOwnProperty.call(object, key)) { | ||
const element = object[key]; | ||
source[key] = iteratee(element, key, object); | ||
} | ||
} | ||
return source; | ||
}; | ||
var map = (value, iteratee) => { | ||
if (isArray(value)) { | ||
return value.map((element, index) => iteratee(element, index, value)); | ||
} | ||
if (isObject(value)) { | ||
return mapObject(value, (value2, key) => iteratee(value2, key, value2)); | ||
} | ||
}; | ||
var deepMap = (object, iteratee, maxDepth = 10) => { | ||
let count = 0; | ||
const closure = (object2, iteratee2) => { | ||
if (count > maxDepth) { | ||
count = 0; | ||
return null; | ||
} | ||
return map(object2, (value, key) => { | ||
if (isArray(value) || isObject(value)) { | ||
count++; | ||
return closure(value, iteratee2); | ||
} | ||
count = 0; | ||
return iteratee2(value, key, object2); | ||
}); | ||
}; | ||
return closure(object, iteratee); | ||
}; | ||
var containsAValue = (value, keys) => { | ||
if (!value) { | ||
return false; | ||
} | ||
return keys.some((key) => value.includes(key)); | ||
}; | ||
function isString(value) { | ||
return typeof value === "string"; | ||
} | ||
// src/Logger.ts | ||
var LOGGER_ENVIRONMENT = /* @__PURE__ */ ((LOGGER_ENVIRONMENT2) => { | ||
@@ -75,12 +13,10 @@ LOGGER_ENVIRONMENT2["DEVELOPMENT"] = "development"; | ||
LOGGER_ENVIRONMENT2["PRODUCTION"] = "production"; | ||
LOGGER_ENVIRONMENT2["QA"] = "qa"; | ||
return LOGGER_ENVIRONMENT2; | ||
})(LOGGER_ENVIRONMENT || {}); | ||
var Logger = class { | ||
var Logger = class extends baseLogger.BaseLogger { | ||
constructor(options) { | ||
super(); | ||
this.options = options; | ||
} | ||
level; | ||
initialized = false; | ||
queue = []; | ||
logSchemaValidator; | ||
@@ -90,2 +26,5 @@ compiledLogSchema; | ||
init(initOptions) { | ||
if (!this.enabled) { | ||
return; | ||
} | ||
const { token, debug, level } = this.options; | ||
@@ -102,13 +41,14 @@ browserLogs.datadogLogs.init({ | ||
this.setLevel(level); | ||
this.initialized = true; | ||
this.queue.forEach((fn) => fn()); | ||
super.init(); | ||
} | ||
// set logger context | ||
reset() { | ||
super.reset(); | ||
this.level = this.options.level; | ||
browserLogs.datadogLogs.logger.setLevel(this.options.level); | ||
browserLogs.datadogLogs.logger.setContext({}); | ||
} | ||
// Set logger context | ||
setContext(context) { | ||
browserLogs.datadogLogs.logger.setContext(context); | ||
} | ||
// Send logs or enqueue them if the SDK isn't initialized | ||
logOrEnqueue(fn) { | ||
this.initialized ? fn() : this.queue.push(fn); | ||
} | ||
// Set level of SDK: logs under this level won't be sent | ||
@@ -119,43 +59,21 @@ setLevel(level) { | ||
} | ||
// It will scrub the properties which their keys contains some sensitive keywords | ||
cleanProperties(properties = {}) { | ||
return deepMap(properties, (value, key) => { | ||
try { | ||
const parsedValue = isString(value) && JSON.parse(value); | ||
if (isObject(parsedValue) || isArray(parsedValue)) { | ||
return JSON.stringify(this.cleanProperties(parsedValue)); | ||
} | ||
} catch (e) { | ||
} | ||
const keyContainsSensitiveData = isString(key) && containsAValue(key, SENSITIVE_KEYS); | ||
if (keyContainsSensitiveData) { | ||
return DEFAULT_SENSITIVE_TEXT; | ||
} | ||
return value; | ||
}); | ||
} | ||
// Generic method to send logs depending on level parameter | ||
log(level, message, properties = {}) { | ||
const cleanedProperties = this.cleanProperties(properties); | ||
this.logOrEnqueue(() => browserLogs.datadogLogs.logger.log(message, cleanedProperties, level)); | ||
const payload = this.buildPayload(properties); | ||
this.logOrEnqueue(() => browserLogs.datadogLogs.logger.log(message, payload, level)); | ||
} | ||
// Send debug logs | ||
debug(message, properties = {}) { | ||
const cleanedProperties = this.cleanProperties(properties); | ||
this.logOrEnqueue(() => browserLogs.datadogLogs.logger.debug(message, cleanedProperties)); | ||
const payload = this.buildPayload(properties); | ||
this.logOrEnqueue(() => browserLogs.datadogLogs.logger.debug(message, payload)); | ||
} | ||
// Send info logs | ||
info(message, properties = {}) { | ||
const cleanedProperties = this.cleanProperties(properties); | ||
this.logOrEnqueue(() => browserLogs.datadogLogs.logger.info(message, cleanedProperties)); | ||
const payload = this.buildPayload(properties); | ||
this.logOrEnqueue(() => browserLogs.datadogLogs.logger.info(message, payload)); | ||
} | ||
// Send warning logs | ||
warn(message, properties = {}) { | ||
const cleanedProperties = this.cleanProperties(properties); | ||
this.logOrEnqueue(() => browserLogs.datadogLogs.logger.warn(message, cleanedProperties)); | ||
const payload = this.buildPayload(properties); | ||
this.logOrEnqueue(() => browserLogs.datadogLogs.logger.warn(message, payload)); | ||
} | ||
// Send error logs | ||
error(message, properties = {}) { | ||
const cleanedProperties = this.cleanProperties(properties); | ||
this.logOrEnqueue(() => browserLogs.datadogLogs.logger.error(message, cleanedProperties)); | ||
const payload = this.buildPayload(properties); | ||
this.logOrEnqueue(() => browserLogs.datadogLogs.logger.error(message, payload)); | ||
} | ||
@@ -166,5 +84,5 @@ }; | ||
enumerable: true, | ||
get: function () { return browserLogs.StatusType; } | ||
get: function () { return baseLogger.LoggerLevel; } | ||
}); | ||
exports.LOGGER_ENVIRONMENT = LOGGER_ENVIRONMENT; | ||
exports.Logger = Logger; |
{ | ||
"name": "@aircall/logger", | ||
"version": "3.2.1", | ||
"version": "3.4.1", | ||
"description": "Aircall Next Logger Module", | ||
@@ -28,26 +28,24 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@aircall/test-sequencer": "1.0.2", | ||
"@aircall/tsconfig": "1.4.2", | ||
"@size-limit/preset-small-lib": "8.1.0", | ||
"@types/jest": "29.5.2", | ||
"jest": "29.5.0", | ||
"size-limit": "8.1.0", | ||
"ts-jest": "29.1.0", | ||
"@aircall/eslint-config": "1.3.1", | ||
"@aircall/tsconfig": "1.4.0", | ||
"@size-limit/preset-small-lib": "8.1.0", | ||
"eslint": "8.30.0", | ||
"size-limit": "8.1.0", | ||
"tsup": "7.1.0", | ||
"tslib": "2.4.0" | ||
"tslib": "2.4.0", | ||
"tsup": "7.1.0" | ||
}, | ||
"dependencies": { | ||
"@datadog/browser-logs": "4.17.1", | ||
"@datadog/browser-core": "4.24.0" | ||
"@aircall/base-logger": "0.1.0", | ||
"@datadog/browser-logs": "4.17.1" | ||
}, | ||
"scripts": { | ||
"build": "tsup --config ../../tsup.config.ts", | ||
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist", | ||
"dev": "pnpm build --watch", | ||
"build": "tsup --config ../../tsup.config.ts", | ||
"test": "jest --passWithNoTests", | ||
"posttest": "pnpm run size", | ||
"lint": "eslint --ext ts src", | ||
"size": "size-limit", | ||
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist" | ||
"test:ci": "pnpm run test --shard ${CI_NODE_INDEX}/${CI_NODE_TOTAL} --passWithNoTests --silent", | ||
"test": "jest --passWithNoTests" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
9
9103
190
+ Added@aircall/base-logger@0.1.0
- Removed@datadog/browser-core@4.24.0
- Removed@datadog/browser-core@4.24.0(transitive)