MCPcopy Create free account
hub / github.com/prettier/prettier / createLogFunc

Function createLogFunc

src/cli/logger.js:30–55  ·  view source on GitHub ↗
(loggerName, color)

Source from the content-addressed store, hash-verified

28 };
29
30 function createLogFunc(loggerName, color) {
31 if (!shouldLog(loggerName)) {
32 return () => emptyLogResult;
33 }
34
35 const stream = process[loggerName === "log" ? "stdout" : "stderr"];
36 const colors = loggerName === "log" ? picocolors : picocolorsStderr;
37 const prefix = color ? `[${colors[color](loggerName)}] ` : "";
38
39 return (message, options) => {
40 options = {
41 newline: true,
42 clearable: false,
43 ...options,
44 };
45 message =
46 message.replaceAll(/^/gm, prefix) + (options.newline ? "\n" : "");
47 stream.write(message);
48
49 if (options.clearable) {
50 return {
51 clear: () => mockable.clearStreamText(stream, message),
52 };
53 }
54 };
55 }
56
57 function shouldLog(loggerName) {
58 switch (logLevel) {

Callers 1

createLoggerFunction · 0.85

Calls 2

shouldLogFunction · 0.85
writeMethod · 0.80

Tested by

no test coverage detected