@dxos/log
Advanced tools
Comparing version 0.1.9 to 0.1.10
@@ -28,3 +28,3 @@ import { LogProcessor } from './context'; | ||
*/ | ||
export declare type LogFilter = { | ||
export type LogFilter = { | ||
level: LogLevel; | ||
@@ -36,3 +36,3 @@ pattern?: string; | ||
*/ | ||
export declare type LogOptions = { | ||
export type LogOptions = { | ||
file?: string; | ||
@@ -39,0 +39,0 @@ filter?: string | string[] | LogLevel; |
import { LogConfig, LogLevel } from './config'; | ||
import { OwnershipScope } from './ownership'; | ||
/** | ||
* Optional object passed to the logging API. | ||
*/ | ||
export declare type LogContext = Record<string, any> | Error | any; | ||
export type LogContext = Record<string, any> | Error | any; | ||
/** | ||
@@ -13,3 +12,7 @@ * Generated meta data from source map. | ||
line: number; | ||
ownershipScope: OwnershipScope | undefined; | ||
/** | ||
* Value of `this` at the site of the log call. | ||
* Will be set to the class instance if the call is inside a method, or to the `globalThis` (`window` or `global`) otherwise. | ||
*/ | ||
scope: any | undefined; | ||
bugcheck?: string; | ||
@@ -30,3 +33,3 @@ } | ||
*/ | ||
export declare type LogProcessor = (config: LogConfig, entry: LogEntry) => void; | ||
export type LogProcessor = (config: LogConfig, entry: LogEntry) => void; | ||
/** | ||
@@ -33,0 +36,0 @@ * Determines if the current line should be logged (called by the processor). |
@@ -5,3 +5,4 @@ export * from './config'; | ||
export * from './processors'; | ||
export { getCurrentOwnershipScope } from './ownership'; | ||
export * from './scope'; | ||
export { getCurrentOwnershipScope } from './experimental/ownership'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -25,4 +25,5 @@ "use strict"; | ||
__exportStar(require("./processors"), exports); | ||
var ownership_1 = require("./ownership"); | ||
__exportStar(require("./scope"), exports); | ||
var ownership_1 = require("./experimental/ownership"); | ||
Object.defineProperty(exports, "getCurrentOwnershipScope", { enumerable: true, get: function () { return ownership_1.getCurrentOwnershipScope; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -6,3 +6,3 @@ import { LogOptions } from './config'; | ||
*/ | ||
declare type Logger = (message: string, context?: LogContext, meta?: LogMetadata) => void; | ||
type Logger = (message: string, context?: LogContext, meta?: LogMetadata) => void; | ||
/** | ||
@@ -9,0 +9,0 @@ * Properties accessible on the logging function. |
import { LogConfig, LogLevel } from '../config'; | ||
import { LogProcessor } from '../context'; | ||
export declare const truncate: (text?: string, length?: number, right?: boolean) => string; | ||
export declare type FormatParts = { | ||
export type FormatParts = { | ||
path?: string; | ||
@@ -12,3 +12,3 @@ line?: number; | ||
}; | ||
export declare type Formatter = (config: LogConfig, parts: FormatParts) => (string | undefined)[]; | ||
export type Formatter = (config: LogConfig, parts: FormatParts) => (string | undefined)[]; | ||
export declare const DEFAULT_FORMATTER: Formatter; | ||
@@ -15,0 +15,0 @@ export declare const SHORT_FORMATTER: Formatter; |
@@ -15,2 +15,3 @@ "use strict"; | ||
const context_1 = require("../context"); | ||
const scope_1 = require("../scope"); | ||
const LEVEL_COLORS = { | ||
@@ -63,3 +64,3 @@ [config_1.LogLevel.DEBUG]: 'gray', | ||
var _a; | ||
const { level, message, context, meta, error } = entry; | ||
let { 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 : '')) { | ||
@@ -72,2 +73,7 @@ return; | ||
parts.line = meta.line; | ||
// TODO(dmaretskyi): Add the same to the browser-processor. | ||
const scopeInfo = (0, scope_1.gatherLogInfoFromScope)(meta.scope); | ||
if (Object.keys(scopeInfo).length > 0) { | ||
context = Object.assign(context !== null && context !== void 0 ? context : {}, scopeInfo); | ||
} | ||
} | ||
@@ -74,0 +80,0 @@ if (context instanceof Error) { |
{ | ||
"name": "@dxos/log", | ||
"version": "0.1.9", | ||
"version": "0.1.10", | ||
"description": "Logger", | ||
@@ -5,0 +5,0 @@ "homepage": "https://dxos.org", |
@@ -6,3 +6,2 @@ // | ||
import { LogConfig, LogFilter, LogLevel } from './config'; | ||
import { OwnershipScope } from './ownership'; | ||
@@ -21,4 +20,7 @@ /** | ||
// TODO(burdon): Document. | ||
ownershipScope: OwnershipScope | undefined; | ||
/** | ||
* Value of `this` at the site of the log call. | ||
* Will be set to the class instance if the call is inside a method, or to the `globalThis` (`window` or `global`) otherwise. | ||
*/ | ||
scope: any | undefined; | ||
@@ -25,0 +27,0 @@ // Useful for pre-processor hook debugging. |
@@ -9,3 +9,4 @@ // | ||
export * from './processors'; | ||
export * from './scope'; | ||
export { getCurrentOwnershipScope } from './ownership'; | ||
export { getCurrentOwnershipScope } from './experimental/ownership'; |
@@ -5,3 +5,3 @@ // | ||
import { LogOptions, LogConfig, LogLevel } from './config'; | ||
import { LogConfig, LogLevel, LogOptions } from './config'; | ||
import { LogContext, LogMetadata } from './context'; | ||
@@ -8,0 +8,0 @@ import { getConfig } from './options'; |
@@ -11,2 +11,3 @@ // | ||
import { LogProcessor, shouldLog } from '../context'; | ||
import { gatherLogInfoFromScope } from '../scope'; | ||
@@ -78,3 +79,3 @@ const LEVEL_COLORS: Record<LogLevel, typeof chalk.ForegroundColor> = { | ||
export const CONSOLE_PROCESSOR: LogProcessor = (config, entry) => { | ||
const { level, message, context, meta, error } = entry; | ||
let { level, message, context, meta, error } = entry; | ||
if (!shouldLog(config, level, meta?.file ?? '')) { | ||
@@ -89,2 +90,8 @@ return; | ||
parts.line = meta.line; | ||
// TODO(dmaretskyi): Add the same to the browser-processor. | ||
const scopeInfo = gatherLogInfoFromScope(meta.scope); | ||
if (Object.keys(scopeInfo).length > 0) { | ||
context = Object.assign(context ?? {}, scopeInfo); | ||
} | ||
} | ||
@@ -91,0 +98,0 @@ |
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
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
82402
88
1565