forked from dpa99c/react-native-launch-navigator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRNLogger.js
50 lines (41 loc) · 1.36 KB
/
RNLogger.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
import { NativeModule, NativeEventEmitter } from 'react-native';
export default class RNLogger {
nativeModule;
/********************
* Internal functions
********************/
_addListeners() {
const customModuleEmitter = new NativeEventEmitter(this.nativeModule);
customModuleEmitter.addListener('console.error', this._error.bind(this));
customModuleEmitter.addListener('console.warn', this._warn.bind(this));
customModuleEmitter.addListener('console.info', this._info.bind(this));
customModuleEmitter.addListener('console.log', this._log.bind(this));
customModuleEmitter.addListener('console.debug', this._debug.bind(this));
}
_createLogStatementFromEvent(ev){
return ev.logTag + ": " + ev.message;
}
_error(ev){
console.log(this._createLogStatementFromEvent(ev));
}
_warn(ev){
console.warn(this._createLogStatementFromEvent(ev));
}
_info(ev){
console.info(this._createLogStatementFromEvent(ev));
}
_log(ev){
console.log(this._createLogStatementFromEvent(ev));
}
_debug(ev){
console.debug(this._createLogStatementFromEvent(ev));
}
/************
* Public API
************/
constructor(nativeModule) {
this.nativeModule = nativeModule;
this._addListeners();
}
}