Compare commits

..

No commits in common. "f21cce994459f143222dde9e7d4477c418028d58" and "6b4173d636de3234fae3dc36794d13d7d64614da" have entirely different histories.

2 changed files with 12 additions and 46 deletions

View File

@ -25,14 +25,6 @@ const customTypescriptConfig = {
rules: { rules: {
'linebreak-style': ['error', 'unix'], 'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single', { avoidEscape: true }], quotes: ['error', 'single', { avoidEscape: true }],
semi: ['error', 'never'],
'@typescript-eslint/no-unused-vars': ['error', {
'args': 'all',
'argsIgnorePattern': '^_',
'caughtErrorsIgnorePattern': '^_',
'destructuredArrayIgnorePattern': '^_',
'varsIgnorePattern': '^_',
}],
}, },
} }
@ -59,10 +51,4 @@ export default [
eslintJs.configs.recommended, eslintJs.configs.recommended,
...recommendedTypeScriptConfigs, ...recommendedTypeScriptConfigs,
customTypescriptConfig, customTypescriptConfig,
{
rules: {
quotes: ['error', 'single', { avoidEscape: true }],
semi: ['error', 'never'],
},
},
] ]

View File

@ -3,23 +3,12 @@ import {
LogLevel, LogLevel,
LogMessage, LogMessage,
LogMessageFormatter, LogMessageFormatter,
} from "./log-message"; } from './log-message';
import { LogAppender } from "./log-appender"; import { LogAppender } from './log-appender';
/**
* A log appender that writes log messages to the console. The behavior of the
* log appender can be configured with a threshold level and a message
* formatter.
*
* When the message formatter returns a string value, that value is logged to
* the console as-is. When the message formatter returns an object, a summary
* string is logged to the console, followed by the object itself. This allows
* logs to be easily read in the console, while still providing the structured
* data for inspection in the browser's developer tools.
*/
export class ConsoleLogAppender implements LogAppender { export class ConsoleLogAppender implements LogAppender {
public threshold = LogLevel.ALL; public threshold = LogLevel.ALL;
public formatter: LogMessageFormatter = flattenMessage; public formatter: LogMessageFormatter = flattenMessage
constructor(threshold?: LogLevel, formatter?: LogMessageFormatter) { constructor(threshold?: LogLevel, formatter?: LogMessageFormatter) {
if (threshold) { if (threshold) {
@ -38,13 +27,17 @@ export class ConsoleLogAppender implements LogAppender {
let logMethod = console.log; let logMethod = console.log;
switch (msg.level) { switch (msg.level) {
case LogLevel.ALL: case LogLevel.ALL:
logMethod = console.log;
break;
case LogLevel.TRACE: case LogLevel.TRACE:
case LogLevel.LOG:
logMethod = console.log; logMethod = console.log;
break; break;
case LogLevel.DEBUG: case LogLevel.DEBUG:
logMethod = console.debug; logMethod = console.debug;
break; break;
case LogLevel.LOG:
logMethod = console.log;
break;
case LogLevel.INFO: case LogLevel.INFO:
logMethod = console.info; logMethod = console.info;
break; break;
@ -57,25 +50,12 @@ export class ConsoleLogAppender implements LogAppender {
break; break;
} }
const fmtMsg = this.formatter(msg); const strMsg = this.formatter(msg);
if (typeof fmtMsg === "string") { if (msg.error || msg.stacktrace) {
if (msg.error || msg.stacktrace) { logMethod(strMsg, msg.error ?? msg.stacktrace);
logMethod(fmtMsg, msg.error ?? msg.stacktrace);
} else {
logMethod(fmtMsg);
}
} else { } else {
const { message, _error, _stacktrace, ...rest } = fmtMsg; logMethod(strMsg);
const summary = `${LogLevel[msg.level]} -- ${msg.scope}: ${
message ?? fmtMsg.method
}\n`;
if (msg.error || msg.stacktrace) {
logMethod(summary, msg.error ?? msg.stacktrace, rest);
} else {
logMethod(summary, rest);
}
} }
} }
} }