(loggerName, color)
| 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) { |
no test coverage detected