Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

@furystack/logging

Package Overview
Dependencies
Maintainers
1
Versions
145
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@furystack/logging - npm Package Compare versions

Comparing version 1.1.7 to 2.0.0

dist/LogEntries.d.ts

40

dist/AbstractLogger.d.ts

@@ -1,3 +0,3 @@

import { ILeveledLogEntry, ILogEntry } from './ILogEntries';
import { ILogger, ILoggerOptions } from './ILogger';
import { LeveledLogEntry, LogEntry } from './LogEntries';
import { Logger } from './Logger';
/**

@@ -8,11 +8,5 @@ * Default scope key for the Abstract Logger

/**
* default options for a logger instance
*/
export declare const defaultLoggerOptions: ILoggerOptions;
/**
* Abstract logger instance
*/
export declare abstract class AbstractLogger<TOptions extends ILoggerOptions = ILoggerOptions> implements ILogger {
readonly options: TOptions;
constructor(options?: Partial<ILoggerOptions>);
export declare abstract class AbstractLogger implements Logger {
/**

@@ -22,3 +16,3 @@ * Adds a new log entry to the logger

*/
abstract addEntry<T>(entry: ILeveledLogEntry<T>): Promise<void>;
abstract addEntry<T>(entry: LeveledLogEntry<T>): Promise<void>;
private addEntryInternal;

@@ -29,3 +23,3 @@ /**

*/
verbose<T>(entry: ILogEntry<T>): Promise<void>;
verbose<T>(entry: LogEntry<T>): Promise<void>;
/**

@@ -35,3 +29,3 @@ * Adds a Debug level log entry. Debug is used for internal system events that are not necessarily observable from the outside, but useful when determining how something happened.

*/
debug<T>(entry: ILogEntry<T>): Promise<void>;
debug<T>(entry: LogEntry<T>): Promise<void>;
/**

@@ -41,3 +35,3 @@ * Adds an Information level log entry. Information events describe things happening in the system that correspond to its responsibilities and functions. Generally these are the observable actions the system can perform.

*/
information<T>(entry: ILogEntry<T>): Promise<void>;
information<T>(entry: LogEntry<T>): Promise<void>;
/**

@@ -47,3 +41,3 @@ * Adds a Warning level log entry. When service is degraded, endangered, or may be behaving outside of its expected parameters, Warning level events are used.

*/
warning<T>(entry: ILogEntry<T>): Promise<void>;
warning<T>(entry: LogEntry<T>): Promise<void>;
/**

@@ -53,3 +47,3 @@ * Adds an Error level log entry. When functionality is unavailable or expectations broken, an Error event is used.

*/
error<T>(entry: ILogEntry<T>): Promise<void>;
error<T>(entry: LogEntry<T>): Promise<void>;
/**

@@ -59,3 +53,3 @@ * Adds a Fatal level log entry. The most critical level, Fatal events demand immediate attention.

*/
fatal<T>(entry: ILogEntry<T>): Promise<void>;
fatal<T>(entry: LogEntry<T>): Promise<void>;
/**

@@ -73,29 +67,29 @@ * Returns an object that contains shortcuts to the original logger that contains the provided scope.

*/
addEntry: <T>(entry: ILeveledLogEntry<T>) => Promise<void>;
addEntry: <T>(entry: LeveledLogEntry<T>) => Promise<void>;
/**
* Adds a Verbose log entry. Verbose is the noisiest level, rarely (if ever) enabled for a production app.
*/
verbose: <T>(entry: ILogEntry<T>) => Promise<void>;
verbose: <T>(entry: LogEntry<T>) => Promise<void>;
/**
* Adds a debug log entry. Debug is used for internal system events that are not necessarily observable from the outside, but useful when determining how something happened.
*/
debug: <T>(entry: ILogEntry<T>) => Promise<void>;
debug: <T>(entry: LogEntry<T>) => Promise<void>;
/**
* Adds an Information log entry. Information events describe things happening in the system that correspond to its responsibilities and functions. Generally these are the observable actions the system can perform.
*/
information: <T>(entry: ILogEntry<T>) => Promise<void>;
information: <T>(entry: LogEntry<T>) => Promise<void>;
/**
* Adds a Warning log entry. When service is degraded, endangered, or may be behaving outside of its expected parameters, Warning level events are used.
*/
warning: <T>(entry: ILogEntry<T>) => Promise<void>;
warning: <T>(entry: LogEntry<T>) => Promise<void>;
/**
* Adds an Error log entry. When functionality is unavailable or expectations broken, an Error event is used.
*/
error: <T>(entry: ILogEntry<T>) => Promise<void>;
error: <T>(entry: LogEntry<T>) => Promise<void>;
/**
* Adds a Fatal log entry. The most critical level, Fatal events demand immediate attention.
*/
fatal: <T>(entry: ILogEntry<T>) => Promise<void>;
fatal: <T>(entry: LogEntry<T>) => Promise<void>;
};
}
//# sourceMappingURL=AbstractLogger.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ILogEntries_1 = require("./ILogEntries");
const LogEntries_1 = require("./LogEntries");
/**

@@ -9,12 +9,6 @@ * Default scope key for the Abstract Logger

/**
* default options for a logger instance
*/
exports.defaultLoggerOptions = {
filter: () => true,
};
/**
* Abstract logger instance
*/
class AbstractLogger {
constructor(options) {
constructor() {
/**

@@ -58,11 +52,4 @@ * Returns an object that contains shortcuts to the original logger that contains the provided scope.

});
this.options = {
...exports.defaultLoggerOptions,
...options,
};
}
async addEntryInternal(entry) {
if (!this.options.filter(entry)) {
return;
}
try {

@@ -89,3 +76,3 @@ await this.addEntry(entry);

...entry,
level: ILogEntries_1.LogLevel.Verbose,
level: LogEntries_1.LogLevel.Verbose,
});

@@ -100,3 +87,3 @@ }

...entry,
level: ILogEntries_1.LogLevel.Debug,
level: LogEntries_1.LogLevel.Debug,
});

@@ -111,3 +98,3 @@ }

...entry,
level: ILogEntries_1.LogLevel.Information,
level: LogEntries_1.LogLevel.Information,
});

@@ -122,3 +109,3 @@ }

...entry,
level: ILogEntries_1.LogLevel.Warning,
level: LogEntries_1.LogLevel.Warning,
});

@@ -134,3 +121,3 @@ }

...entry,
level: ILogEntries_1.LogLevel.Error,
level: LogEntries_1.LogLevel.Error,
});

@@ -156,3 +143,3 @@ }

...entry,
level: ILogEntries_1.LogLevel.Fatal,
level: LogEntries_1.LogLevel.Fatal,
});

@@ -159,0 +146,0 @@ }

import { AbstractLogger } from './AbstractLogger';
import { ILeveledLogEntry, LogLevel } from './ILogEntries';
import { ILoggerOptions } from './ILogger';
import { LeveledLogEntry, LogLevel } from './LogEntries';
/**

@@ -49,3 +48,3 @@ * Resets the console color

*/
export declare const defaultFormatter: <T>(entry: ILeveledLogEntry<T>) => (string | undefined)[];
export declare const defaultFormatter: <T>(entry: LeveledLogEntry<T>) => (string | undefined)[];
/**

@@ -55,17 +54,12 @@ * Formatter for a verbose message

*/
export declare const verboseFormatter: <T>(entry: ILeveledLogEntry<T>) => (string | T | undefined)[];
export declare const verboseFormatter: <T>(entry: LeveledLogEntry<T>) => (string | T | undefined)[];
/**
* Options for a Console Logger instance
*/
export interface IConsoleLoggerOptions extends ILoggerOptions {
formatter: <T>(entry: ILeveledLogEntry<T>) => any[];
}
/**
* A logger implementation that dumps log messages to the console
*/
export declare class ConsoleLogger extends AbstractLogger<IConsoleLoggerOptions> {
readonly options: IConsoleLoggerOptions;
constructor();
addEntry<T>(entry: ILeveledLogEntry<T>): Promise<void>;
export declare class ConsoleLogger extends AbstractLogger {
addEntry<T>(entry: LeveledLogEntry<T>): Promise<void>;
}
export declare class VerboseConsoleLogger extends AbstractLogger {
addEntry<T>(entry: LeveledLogEntry<T>): Promise<void>;
}
//# sourceMappingURL=ConsoleLogger.d.ts.map

@@ -6,3 +6,3 @@ "use strict";

const AbstractLogger_1 = require("./AbstractLogger");
const ILogEntries_1 = require("./ILogEntries");
const LogEntries_1 = require("./LogEntries");
/**

@@ -50,11 +50,11 @@ * Resets the console color

switch (level) {
case ILogEntries_1.LogLevel.Verbose:
case ILogEntries_1.LogLevel.Debug:
case LogEntries_1.LogLevel.Verbose:
case LogEntries_1.LogLevel.Debug:
return exports.FgBlue;
case ILogEntries_1.LogLevel.Information:
case LogEntries_1.LogLevel.Information:
return exports.FgGreen;
case ILogEntries_1.LogLevel.Warning:
case LogEntries_1.LogLevel.Warning:
return exports.FgYellow;
case ILogEntries_1.LogLevel.Error:
case ILogEntries_1.LogLevel.Fatal:
case LogEntries_1.LogLevel.Error:
default:
return exports.FgRed;

@@ -85,12 +85,4 @@ }

let ConsoleLogger = class ConsoleLogger extends AbstractLogger_1.AbstractLogger {
constructor() {
super();
this.options = {
...AbstractLogger_1.defaultLoggerOptions,
formatter: exports.defaultFormatter,
};
}
async addEntry(entry) {
const data = this.options.formatter(entry);
// tslint:disable-next-line:no-console
const data = exports.defaultFormatter(entry);
console.log(...data);

@@ -100,6 +92,15 @@ }

ConsoleLogger = tslib_1.__decorate([
inject_1.Injectable({ lifetime: 'scoped' }),
tslib_1.__metadata("design:paramtypes", [])
inject_1.Injectable({ lifetime: 'scoped' })
], ConsoleLogger);
exports.ConsoleLogger = ConsoleLogger;
let VerboseConsoleLogger = class VerboseConsoleLogger extends AbstractLogger_1.AbstractLogger {
async addEntry(entry) {
const data = exports.verboseFormatter(entry);
console.log(...data);
}
};
VerboseConsoleLogger = tslib_1.__decorate([
inject_1.Injectable({ lifetime: 'scoped' })
], VerboseConsoleLogger);
exports.VerboseConsoleLogger = VerboseConsoleLogger;
//# sourceMappingURL=ConsoleLogger.js.map

@@ -5,5 +5,5 @@ export * from './AbstractLogger';

export * from './LoggerCollection';
export * from './ILogger';
export * from './ILogEntries';
export * from './Logger';
export * from './LogEntries';
import './InjectorExtension';
//# sourceMappingURL=index.d.ts.map

@@ -8,4 +8,4 @@ "use strict";

tslib_1.__exportStar(require("./LoggerCollection"), exports);
tslib_1.__exportStar(require("./ILogEntries"), exports);
tslib_1.__exportStar(require("./LogEntries"), exports);
require("./InjectorExtension");
//# sourceMappingURL=index.js.map
import { Constructable } from '@furystack/inject';
import { ILogger } from './ILogger';
import { Logger } from './Logger';
declare module '@furystack/inject/dist/Injector' {

@@ -11,9 +11,9 @@ /**

*/
useLogging: (...loggers: Array<Constructable<ILogger>>) => Injector;
useLogging: (...loggers: Array<Constructable<Logger>>) => Injector;
/**
* Returns the registered Logger instance
*/
readonly logger: ILogger;
readonly logger: Logger;
}
}
//# sourceMappingURL=InjectorExtension.d.ts.map

@@ -14,3 +14,3 @@ "use strict";

// tslint:disable-next-line: object-literal-shorthand
get: function () {
get() {
return this.getInstance(LoggerCollection_1.LoggerCollection);

@@ -17,0 +17,0 @@ },

import { AbstractLogger } from './AbstractLogger';
import { ILeveledLogEntry } from './ILogEntries';
import { ILogger } from './ILogger';
import { LeveledLogEntry } from './LogEntries';
import { Logger } from './Logger';
/**

@@ -8,6 +8,6 @@ * A specific logger that forwards its messages to a collection of loggers

export declare class LoggerCollection extends AbstractLogger {
addEntry<T>(entry: ILeveledLogEntry<T>): Promise<void>;
addEntry<T>(entry: LeveledLogEntry<T>): Promise<void>;
private loggers;
attachLogger(...loggers: ILogger[]): void;
attachLogger(...loggers: Logger[]): void;
}
//# sourceMappingURL=LoggerCollection.d.ts.map

@@ -18,3 +18,3 @@ "use strict";

async addEntry(entry) {
const promises = this.loggers.filter(l => l.options.filter(entry)).map(l => l.addEntry(entry));
const promises = this.loggers.map(l => l.addEntry(entry));
await Promise.all(promises);

@@ -21,0 +21,0 @@ }

import { AbstractLogger } from './AbstractLogger';
import { ILeveledLogEntry } from './ILogEntries';
import { ILoggerOptions } from './ILogger';
import { LeveledLogEntry } from './LogEntries';
/**

@@ -9,5 +8,5 @@ * A test logger instance with a callback for added events

private readonly onAddEntry;
constructor(onAddEntry: <T>(entry: ILeveledLogEntry<T>) => Promise<void>, options?: Partial<ILoggerOptions>);
addEntry<T>(entry: ILeveledLogEntry<T>): Promise<void>;
constructor(onAddEntry: <T>(entry: LeveledLogEntry<T>) => Promise<void>);
addEntry<T>(entry: LeveledLogEntry<T>): Promise<void>;
}
//# sourceMappingURL=TestLogger.d.ts.map

@@ -8,4 +8,4 @@ "use strict";

class TestLogger extends AbstractLogger_1.AbstractLogger {
constructor(onAddEntry, options) {
super(options);
constructor(onAddEntry) {
super();
this.onAddEntry = onAddEntry;

@@ -12,0 +12,0 @@ }

{
"name": "@furystack/logging",
"version": "1.1.7",
"version": "2.0.0",
"description": "Logging API for FuryStack package",

@@ -45,3 +45,3 @@ "main": "dist/index.js",

"dependencies": {
"@furystack/inject": "^3.0.8"
"@furystack/inject": "^4.0.0"
},

@@ -54,3 +54,3 @@ "config": {

"typings": "./dist/index.d.ts",
"gitHead": "d6391577488cbe5410f76881689a9f0cba7bbcef"
"gitHead": "f990a9bf0adf05b3bcbf307e1191be5b8ebb7c6b"
}

@@ -1,3 +0,3 @@

import { ILeveledLogEntry, ILogEntry, LogLevel } from './ILogEntries'
import { ILogger, ILoggerOptions, LeveledLogEntryWithoutScope, LogEntryWithoutScope } from './ILogger'
import { LeveledLogEntry, LogEntry, LogLevel } from './LogEntries'
import { Logger, LeveledLogEntryWithoutScope, LogEntryWithoutScope } from './Logger'

@@ -10,20 +10,5 @@ /**

/**
* default options for a logger instance
*/
export const defaultLoggerOptions: ILoggerOptions = {
filter: () => true,
}
/**
* Abstract logger instance
*/
export abstract class AbstractLogger<TOptions extends ILoggerOptions = ILoggerOptions> implements ILogger {
public readonly options: TOptions
constructor(options?: Partial<ILoggerOptions>) {
this.options = {
...defaultLoggerOptions,
...options,
} as TOptions
}
export abstract class AbstractLogger implements Logger {
/**

@@ -33,7 +18,4 @@ * Adds a new log entry to the logger

*/
public abstract addEntry<T>(entry: ILeveledLogEntry<T>): Promise<void>
private async addEntryInternal<T>(entry: ILeveledLogEntry<T>) {
if (!this.options.filter(entry)) {
return
}
public abstract addEntry<T>(entry: LeveledLogEntry<T>): Promise<void>
private async addEntryInternal<T>(entry: LeveledLogEntry<T>) {
try {

@@ -57,3 +39,3 @@ await this.addEntry(entry)

*/
public async verbose<T>(entry: ILogEntry<T>) {
public async verbose<T>(entry: LogEntry<T>) {
await this.addEntryInternal({

@@ -69,3 +51,3 @@ ...entry,

*/
public async debug<T>(entry: ILogEntry<T>) {
public async debug<T>(entry: LogEntry<T>) {
await this.addEntryInternal({

@@ -81,3 +63,3 @@ ...entry,

*/
public async information<T>(entry: ILogEntry<T>) {
public async information<T>(entry: LogEntry<T>) {
await this.addEntryInternal({

@@ -93,3 +75,3 @@ ...entry,

*/
public async warning<T>(entry: ILogEntry<T>) {
public async warning<T>(entry: LogEntry<T>) {
await this.addEntryInternal({

@@ -105,3 +87,3 @@ ...entry,

*/
public async error<T>(entry: ILogEntry<T>) {
public async error<T>(entry: LogEntry<T>) {
try {

@@ -129,3 +111,3 @@ await this.addEntry({

*/
public async fatal<T>(entry: ILogEntry<T>) {
public async fatal<T>(entry: LogEntry<T>) {
await this.addEntry({

@@ -132,0 +114,0 @@ ...entry,

import { Injectable } from '@furystack/inject'
import { AbstractLogger, defaultLoggerOptions } from './AbstractLogger'
import { ILeveledLogEntry, LogLevel } from './ILogEntries'
import { ILoggerOptions } from './ILogger'
import { AbstractLogger } from './AbstractLogger'
import { LeveledLogEntry, LogLevel } from './LogEntries'

@@ -60,3 +59,3 @@ /**

case LogLevel.Error:
case LogLevel.Fatal:
default:
return FgRed

@@ -70,3 +69,3 @@ }

*/
export const defaultFormatter = <T>(entry: ILeveledLogEntry<T>) => {
export const defaultFormatter = <T>(entry: LeveledLogEntry<T>) => {
const fontColor = getLevelColor(entry.level)

@@ -80,3 +79,3 @@ return [`${fontColor}%s${Reset}`, entry.scope, entry.message]

*/
export const verboseFormatter = <T>(entry: ILeveledLogEntry<T>) => {
export const verboseFormatter = <T>(entry: LeveledLogEntry<T>) => {
const fontColor = getLevelColor(entry.level)

@@ -89,25 +88,18 @@ return entry.data

/**
* Options for a Console Logger instance
* A logger implementation that dumps log messages to the console
*/
export interface IConsoleLoggerOptions extends ILoggerOptions {
formatter: <T>(entry: ILeveledLogEntry<T>) => any[]
@Injectable({ lifetime: 'scoped' })
export class ConsoleLogger extends AbstractLogger {
public async addEntry<T>(entry: LeveledLogEntry<T>) {
const data = defaultFormatter(entry)
console.log(...data)
}
}
/**
* A logger implementation that dumps log messages to the console
*/
@Injectable({ lifetime: 'scoped' })
export class ConsoleLogger extends AbstractLogger<IConsoleLoggerOptions> {
public readonly options: IConsoleLoggerOptions = {
...defaultLoggerOptions,
formatter: defaultFormatter,
}
constructor() {
super()
}
public async addEntry<T>(entry: ILeveledLogEntry<T>) {
const data = this.options.formatter(entry)
// tslint:disable-next-line:no-console
export class VerboseConsoleLogger extends AbstractLogger {
public async addEntry<T>(entry: LeveledLogEntry<T>) {
const data = verboseFormatter(entry)
console.log(...data)
}
}

@@ -5,4 +5,4 @@ export * from './AbstractLogger'

export * from './LoggerCollection'
export * from './ILogger'
export * from './ILogEntries'
export * from './Logger'
export * from './LogEntries'
import './InjectorExtension'
import { Constructable } from '@furystack/inject'
import { Injector } from '@furystack/inject/dist/Injector'
import { ILogger } from './ILogger'
import { Logger } from './Logger'
import { LoggerCollection } from './LoggerCollection'

@@ -15,3 +15,3 @@

*/
useLogging: (...loggers: Array<Constructable<ILogger>>) => Injector
useLogging: (...loggers: Array<Constructable<Logger>>) => Injector

@@ -21,3 +21,3 @@ /**

*/
readonly logger: ILogger
readonly logger: Logger
}

@@ -36,5 +36,5 @@ }

// tslint:disable-next-line: object-literal-shorthand
get: function() {
get() {
return this.getInstance(LoggerCollection)
},
})
import { Injectable } from '@furystack/inject'
import { AbstractLogger } from './AbstractLogger'
import { ILeveledLogEntry } from './ILogEntries'
import { ILogger } from './ILogger'
import { LeveledLogEntry } from './LogEntries'
import { Logger } from './Logger'

@@ -11,11 +11,11 @@ /**

export class LoggerCollection extends AbstractLogger {
public async addEntry<T>(entry: ILeveledLogEntry<T>): Promise<void> {
const promises = this.loggers.filter(l => l.options.filter(entry)).map(l => l.addEntry(entry))
public async addEntry<T>(entry: LeveledLogEntry<T>): Promise<void> {
const promises = this.loggers.map(l => l.addEntry(entry))
await Promise.all(promises)
}
private loggers: ILogger[] = []
public attachLogger(...loggers: ILogger[]) {
private loggers: Logger[] = []
public attachLogger(...loggers: Logger[]) {
this.loggers.push(...loggers)
}
}
import { AbstractLogger } from './AbstractLogger'
import { ILeveledLogEntry } from './ILogEntries'
import { ILoggerOptions } from './ILogger'
import { LeveledLogEntry } from './LogEntries'

@@ -9,11 +8,9 @@ /**

export class TestLogger extends AbstractLogger {
constructor(
private readonly onAddEntry: <T>(entry: ILeveledLogEntry<T>) => Promise<void>,
options?: Partial<ILoggerOptions>,
) {
super(options)
constructor(private readonly onAddEntry: <T>(entry: LeveledLogEntry<T>) => Promise<void>) {
super()
}
public async addEntry<T>(entry: ILeveledLogEntry<T>): Promise<void> {
public async addEntry<T>(entry: LeveledLogEntry<T>): Promise<void> {
await this.onAddEntry(entry)
}
}

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc