"Fossies" - the Fresh Open Source Software Archive 
Member "jitsi-meet-7561/react/features/base/logging/LogTransport.native.ts" (29 Sep 2023, 1755 Bytes) of package /linux/misc/jitsi-meet-7561.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 import { NativeModules } from 'react-native';
2 // eslint-disable-next-line lines-around-comment
3 // @ts-expect-error
4 import { format } from 'util';
5
6 // Some code adapted from https://github.com/houserater/react-native-lumberjack
7 // License: MIT
8
9 const { LogBridge } = NativeModules;
10
11 /**
12 * Returns the stack trace for a given @code {Error} object.
13 *
14 * @param {Error} e - The error.
15 * @returns {string} - The stack trace.
16 */
17 function stackToString(e: any) {
18 let ce;
19 let s = e.stack;
20
21 if (typeof e.cause === 'function' && (ce = e.cause())) {
22 s += `\nCaused by: ${stackToString(ce)}`;
23 }
24
25 return s;
26 }
27
28 /**
29 * Constructs a log transport object for use with @jitsi/logger.
30 *
31 * @returns {Object} - The transport object.
32 */
33 function buildTransport() {
34 return [
35 'trace',
36 'debug',
37 'info',
38 'log',
39 'warn',
40 'error'
41 ].reduce((logger: any, logName) => {
42 logger[logName] = (timestamp: string, ...args: Array<string>) => {
43 // It ignores the timestamp argument, because LogBridge will add it on the native side anyway
44 const nargs = args.map((arg: any) => {
45 if (arg instanceof Error) {
46 const errorBody = {
47 message: arg.message,
48
49 // @ts-ignore
50 code: arg.code,
51 stack: stackToString(arg)
52 };
53
54 return `Error(${arg.name})${JSON.stringify(errorBody)}`;
55 }
56
57 return arg;
58 });
59 const message = format(...nargs);
60
61 LogBridge[logName](message);
62 };
63
64 return logger;
65 }, {});
66 }
67
68 export default buildTransport();