@dxos/log
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -22,3 +22,3 @@ import { LogConfig, LogLevel } from './config'; | ||
message: string; | ||
ctx?: LogContext; | ||
context?: LogContext; | ||
meta?: LogMetadata; | ||
@@ -25,0 +25,0 @@ error?: Error; |
@@ -6,3 +6,3 @@ import { LogOptions } from './config'; | ||
*/ | ||
declare type Logger = (message: string, ctx?: LogContext, meta?: LogMetadata) => void; | ||
declare type Logger = (message: string, context?: LogContext, meta?: LogMetadata) => void; | ||
/** | ||
@@ -17,3 +17,3 @@ * Properties accessible on the logging function. | ||
error: Logger; | ||
catch: (error: Error, ctx?: LogContext, meta?: LogMetadata) => void; | ||
catch: (error: Error, context?: LogContext, meta?: LogMetadata) => void; | ||
} | ||
@@ -20,0 +20,0 @@ /** |
@@ -22,11 +22,11 @@ "use strict"; | ||
// TODO(burdon): Option to display/hide stack. | ||
log.catch = (error, ctx, meta) => processLog(config_1.LogLevel.ERROR, String(error.stack), ctx, meta, error); | ||
log.catch = (error, context, meta) => processLog(config_1.LogLevel.ERROR, String(error.stack), context, meta, error); | ||
/** | ||
* Process the current log call. | ||
*/ | ||
const processLog = (level, message, ctx, meta, error) => { | ||
const processLog = (level, message, context, meta, error) => { | ||
log._config.processor(log._config, { | ||
level, | ||
message, | ||
ctx, | ||
context, | ||
meta, | ||
@@ -33,0 +33,0 @@ error |
@@ -29,14 +29,17 @@ "use strict"; | ||
args.push(`${config_1.shortLevelName[entry.level]} ${entry.message}`); | ||
if (entry.ctx && Object.keys(entry.ctx).length > 0) { | ||
args.push(entry.ctx); | ||
if (entry.context && Object.keys(entry.context).length > 0) { | ||
args.push(entry.context); | ||
} | ||
switch (entry.level) { | ||
case config_1.LogLevel.ERROR: | ||
case config_1.LogLevel.ERROR: { | ||
console.error(...args); | ||
break; | ||
case config_1.LogLevel.WARN: | ||
} | ||
case config_1.LogLevel.WARN: { | ||
console.warn(...args); | ||
break; | ||
default: | ||
} | ||
default: { | ||
console.log(...args); | ||
} | ||
} | ||
@@ -43,0 +46,0 @@ }; |
@@ -9,3 +9,4 @@ import { LogConfig, LogLevel } from '../config'; | ||
message: string; | ||
context?: string; | ||
context?: any; | ||
error?: Error; | ||
}; | ||
@@ -12,0 +13,0 @@ export declare type Formatter = (config: LogConfig, parts: FormatParts) => (string | undefined)[]; |
@@ -35,15 +35,15 @@ "use strict"; | ||
}; | ||
const DEFAULT_FORMATTER = (config, { path, line, level, message, context }) => { | ||
const DEFAULT_FORMATTER = (config, { path, line, level, message, context, error }) => { | ||
var _a, _b; | ||
const column = (_b = (_a = config.options) === null || _a === void 0 ? void 0 : _a.formatter) === null || _b === void 0 ? void 0 : _b.column; | ||
const filepath = `${path}:${line}`; | ||
const filepath = path !== undefined && line !== undefined ? chalk_1.default.grey(`${path}:${line}`) : undefined; | ||
return [ | ||
// NOTE: File path must come fist for console hyperlinks. | ||
path !== undefined && line !== undefined ? chalk_1.default.grey(filepath) : undefined, | ||
column ? ''.padStart(column - filepath.length) : undefined, | ||
// Must not truncate for terminal output. | ||
filepath, | ||
column && filepath ? ''.padStart(column - filepath.length) : undefined, | ||
chalk_1.default[LEVEL_COLORS[level]](column ? config_1.shortLevelName[level] : config_1.LogLevel[level]), | ||
message, | ||
// NOTE: Must not stringify. | ||
// TODO(burdon): Substitutions (e.g., replace buffer contents with length?) | ||
context | ||
context, | ||
error | ||
]; | ||
@@ -61,20 +61,19 @@ }; | ||
const CONSOLE_PROCESSOR = (config, entry) => { | ||
var _a, _b; | ||
if (!(0, context_1.shouldLog)(config, entry.level, (_b = (_a = entry.meta) === null || _a === void 0 ? void 0 : _a.file) !== null && _b !== void 0 ? _b : '')) { | ||
var _a; | ||
const { level, message, context, meta, error } = entry; | ||
if (!(0, context_1.shouldLog)(config, level, (_a = meta === null || meta === void 0 ? void 0 : meta.file) !== null && _a !== void 0 ? _a : '')) { | ||
return; | ||
} | ||
const parts = { | ||
level: entry.level, | ||
message: entry.message | ||
}; | ||
if (entry.meta) { | ||
parts.path = getRelativeFilename(entry.meta.file); | ||
parts.line = entry.meta.line; | ||
const parts = { level, message, error }; | ||
if (meta) { | ||
parts.path = getRelativeFilename(meta.file); | ||
parts.line = meta.line; | ||
} | ||
if (entry.ctx && Object.keys(entry.ctx).length > 0) { | ||
parts.context = (0, node_util_1.inspect)(entry.ctx, false, undefined, true); | ||
if ((context && Object.keys(context).length > 0) || context instanceof Error) { | ||
parts.context = (0, node_util_1.inspect)(context, false, undefined, true); | ||
} | ||
console.log(formatter(config, parts).filter(Boolean).join(' ')); | ||
const line = formatter(config, parts).filter(Boolean).join(' '); | ||
console.log(line); | ||
}; | ||
exports.CONSOLE_PROCESSOR = CONSOLE_PROCESSOR; | ||
//# sourceMappingURL=console-processor.js.map |
{ | ||
"name": "@dxos/log", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Logger", | ||
@@ -5,0 +5,0 @@ "homepage": "https://dxos.org", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68884
1328