Define global logger instance to be used for all logging
Summary: The advantage of this is that anyone can now log without needing to carry around a Logger object. Primary reason is for making metrics less intrusive in the codebase. Reviewed By: passy Differential Revision: D13671368 fbshipit-source-id: 162ab1351a124683aef13983fc3bcec01385cd1a
This commit is contained in:
committed by
Facebook Github Bot
parent
e71804fe9e
commit
3bcb079f87
@@ -9,6 +9,8 @@ export type LogTypes = 'error' | 'warn' | 'info' | 'debug';
|
||||
export type TrackType = 'duration' | 'usage' | 'performance' | 'success-rate';
|
||||
import ScribeLogger from './ScribeLogger';
|
||||
|
||||
var instance: ?LogManager = null;
|
||||
|
||||
export default class LogManager {
|
||||
constructor(store: ?Store) {
|
||||
this.scribeLogger = new ScribeLogger(this);
|
||||
@@ -28,3 +30,20 @@ export default class LogManager {
|
||||
|
||||
debug(data: any, category: string) {}
|
||||
}
|
||||
|
||||
export function init(store: Store): LogManager {
|
||||
if (instance) {
|
||||
throw new Error('Attempted to initialize Logger when already initialized');
|
||||
}
|
||||
instance = new LogManager(store);
|
||||
return instance;
|
||||
}
|
||||
|
||||
export function getInstance(): LogManager {
|
||||
if (!instance) {
|
||||
throw new Error(
|
||||
'Requested Logger instance without initializing it. Make sure init() is called at app start',
|
||||
);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user