-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlogger.tsx
71 lines (59 loc) · 1.37 KB
/
logger.tsx
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import {Alert} from 'react-native';
const stringify = (data: any) => {
try {
if (data instanceof Error) {
return data.toString();
} else if (typeof data === 'object') {
return JSON.stringify(data, null, 2);
} else if (typeof data === 'string') {
return data;
}
return String(data);
} catch (e) {
return String(data);
}
};
const alert = (prefix: string, args: Array<any>) => {
const [first, ...rest] = args;
if (typeof first === 'string' && rest.length > 0) {
const title = `[${prefix}] ${first}`;
Alert.alert(
title,
rest.map((arg: any) => stringify(arg)).join('\n'),
[{text: 'Dismiss'}],
{cancelable: true}
);
} else {
Alert.alert(
prefix,
args.map((arg: any) => stringify(arg)).join('\n'),
[{text: 'Dismiss'}],
{cancelable: true}
);
}
};
const logger = {
debug(...args: any) {
console.debug(...args);
},
log(...args: any) {
console.log(...args);
},
info(...args: any) {
console.info(...args);
},
warn(...args: any) {
console.warn(...args);
},
error(...args: any) {
// TODO: capture these errors in Sentry?
console.error(...args);
},
critical(...args: any) {
// TODO: capture these errors in Sentry?
console.error(...args);
// TODO: remove after testing
alert('Error', args);
},
};
export default logger;