@aircall/logger
Advanced tools
Comparing version 0.0.14 to 1.0.0
{ | ||
"name": "@aircall/logger", | ||
"version": "0.0.14", | ||
"version": "1.0.0", | ||
"main": "dist/index.js", | ||
@@ -13,6 +13,9 @@ "types": "dist/index.d.ts", | ||
}, | ||
"gitHead": "39ddd135130b8ca0f7526d61ffe7b752087b11ba", | ||
"gitHead": "6ad02dc2f6f4484618a73a42ad5a6b1a36eb19ad", | ||
"devDependencies": { | ||
"@types/segment-analytics": "^0.0.31" | ||
}, | ||
"dependencies": { | ||
"redux": "^4.0.1" | ||
} | ||
} |
@@ -0,1 +1,2 @@ | ||
import { Action } from 'redux'; | ||
import { LOGGER_LEVEL } from './Logger'; | ||
@@ -12,8 +13,12 @@ | ||
export interface LoggerLog { | ||
export interface LoggerLogAction { | ||
type: LOGGER; | ||
message: string; | ||
properties: object; | ||
properties: object & { lastDispatchedActions?: Action[] }; | ||
} | ||
const loggerActionsTypes = [ LOGGER.LOG, LOGGER.INFO, LOGGER.WARN, LOGGER.ERROR ]; | ||
export const isLoggerAction = (action: Action): action is LoggerLogAction => loggerActionsTypes.includes(action.type); | ||
export const initLogger = (): { type: LOGGER.INIT } => ({ | ||
@@ -23,3 +28,3 @@ type: LOGGER.INIT | ||
export const log = (level: LOGGER_LEVEL, message: string, properties: object = {}): LoggerLog & { level: LOGGER_LEVEL } => ({ | ||
export const log = (level: LOGGER_LEVEL, message: string, properties: object = {}): LoggerLogAction & { level: LOGGER_LEVEL } => ({ | ||
type: LOGGER.LOG, | ||
@@ -31,3 +36,3 @@ level, | ||
export const info = (message: string, properties: object = {}): LoggerLog => ({ | ||
export const info = (message: string, properties: object = {}): LoggerLogAction => ({ | ||
type: LOGGER.INFO, | ||
@@ -38,3 +43,3 @@ message, | ||
export const warn = (message: string, properties: object = {}): LoggerLog => ({ | ||
export const warn = (message: string, properties: object = {}): LoggerLogAction => ({ | ||
type: LOGGER.WARN, | ||
@@ -45,3 +50,3 @@ message, | ||
export const error = (message: string, properties: object = {}): LoggerLog => ({ | ||
export const error = (message: string, properties: object = {}): LoggerLogAction => ({ | ||
type: LOGGER.ERROR, | ||
@@ -52,3 +57,3 @@ message, | ||
export const track = (message: string, properties: object = {}): LoggerLog => ({ | ||
export const track = (message: string, properties: object = {}): LoggerLogAction => ({ | ||
type: LOGGER.TRACK, | ||
@@ -55,0 +60,0 @@ message, |
@@ -6,4 +6,5 @@ import Logger from './Logger'; | ||
export * from './actions'; | ||
export * from './middleware'; | ||
export * from './Logger'; | ||
export default logger; |
@@ -5,3 +5,4 @@ import Logger, { LOGGER_LEVEL, WindowWithAnalytics } from './Logger'; | ||
key: 'FOO', | ||
debugMode: false | ||
development: false, | ||
verbose: false | ||
}; | ||
@@ -50,4 +51,27 @@ | ||
}); | ||
it('should set verbose', (): void => { | ||
logger.init({ ...initOptions, verbose: true }); | ||
expect(logger.isVerbose).toBeTruthy(); | ||
}); | ||
}); | ||
describe('enableVerboseMode', (): void => { | ||
it('should set verbose', (): void => { | ||
logger.init(initOptions); | ||
expect(logger.isVerbose).toBeFalsy(); | ||
logger.enableVerboseMode(); | ||
expect(logger.isVerbose).toBeTruthy(); | ||
}); | ||
}); | ||
describe('disableVerboseMode', (): void => { | ||
it('should set verbose', (): void => { | ||
logger.init({ ...initOptions, verbose: true }); | ||
expect(logger.isVerbose).toBeTruthy(); | ||
logger.disableVerboseMode(); | ||
expect(logger.isVerbose).toBeFalsy(); | ||
}); | ||
}); | ||
describe('log', (): void => { | ||
@@ -66,9 +90,39 @@ it('should call track', (): void => { | ||
it('should call track for DEBUG level only in verbose mode', (): void => { | ||
logger.init({ ...initOptions, development: false, verbose: false }); | ||
const spy: jest.SpyInstance = jest.spyOn(logger, 'track'); | ||
logger.log(LOGGER_LEVEL.DEBUG, message, properties); | ||
expect(spy).not.toHaveBeenCalledWith(); | ||
logger.enableVerboseMode(); | ||
logger.log(LOGGER_LEVEL.DEBUG, message, properties); | ||
expect(spy).toHaveBeenCalledWith( | ||
'log', | ||
{ level: LOGGER_LEVEL.DEBUG, message, ...properties }, | ||
{ 'All': false, 'Amazon Kinesis': true } | ||
); | ||
}); | ||
it('should call console.log', (): void => { | ||
logger.init({ ...initOptions, debugMode: true }); | ||
logger.init({ ...initOptions, development: true }); | ||
logger.log(LOGGER_LEVEL.INFO, message, properties); | ||
expect(console.log).toHaveBeenCalledWith('LOG', LOGGER_LEVEL.INFO, message, properties); // eslint-disable-line no-console | ||
expect(console.log).toHaveBeenCalledWith(LOGGER_LEVEL.INFO, message, properties); // eslint-disable-line no-console | ||
}); | ||
}); | ||
describe('debug', (): void => { | ||
it('should call log', (): void => { | ||
const spy: jest.SpyInstance = jest.spyOn(logger, 'log'); | ||
logger.debug(message, properties); | ||
expect(spy).toHaveBeenCalledWith(LOGGER_LEVEL.DEBUG, message, properties); | ||
}); | ||
}); | ||
describe('info', (): void => { | ||
@@ -118,3 +172,3 @@ it('should call log', (): void => { | ||
it('should call console.log', (): void => { | ||
logger.init({ ...initOptions, debugMode: true }); | ||
logger.init({ ...initOptions, development: true }); | ||
logger.identify(identifyOptions); | ||
@@ -121,0 +175,0 @@ logger.track(message, properties, integrations); |
@@ -6,2 +6,3 @@ export declare interface WindowWithAnalytics extends Window { | ||
export enum LOGGER_LEVEL { | ||
DEBUG = 'DEBUG', | ||
INFO = 'INFO', | ||
@@ -21,4 +22,5 @@ WARN = 'WARN', | ||
export declare interface LoggerInitOptions { | ||
debugMode: boolean; | ||
development?: boolean; | ||
key: string; | ||
verbose?: boolean; | ||
} | ||
@@ -34,4 +36,6 @@ | ||
private debugMode: boolean = false; | ||
private development: boolean = false; | ||
private verbose: boolean = false; | ||
private onInitialized(): void { | ||
@@ -51,2 +55,6 @@ this.initialized = true; | ||
public get isVerbose(): boolean { | ||
return this.verbose; | ||
} | ||
public get isInitialized(): boolean { | ||
@@ -60,4 +68,13 @@ return this.initialized; | ||
public enableVerboseMode(): void { | ||
this.verbose = true; | ||
} | ||
public disableVerboseMode(): void { | ||
this.verbose = false; | ||
} | ||
public init(options: LoggerInitOptions): void { | ||
this.debugMode = options.debugMode; | ||
this.development = options.development || false; | ||
this.verbose = options.verbose || false; | ||
@@ -76,5 +93,5 @@ const script: HTMLScriptElement = this.getScriptTag(options.key); | ||
public log(level: LOGGER_LEVEL, message: string, properties: object = {}): void { | ||
if (this.debugMode) { | ||
console.log('LOG', level, message, properties); // eslint-disable-line no-console | ||
} else { | ||
if (this.development) { | ||
console.log(level, message, properties); // eslint-disable-line no-console | ||
} else if (level !== LOGGER_LEVEL.DEBUG || this.isVerbose) { | ||
this.track('log', { level, message, ...properties }, { 'All': false, 'Amazon Kinesis': true }); | ||
@@ -84,2 +101,6 @@ } | ||
public debug(message: string, properties: object = {}): void { | ||
this.log(LOGGER_LEVEL.DEBUG, message, properties); | ||
} | ||
public info(message: string, properties: object = {}): void { | ||
@@ -98,3 +119,3 @@ this.log(LOGGER_LEVEL.INFO, message, properties); | ||
public track(message: string, properties: object = {}, integrations: object = {}): void { | ||
if (this.debugMode) { | ||
if (this.development) { | ||
console.log('TRACK', message, properties); // eslint-disable-line no-console | ||
@@ -101,0 +122,0 @@ } else { |
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 2 instances 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
35512
23
562
1
1
2
+ Addedredux@^4.0.1
+ Added@babel/runtime@7.26.0(transitive)
+ Addedredux@4.2.1(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)