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

@spinajs/log

Package Overview
Dependencies
Maintainers
1
Versions
288
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.10 to 1.1.0

lib/decorators.d.ts

232

lib/index.d.ts

@@ -1,227 +0,5 @@

/// <reference types="node" />
import { Writable } from "stream";
import { Configuration } from "@spinajs/configuration";
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 {
private TRACE;
private DEBUG;
private INFO;
private WARN;
private ERROR;
private FATAL;
write(chunk: any): boolean;
private _getNameFromType;
}
/**
* 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;
}
/**
* 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;
}
export * from "./types";
export * from "./targets";
export * from "./variables";
export * from "./log";
export * from "./decorators";
"use strict";
// tslint:disable: ban-types
// tslint:disable: interface-name
// tslint:disable: unified-signatures
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {

@@ -12,201 +9,11 @@ if (k2 === undefined) k2 = k;

}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SpinaJsDefaultLog = exports.LogModule = exports.ConsoleLogStream = exports.Logger = void 0;
const bunyan = __importStar(require("bunyan"));
const chalk_1 = __importDefault(require("chalk"));
const stream_1 = require("stream");
const configuration_1 = require("@spinajs/configuration");
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 = () => {
if (!logger) {
logger = di_1.DI.get("LogModule").getLogger(options);
}
return logger;
};
// Create new property with getter and setter
Object.defineProperty(target, key, {
get: getter,
enumerable: false,
configurable: false
});
};
}
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 {
constructor() {
super(...arguments);
this.TRACE = 10;
this.DEBUG = 20;
this.INFO = 30;
this.WARN = 40;
this.ERROR = 50;
this.FATAL = 60;
}
write(chunk) {
const type = this._getNameFromType(chunk.level);
const err = chunk.err
? `Exception: ${chunk.err.name}, ${chunk.err.message}, ${chunk.err.stack}`
: "";
const message = `${chunk.time.toISOString()} ${type} ${chunk.name}: ${chunk.msg} (module=${chunk.module}) ${err}`;
let c = null;
switch (chunk.level) {
case this.TRACE:
c = chalk_1.default.gray(message);
break;
case this.DEBUG:
c = chalk_1.default.white(message);
break;
case this.INFO:
c = chalk_1.default.cyan(message);
break;
case this.WARN:
c = chalk_1.default.yellow(message);
break;
case this.ERROR:
c = chalk_1.default.red(message);
break;
case this.FATAL:
c = chalk_1.default.bgRed.white(message);
break;
}
console.log(c);
return true;
}
_getNameFromType(type) {
switch (type) {
case this.TRACE:
return "TRACE";
case this.DEBUG:
return "DEBUG";
case this.INFO:
return "INFO";
case this.WARN:
return "WARN";
case this.ERROR:
return "ERROR";
case this.FATAL:
return "FATAL";
}
}
}
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(),
level: process.env.NODE_ENV === "development" ? "trace" : "info"
}
]
};
/**
* 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));
process.on("uncaughtException", (err) => {
this.log.fatal(err);
});
}
};
__decorate([
di_1.Autoinject(),
__metadata("design:type", configuration_1.Configuration)
], SpinaJsDefaultLog.prototype, "cfg", void 0);
SpinaJsDefaultLog = __decorate([
di_1.Injectable(LogModule)
], SpinaJsDefaultLog);
exports.SpinaJsDefaultLog = SpinaJsDefaultLog;
__exportStar(require("./types"), exports);
__exportStar(require("./targets"), exports);
__exportStar(require("./variables"), exports);
__exportStar(require("./log"), exports);
__exportStar(require("./decorators"), exports);
//# sourceMappingURL=index.js.map
{
"name": "@spinajs/log",
"version": "1.0.10",
"version": "1.1.0",
"description": "Log lib for all spinejs related libs",

@@ -12,2 +12,3 @@ "main": "lib/index.js",

"build": "tsc",
"build-watch": "tsc -w",
"prepare": "npm run build",

@@ -28,8 +29,12 @@ "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",

"dependencies": {
"@spinajs/configuration": "^1.0.9",
"@spinajs/di": "^1.0.19",
"@spinajs/exceptions": "^1.0.3",
"bunyan": "^1.8.12",
"chalk": "^3.0.0",
"lodash": "^4.17.14"
"@spinajs/configuration": "^1.1.2",
"@spinajs/di": "^1.1.7",
"@spinajs/exceptions": "^1.0.5",
"@spinajs/validation": "^1.0.2",
"colors": "^1.4.0",
"glob": "^7.2.0",
"glob-to-regexp": "^0.4.1",
"lodash": "^4.17.14",
"luxon": "^2.3.0",
"node-schedule": "^2.1.0"
},

@@ -41,4 +46,11 @@ "devDependencies": {

"@types/chai-subset": "^1.3.3",
"@types/colors": "^1.2.1",
"@types/glob": "^7.2.0",
"@types/glob-to-regexp": "^0.4.1",
"@types/lodash": "^4.14.136",
"@types/luxon": "^2.0.8",
"@types/mocha": "^5.2.7",
"@types/node": "^17.0.8",
"@types/node-schedule": "^1.3.2",
"@types/sinon": "^10.0.6",
"chai": "^4.2.0",

@@ -50,2 +62,3 @@ "chai-as-promised": "^7.1.1",

"prettier": "^1.18.2",
"sinon": "^12.0.1",
"ts-mocha": "^6.0.0",

@@ -59,4 +72,4 @@ "ts-node": "^8.3.0",

"typedoc": "^0.14.2",
"typescript": "^3.5.3"
"typescript": "^4.2.3"
}
}

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