Socket
Socket
Sign inDemoInstall

@spinajs/log

Package Overview
Dependencies
Maintainers
1
Versions
277
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@spinajs/log - npm Package Compare versions

Comparing version 1.0.5 to 1.0.7

179

lib/index.d.ts
/// <reference types="node" />
import { Writable } from 'stream';
import { Configuration } from '@spinajs/configuration';
import { ResolveStrategy } from '@spinajs/di';
import { SyncModule } from '@spinajs/di';
/**
* -----------------------------------------------------------------------------------
* IMPORTANT: log subsystem is havily based on bunyan. It uses bunyan by default, all options & functions are based on
* bunyan lib. However you can implement custom log module and inject it to framework simply by implementing
* `LogModule` that returns custom implementation of `Log` interface. Then override default DI registered class at app bootstrap.
*
* If you simply want to add more places where log goes eg. database, simply add custom log stream to configuration file.
*/
/**
* Creates child logger
*
* @param options - additional logger options
*/
export declare function Logger(options?: any): (target?: any, key?: string) => any;
/**
* Log stream that writes messages in console with proper colours for message types.
* * TRACE - gray
* * DEBUG - white
* * INFO - cyan
* * WARN - yellow
* * ERROR - red
* * FATAL - red on white background
*/
export declare class ConsoleLogStream extends Writable {

@@ -16,38 +38,191 @@ private TRACE;

}
/**
* Default log implementation interface. Taken from bunyan. Feel free to implement own.
*/
export interface Log {
/**
* Returns a boolean: is the `trace` level enabled?
*
* This is equivalent to `log.isTraceEnabled()` or `log.isEnabledFor(TRACE)` in log4j.
*/
trace(): boolean;
/**
* Special case to log an `Error` instance to the record.
* This adds an `err` field with exception details
* (including the stack) and sets `msg` to the exception
* message or you can specify the `msg`.
*/
trace(error: Error, ...params: any[]): void;
/**
* The first field can optionally be a "fields" object, which
* is merged into the log record.
*
* To pass in an Error *and* other fields, use the `err`
* field name for the Error instance.
*/
trace(obj: Object, ...params: any[]): void;
/**
* Uses `util.format` for msg formatting.
*/
trace(format: any, ...params: any[]): void;
/**
* Returns a boolean: is the `debug` level enabled?
*
* This is equivalent to `log.isDebugEnabled()` or `log.isEnabledFor(DEBUG)` in log4j.
*/
debug(): boolean;
/**
* Special case to log an `Error` instance to the record.
* This adds an `err` field with exception details
* (including the stack) and sets `msg` to the exception
* message or you can specify the `msg`.
*/
debug(error: Error, ...params: any[]): void;
/**
* The first field can optionally be a "fields" object, which
* is merged into the log record.
*
* To pass in an Error *and* other fields, use the `err`
* field name for the Error instance.
*/
debug(obj: Object, ...params: any[]): void;
/**
* Uses `util.format` for msg formatting.
*/
debug(format: any, ...params: any[]): void;
/**
* Returns a boolean: is the `info` level enabled?
*
* This is equivalent to `log.isInfoEnabled()` or `log.isEnabledFor(INFO)` in log4j.
*/
info(): boolean;
/**
* Special case to log an `Error` instance to the record.
* This adds an `err` field with exception details
* (including the stack) and sets `msg` to the exception
* message or you can specify the `msg`.
*/
info(error: Error, ...params: any[]): void;
/**
* The first field can optionally be a "fields" object, which
* is merged into the log record.
*
* To pass in an Error *and* other fields, use the `err`
* field name for the Error instance.
*/
info(obj: Object, ...params: any[]): void;
/**
* Uses `util.format` for msg formatting.
*/
info(format: any, ...params: any[]): void;
/**
* Returns a boolean: is the `warn` level enabled?
*
* This is equivalent to `log.isWarnEnabled()` or `log.isEnabledFor(WARN)` in log4j.
*/
warn(): boolean;
/**
* Special case to log an `Error` instance to the record.
* This adds an `err` field with exception details
* (including the stack) and sets `msg` to the exception
* message or you can specify the `msg`.
*/
warn(error: Error, ...params: any[]): void;
/**
* The first field can optionally be a "fields" object, which
* is merged into the log record.
*
* To pass in an Error *and* other fields, use the `err`
* field name for the Error instance.
*/
warn(obj: Object, ...params: any[]): void;
/**
* Uses `util.format` for msg formatting.
*/
warn(format: any, ...params: any[]): void;
/**
* Returns a boolean: is the `error` level enabled?
*
* This is equivalent to `log.isErrorEnabled()` or `log.isEnabledFor(ERROR)` in log4j.
*/
error(): boolean;
/**
* Special case to log an `Error` instance to the record.
* This adds an `err` field with exception details
* (including the stack) and sets `msg` to the exception
* message or you can specify the `msg`.
*/
error(error: Error, ...params: any[]): void;
/**
* The first field can optionally be a "fields" object, which
* is merged into the log record.
*
* To pass in an Error *and* other fields, use the `err`
* field name for the Error instance.
*/
error(obj: Object, ...params: any[]): void;
/**
* Uses `util.format` for msg formatting.
*/
error(format: any, ...params: any[]): void;
/**
* Returns a boolean: is the `fatal` level enabled?
*
* This is equivalent to `log.isFatalEnabled()` or `log.isEnabledFor(FATAL)` in log4j.
*/
fatal(): boolean;
/**
* Special case to log an `Error` instance to the record.
* This adds an `err` field with exception details
* (including the stack) and sets `msg` to the exception
* message or you can specify the `msg`.
*/
fatal(error: Error, ...params: any[]): void;
/**
* The first field can optionally be a "fields" object, which
* is merged into the log record.
*
* To pass in an Error *and* other fields, use the `err`
* field name for the Error instance.
*/
fatal(obj: Object, ...params: any[]): void;
/**
* Uses `util.format` for msg formatting.
*/
fatal(format: any, ...params: any[]): void;
child(options: Object, simple?: boolean): Log;
}
export declare abstract class LogModule extends ResolveStrategy {
/**
* Abstract class to implement for framework log module.
*/
export declare abstract class LogModule extends SyncModule {
abstract getLogger(options?: any[]): Log;
}
/**
* Default Log implementation that uses bunyan internally. Feel free to implement own
*/
export declare class SpinaJsDefaultLog extends LogModule {
/**
* Injected Configuration object
*/
cfg: Configuration;
/**
* root logger
* @access protected
*/
protected log: Log;
/**
* Name of module
* @access protected
*/
protected name: string;
/**
* Creates child logger
* @param options - additional logger options eg. fields.
*/
getLogger(options?: any[]): Log;
/**
* Initializes bunyan logger & hooks for process:uncaughtException to log fatal application events
*/
resolve(): void;
}
"use strict";
// tslint:disable: ban-types
// tslint:disable: interface-name
// tslint:disable: unified-signatures
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

@@ -27,5 +30,19 @@ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;

const di_1 = require("@spinajs/di");
/**
* -----------------------------------------------------------------------------------
* IMPORTANT: log subsystem is havily based on bunyan. It uses bunyan by default, all options & functions are based on
* bunyan lib. However you can implement custom log module and inject it to framework simply by implementing
* `LogModule` that returns custom implementation of `Log` interface. Then override default DI registered class at app bootstrap.
*
* If you simply want to add more places where log goes eg. database, simply add custom log stream to configuration file.
*/
/**
* Creates child logger
*
* @param options - additional logger options
*/
function Logger(options) {
return (target, key) => {
let logger;
// property getter
const getter = () => {

@@ -37,2 +54,3 @@ if (!logger) {

};
// Create new property with getter and setter
Object.defineProperty(target, key, {

@@ -46,2 +64,11 @@ get: getter,

exports.Logger = Logger;
/**
* Log stream that writes messages in console with proper colours for message types.
* * TRACE - gray
* * DEBUG - white
* * INFO - cyan
* * WARN - yellow
* * ERROR - red
* * FATAL - red on white background
*/
class ConsoleLogStream extends stream_1.Writable {

@@ -103,8 +130,18 @@ constructor() {

exports.ConsoleLogStream = ConsoleLogStream;
/**
* Default logger options
* used as fallback if no config is provided
*/
const DEFAULT_OPTIONS = {
name: 'spine-framework',
serializers: bunyan.stdSerializers,
/**
* streams to log to. See more on bunyan docs
*/
streams: [
{
type: 'raw',
/**
* We use default console log stream with colors
*/
stream: new ConsoleLogStream(),

@@ -115,15 +152,36 @@ level: process.env.NODE_ENV === 'development' ? 'trace' : 'info',

};
class LogModule extends di_1.ResolveStrategy {
/**
* Abstract class to implement for framework log module.
*/
class LogModule extends di_1.SyncModule {
}
exports.LogModule = LogModule;
/**
* Default Log implementation that uses bunyan internally. Feel free to implement own
*/
let SpinaJsDefaultLog = class SpinaJsDefaultLog extends LogModule {
constructor() {
super(...arguments);
/**
* Injected Configuration object
*/
this.cfg = null;
/**
* Name of module
* @access protected
*/
this.name = 'Log';
}
/**
* Creates child logger
* @param options - additional logger options eg. fields.
*/
getLogger(options) {
return this.log.child(options);
}
/**
* Initializes bunyan logger & hooks for process:uncaughtException to log fatal application events
*/
resolve() {
// get config
this.log = bunyan.createLogger(this.cfg.get(['log'], DEFAULT_OPTIONS));

@@ -130,0 +188,0 @@ process.on('uncaughtException', (err) => {

8

package.json
{
"name": "@spinajs/log",
"version": "1.0.5",
"version": "1.0.7",
"description": "Log lib for all spinejs related libs",

@@ -27,5 +27,5 @@ "main": "lib/index.js",

"dependencies": {
"@spinajs/configuration": "^1.0.5",
"@spinajs/di": "^1.0.3",
"@spinajs/exceptions": "^1.0.0",
"@spinajs/configuration": "^1.0.9",
"@spinajs/di": "^1.0.16",
"@spinajs/exceptions": "^1.0.3",
"bunyan": "^1.8.12",

@@ -32,0 +32,0 @@ "chalk": "^3.0.0",

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