MCPcopy
hub / github.com/callstack/repack / LoggerPlugin

Class LoggerPlugin

packages/repack/src/webpack/plugins/LoggerPlugin.ts:32–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30 * @category Webpack Plugin
31 */
32export class LoggerPlugin implements WebpackPlugin {
33 private static SUPPORTED_TYPES: string[] = ['debug', 'info', 'warn', 'error'];
34
35 /** {@link Reporter} instance used to actually writing logs to terminal/file. */
36 readonly reporter = new Reporter();
37
38 /**
39 * Constructs new `LoggerPlugin`.
40 *
41 * @param config Plugin configuration options.
42 */
43 constructor(private config: LoggerPluginConfig) {
44 if (this.config.output === undefined) {
45 this.config.output = { console: true };
46 }
47 // TODO: disable console in reporter
48 if (this.config.output.file) {
49 this.reporter.enableFileLogging(this.config.output.file);
50 }
51 }
52
53 /**
54 * Create log entry from Webpack log message from {@link WebpackLogger}.
55 *
56 * @param issuer Issuer of the message.
57 * @param type Type of the message.
58 * @param args The body of the message.
59 * @param timestamp Timestamp when the message was recorder.
60 * @returns Log entry object or undefined when if message is invalid.
61 */
62 createEntry(
63 issuer: string,
64 type: string,
65 args: any[],
66 timestamp?: number
67 ): LogEntry | undefined {
68 if (LoggerPlugin.SUPPORTED_TYPES.includes(type)) {
69 return {
70 timestamp: timestamp ?? Date.now(),
71 issuer: issuer.includes('reactNativeAssetsLoader')
72 ? 'reactNativeAssetsLoader'
73 : issuer,
74 type: type as LogType,
75 message: args,
76 };
77 }
78
79 return undefined;
80 }
81
82 /**
83 * Process log entry and pass it to {@link reporter} instance.
84 *
85 * @param entry Log entry to process
86 */
87 processEntry(entry: LogEntry) {
88 if (
89 !this.config.output?.console &&

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…