@aircall/logger
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -0,1 +1,2 @@ | ||
import { Action } from 'redux'; | ||
import { LOGGER_LEVEL } from './Logger'; | ||
@@ -10,16 +11,19 @@ export declare enum LOGGER { | ||
} | ||
export interface LoggerLog { | ||
export interface LoggerLogAction { | ||
type: LOGGER; | ||
message: string; | ||
properties: object; | ||
properties: object & { | ||
lastDispatchedActions?: Action[]; | ||
}; | ||
} | ||
export declare const isLoggerAction: (action: Action<any>) => action is LoggerLogAction; | ||
export declare const initLogger: () => { | ||
type: LOGGER.INIT; | ||
}; | ||
export declare const log: (level: LOGGER_LEVEL, message: string, properties?: object) => LoggerLog & { | ||
export declare const log: (level: LOGGER_LEVEL, message: string, properties?: object) => LoggerLogAction & { | ||
level: LOGGER_LEVEL; | ||
}; | ||
export declare const info: (message: string, properties?: object) => LoggerLog; | ||
export declare const warn: (message: string, properties?: object) => LoggerLog; | ||
export declare const error: (message: string, properties?: object) => LoggerLog; | ||
export declare const track: (message: string, properties?: object) => LoggerLog; | ||
export declare const info: (message: string, properties?: object) => LoggerLogAction; | ||
export declare const warn: (message: string, properties?: object) => LoggerLogAction; | ||
export declare const error: (message: string, properties?: object) => LoggerLogAction; | ||
export declare const track: (message: string, properties?: object) => LoggerLogAction; |
@@ -12,2 +12,4 @@ "use strict"; | ||
})(LOGGER = exports.LOGGER || (exports.LOGGER = {})); | ||
const loggerActionsTypes = [LOGGER.LOG, LOGGER.INFO, LOGGER.WARN, LOGGER.ERROR]; | ||
exports.isLoggerAction = (action) => loggerActionsTypes.includes(action.type); | ||
exports.initLogger = () => ({ | ||
@@ -14,0 +16,0 @@ type: LOGGER.INIT |
import Logger from './Logger'; | ||
declare const logger: Logger; | ||
export * from './actions'; | ||
export * from './middleware'; | ||
export * from './Logger'; | ||
export default logger; |
@@ -9,4 +9,5 @@ "use strict"; | ||
__export(require("./actions")); | ||
__export(require("./middleware")); | ||
__export(require("./Logger")); | ||
exports.default = logger; | ||
//# sourceMappingURL=index.js.map |
@@ -6,2 +6,3 @@ /// <reference types="segment-analytics" /> | ||
export declare enum LOGGER_LEVEL { | ||
DEBUG = "DEBUG", | ||
INFO = "INFO", | ||
@@ -19,4 +20,5 @@ WARN = "WARN", | ||
export declare interface LoggerInitOptions { | ||
debugMode: boolean; | ||
development?: boolean; | ||
key: string; | ||
verbose?: boolean; | ||
} | ||
@@ -27,10 +29,15 @@ export default class Logger { | ||
private identification; | ||
private debugMode; | ||
private development; | ||
private verbose; | ||
private onInitialized; | ||
private getScriptTag; | ||
readonly isVerbose: boolean; | ||
readonly isInitialized: boolean; | ||
readonly isIdentified: boolean; | ||
enableVerboseMode(): void; | ||
disableVerboseMode(): void; | ||
init(options: LoggerInitOptions): void; | ||
identify(options: LoggerIdentificationOptions): void; | ||
log(level: LOGGER_LEVEL, message: string, properties?: object): void; | ||
debug(message: string, properties?: object): void; | ||
info(message: string, properties?: object): void; | ||
@@ -37,0 +44,0 @@ warn(message: string, properties?: object): void; |
@@ -5,2 +5,3 @@ "use strict"; | ||
(function (LOGGER_LEVEL) { | ||
LOGGER_LEVEL["DEBUG"] = "DEBUG"; | ||
LOGGER_LEVEL["INFO"] = "INFO"; | ||
@@ -15,3 +16,4 @@ LOGGER_LEVEL["WARN"] = "WARN"; | ||
this.identification = null; | ||
this.debugMode = false; | ||
this.development = false; | ||
this.verbose = false; | ||
} | ||
@@ -28,2 +30,5 @@ onInitialized() { | ||
} | ||
get isVerbose() { | ||
return this.verbose; | ||
} | ||
get isInitialized() { | ||
@@ -35,4 +40,11 @@ return this.initialized; | ||
} | ||
enableVerboseMode() { | ||
this.verbose = true; | ||
} | ||
disableVerboseMode() { | ||
this.verbose = false; | ||
} | ||
init(options) { | ||
this.debugMode = options.debugMode; | ||
this.development = options.development || false; | ||
this.verbose = options.verbose || false; | ||
const script = this.getScriptTag(options.key); | ||
@@ -48,9 +60,12 @@ script.addEventListener('load', this.onInitialized.bind(this)); | ||
log(level, message, properties = {}) { | ||
if (this.debugMode) { | ||
console.log('LOG', level, message, properties); // eslint-disable-line no-console | ||
if (this.development) { | ||
console.log(level, message, properties); // eslint-disable-line no-console | ||
} | ||
else { | ||
else if (level !== LOGGER_LEVEL.DEBUG || this.isVerbose) { | ||
this.track('log', Object.assign({ level, message }, properties), { 'All': false, 'Amazon Kinesis': true }); | ||
} | ||
} | ||
debug(message, properties = {}) { | ||
this.log(LOGGER_LEVEL.DEBUG, message, properties); | ||
} | ||
info(message, properties = {}) { | ||
@@ -66,3 +81,3 @@ this.log(LOGGER_LEVEL.INFO, message, properties); | ||
track(message, properties = {}, integrations = {}) { | ||
if (this.debugMode) { | ||
if (this.development) { | ||
console.log('TRACK', message, properties); // eslint-disable-line no-console | ||
@@ -69,0 +84,0 @@ } |
{ | ||
"name": "@aircall/logger", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"main": "dist/index.js", | ||
@@ -13,3 +13,3 @@ "types": "dist/index.d.ts", | ||
}, | ||
"gitHead": "6ad02dc2f6f4484618a73a42ad5a6b1a36eb19ad", | ||
"gitHead": "1f4fa00ec385102fe13378472846f40e93e3bcd8", | ||
"devDependencies": { | ||
@@ -16,0 +16,0 @@ "@types/segment-analytics": "^0.0.31" |
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
39320
29
622