@spot-meetings/backend-logger
Advanced tools
Comparing version 1.0.1 to 2.0.0
@@ -0,1 +1,5 @@ | ||
import winston from 'winston'; | ||
/** | ||
* @see https://github.com/winstonjs/winston#logging | ||
*/ | ||
export declare enum LogLevel { | ||
@@ -5,3 +9,6 @@ Error = "error", | ||
Info = "info", | ||
Debug = "debug" | ||
Http = "http", | ||
Verbose = "verbose", | ||
Debug = "debug", | ||
Silly = "silly" | ||
} | ||
@@ -17,3 +24,2 @@ export interface LogReporter { | ||
stack?: string; | ||
error?: Error; | ||
[prop: string]: any; | ||
@@ -24,8 +30,2 @@ } | ||
*/ | ||
export declare const createLogger: (id: string, ip: string, version: string) => Readonly<{ | ||
log: (level: LogLevel, message: string, data?: Partial<LogData>) => void; | ||
debug: (message: string, data?: Partial<LogData>) => void; | ||
info: (message: string, data?: Partial<LogData>) => void; | ||
warn: (message: string, data?: Partial<LogData>) => void; | ||
error: (message: string, data?: Partial<LogData>) => void; | ||
}>; | ||
export declare const createLogger: (id: string, ip: string, version: string) => winston.Logger; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createLogger = exports.LogLevel = void 0; | ||
const winston_1 = require("winston"); | ||
const { timestamp, splat, json } = winston_1.format; | ||
const winston_1 = __importDefault(require("winston")); | ||
const { timestamp, splat, json, errors, combine, } = winston_1.default.format; | ||
/** | ||
* @see https://github.com/winstonjs/winston#logging | ||
*/ | ||
var LogLevel; | ||
@@ -11,6 +17,6 @@ (function (LogLevel) { | ||
LogLevel["Info"] = "info"; | ||
// Http = 'http', | ||
// Verbose = 'verbose', | ||
LogLevel["Http"] = "http"; | ||
LogLevel["Verbose"] = "verbose"; | ||
LogLevel["Debug"] = "debug"; | ||
// Silly = 'silly', | ||
LogLevel["Silly"] = "silly"; | ||
})(LogLevel = exports.LogLevel || (exports.LogLevel = {})); | ||
@@ -27,5 +33,5 @@ /** | ||
} | ||
const logger = winston_1.createLogger({ | ||
format: winston_1.format.combine(timestamp(), splat(), json()), | ||
transports: [new winston_1.transports.Console()], | ||
return winston_1.default.createLogger({ | ||
format: combine(errors({ stack: true }), timestamp(), splat(), json()), | ||
transports: [new winston_1.default.transports.Console()], | ||
level: logLevel, | ||
@@ -42,58 +48,3 @@ defaultMeta: { | ||
}); | ||
/** | ||
* @param level The log level to use. | ||
* @param message The message to log. | ||
* @param data Additional metadata. | ||
*/ | ||
const log = (level, message, data = {}) => { | ||
const logData = { ...data }; | ||
if (data?.error?.stack) { | ||
logData.stack = data.error.stack; | ||
} | ||
logger.log({ level, message, ...(logData || {}) }); | ||
}; | ||
/** | ||
* Logs a debug message. | ||
* | ||
* @param message The message to log. | ||
* @param data Additional metadata. | ||
*/ | ||
const debug = (message, data = {}) => { | ||
log(LogLevel.Debug, message, data); | ||
}; | ||
/** | ||
* Logs an info message. | ||
* | ||
* @param message The message to log. | ||
* @param data Additional metadata. | ||
*/ | ||
const info = (message, data = {}) => { | ||
log(LogLevel.Info, message, data); | ||
}; | ||
/** | ||
* Logs an info message. | ||
* | ||
* @param message The message to log. | ||
* @param data Additional metadata. | ||
*/ | ||
const warn = (message, data = {}) => { | ||
log(LogLevel.Warn, message, data); | ||
}; | ||
/** | ||
* Logs an info message. | ||
* | ||
* @param message The message to log. | ||
* @param data Additional metadata. | ||
*/ | ||
const error = (message, data = {}) => { | ||
log(LogLevel.Error, message, data); | ||
}; | ||
return Object.freeze({ | ||
log, | ||
debug, | ||
info, | ||
warn, | ||
error, | ||
}); | ||
}; | ||
exports.createLogger = createLogger; |
{ | ||
"name": "@spot-meetings/backend-logger", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "Spot's backend logger module.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -1,5 +0,10 @@ | ||
import { createLogger as _createLogger, transports, format } from 'winston' | ||
import winston from 'winston' | ||
const { timestamp, splat, json } = format | ||
const { | ||
timestamp, splat, json, errors, combine, | ||
} = winston.format | ||
/** | ||
* @see https://github.com/winstonjs/winston#logging | ||
*/ | ||
export enum LogLevel { | ||
@@ -9,6 +14,6 @@ Error = 'error', | ||
Info = 'info', | ||
// Http = 'http', | ||
// Verbose = 'verbose', | ||
Http = 'http', | ||
Verbose = 'verbose', | ||
Debug = 'debug', | ||
// Silly = 'silly', | ||
Silly = 'silly', | ||
} | ||
@@ -27,5 +32,4 @@ | ||
// Optional error info | ||
// Optional error stack | ||
stack?: string | ||
error?: Error | ||
@@ -51,5 +55,10 @@ // Optional additional info | ||
const logger = _createLogger({ | ||
format: format.combine(timestamp(), splat(), json()), | ||
transports: [new transports.Console()], | ||
return winston.createLogger({ | ||
format: combine( | ||
errors({ stack: true }), | ||
timestamp(), | ||
splat(), | ||
json(), | ||
), | ||
transports: [new winston.transports.Console()], | ||
level: logLevel, | ||
@@ -66,69 +75,2 @@ defaultMeta: { | ||
}) | ||
/** | ||
* @param level The log level to use. | ||
* @param message The message to log. | ||
* @param data Additional metadata. | ||
*/ | ||
const log = ( | ||
level: LogLevel, | ||
message: string, | ||
data: Partial<LogData> = {}, | ||
) => { | ||
const logData = { ...data } | ||
if (data?.error?.stack) { | ||
logData.stack = data.error.stack | ||
} | ||
logger.log({ level, message, ...(logData || {}) }) | ||
} | ||
/** | ||
* Logs a debug message. | ||
* | ||
* @param message The message to log. | ||
* @param data Additional metadata. | ||
*/ | ||
const debug = (message: string, data: Partial<LogData> = {}) => { | ||
log(LogLevel.Debug, message, data) | ||
} | ||
/** | ||
* Logs an info message. | ||
* | ||
* @param message The message to log. | ||
* @param data Additional metadata. | ||
*/ | ||
const info = (message: string, data: Partial<LogData> = {}) => { | ||
log(LogLevel.Info, message, data) | ||
} | ||
/** | ||
* Logs an info message. | ||
* | ||
* @param message The message to log. | ||
* @param data Additional metadata. | ||
*/ | ||
const warn = (message: string, data: Partial<LogData> = {}) => { | ||
log(LogLevel.Warn, message, data) | ||
} | ||
/** | ||
* Logs an info message. | ||
* | ||
* @param message The message to log. | ||
* @param data Additional metadata. | ||
*/ | ||
const error = (message: string, data: Partial<LogData> = {}) => { | ||
log(LogLevel.Error, message, data) | ||
} | ||
return Object.freeze({ | ||
log, | ||
debug, | ||
info, | ||
warn, | ||
error, | ||
}) | ||
} |
{ | ||
"compilerOptions": { | ||
"esModuleInterop": true, | ||
"module": "commonjs", | ||
"skipLibCheck": true, | ||
"declaration": true, | ||
"module": "commonjs", | ||
"target": "ESNext", | ||
@@ -7,0 +8,0 @@ "strict": false, |
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
9497
158