@chainsafe/lodestar-utils
Advanced tools
Comparing version 0.8.0 to 0.9.0
/// <reference types="node" /> | ||
import { ArrayLike } from "@chainsafe/ssz"; | ||
declare type Endianness = "le" | "be"; | ||
@@ -13,4 +14,4 @@ /** | ||
export declare function bytesToBigInt(value: Uint8Array, endianness?: Endianness): bigint; | ||
export declare function toHex(buffer: Uint8Array): string; | ||
export declare function toHex(buffer: ArrayLike<number>): string; | ||
export declare function fromHex(hex: string): Uint8Array; | ||
export {}; |
@@ -51,3 +51,7 @@ "use strict"; | ||
function toHex(buffer) { | ||
return "0x" + Buffer.from(buffer.buffer, buffer.byteOffset).toString("hex"); | ||
if (buffer instanceof Uint8Array) { | ||
return "0x" + Buffer.from(buffer.buffer, buffer.byteOffset).toString("hex"); | ||
} else { | ||
return "0x" + Buffer.from(buffer).toString("hex"); | ||
} | ||
} | ||
@@ -54,0 +58,0 @@ |
@@ -6,1 +6,2 @@ /** | ||
export * from "./interface"; | ||
export * from "./format"; |
@@ -30,2 +30,14 @@ "use strict"; | ||
}); | ||
var _format = require("./format"); | ||
Object.keys(_format).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _format[key]; | ||
} | ||
}); | ||
}); | ||
//# sourceMappingURL=index.js.map |
/** | ||
* @module logger | ||
*/ | ||
import { ArrayLike } from "@chainsafe/ssz"; | ||
export declare enum LogLevel { | ||
error = 0, | ||
warn = 1, | ||
info = 2, | ||
verbose = 3, | ||
debug = 4, | ||
silly = 5 | ||
error = "error", | ||
warn = "warn", | ||
info = "info", | ||
verbose = "verbose", | ||
debug = "debug", | ||
silly = "silly" | ||
} | ||
export declare const LogLevels: string[]; | ||
export declare const LogLevels: any[]; | ||
export declare const customColors: { | ||
@@ -23,16 +24,23 @@ error: string; | ||
export interface ILoggerOptions { | ||
level: typeof LogLevel[number]; | ||
level: LogLevel; | ||
module: string; | ||
} | ||
export declare type Context = { | ||
[k: string]: string | number | BigInt | ArrayLike<number>; | ||
}; | ||
export interface ILogger { | ||
level: LogLevel; | ||
silent: boolean; | ||
error(message: string | object, context?: object): void; | ||
warn(message: string | object, context?: object): void; | ||
info(message: string | object, context?: object): void; | ||
verbose(message: string | object, context?: object): void; | ||
debug(message: string | object, context?: object): void; | ||
silly(message: string | object, context?: object): void; | ||
error(message: string, context?: Context | Error): void; | ||
warn(message: string, context?: Context | Error): void; | ||
info(message: string, context?: Context): void; | ||
important(message: string, context?: Context): void; | ||
verbose(message: string, context?: Context): void; | ||
debug(message: string, context?: Context): void; | ||
silly(message: string, context?: Context): void; | ||
profile(message: string, option?: { | ||
level: string; | ||
message: string; | ||
}): void; | ||
child(options: ILoggerOptions): ILogger; | ||
important(message: string | object, context?: object): void; | ||
} |
@@ -11,15 +11,16 @@ "use strict"; | ||
*/ | ||
let LogLevel; | ||
let LogLevel; // @ts-ignore | ||
exports.LogLevel = LogLevel; | ||
(function (LogLevel) { | ||
LogLevel[LogLevel["error"] = 0] = "error"; | ||
LogLevel[LogLevel["warn"] = 1] = "warn"; | ||
LogLevel[LogLevel["info"] = 2] = "info"; | ||
LogLevel[LogLevel["verbose"] = 3] = "verbose"; | ||
LogLevel[LogLevel["debug"] = 4] = "debug"; | ||
LogLevel[LogLevel["silly"] = 5] = "silly"; | ||
LogLevel["error"] = "error"; | ||
LogLevel["warn"] = "warn"; | ||
LogLevel["info"] = "info"; | ||
LogLevel["verbose"] = "verbose"; | ||
LogLevel["debug"] = "debug"; | ||
LogLevel["silly"] = "silly"; | ||
})(LogLevel || (exports.LogLevel = LogLevel = {})); | ||
const LogLevels = ["error", "warn", "info", "verbose", "debug", "silly"]; | ||
const LogLevels = Object.keys(LogLevel).map(key => LogLevel[key]); | ||
exports.LogLevels = LogLevels; | ||
@@ -26,0 +27,0 @@ const customColors = { |
/** | ||
* @module logger | ||
*/ | ||
import { LogLevel, ILogger, ILoggerOptions } from "./interface"; | ||
import { Context, ILogger, ILoggerOptions, LogLevel } from "./interface"; | ||
import TransportStream from "winston-transport"; | ||
export declare class WinstonLogger implements ILogger { | ||
@@ -9,10 +10,14 @@ private winston; | ||
private _silent; | ||
constructor(options?: Partial<ILoggerOptions>); | ||
debug(message: string | object, context?: object): void; | ||
info(message: string | object, context?: object): void; | ||
important(message: string | object, context?: object): void; | ||
error(message: string | object, context?: object): void; | ||
warn(message: string | object, context?: object): void; | ||
verbose(message: string | object, context?: object): void; | ||
silly(message: string | object, context?: object): void; | ||
constructor(options?: Partial<ILoggerOptions>, transports?: TransportStream); | ||
debug(message: string, context?: Context): void; | ||
info(message: string, context?: Context): void; | ||
important(message: string, context?: Context): void; | ||
error(message: string, context?: Context | Error): void; | ||
warn(message: string, context?: Context | Error): void; | ||
verbose(message: string, context?: Context): void; | ||
silly(message: string, context?: Context): void; | ||
profile(message: string, option?: { | ||
level: string; | ||
message: string; | ||
}): void; | ||
set level(level: LogLevel); | ||
@@ -19,0 +24,0 @@ get level(): LogLevel; |
@@ -14,2 +14,4 @@ "use strict"; | ||
var _format = require("./format"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -24,3 +26,3 @@ | ||
class WinstonLogger { | ||
constructor(options) { | ||
constructor(options, transports) { | ||
_defineProperty(this, "winston", void 0); | ||
@@ -33,7 +35,7 @@ | ||
options = _objectSpread({ | ||
level: _interface.LogLevel[_interface.defaultLogLevel], | ||
level: _interface.defaultLogLevel, | ||
module: "" | ||
}, options); | ||
this.winston = (0, _winston.createLogger)({ | ||
level: _interface.LogLevel[_interface.LogLevel.verbose], | ||
level: options.level, | ||
// log level switching handled in `createLogEntry` | ||
@@ -43,17 +45,9 @@ defaultMeta: { | ||
}, | ||
transports: [new _winston.transports.Console({ | ||
format: _winston.format.combine(_winston.format.colorize(), _winston.format.timestamp({ | ||
format: "YYYY-MM-DD HH:mm:ss" | ||
}), _winston.format.printf(info => { | ||
const paddingBetweenInfo = 30; | ||
const infoString = info.module || info.namespace || ""; | ||
const infoPad = paddingBetweenInfo - infoString.length; | ||
return "".concat(info.timestamp, " [").concat(infoString.toUpperCase(), "] ").concat(info.level.padStart(infoPad), ": ").concat(info.message); | ||
})), | ||
format: _format.defaultLogFormat, | ||
transports: transports || [new _winston.transports.Console({ | ||
handleExceptions: true | ||
})], | ||
exitOnError: false | ||
}); //@ts-ignore | ||
this._level = _interface.LogLevel[options.level]; | ||
}); | ||
this._level = options.level; | ||
this._silent = false; | ||
@@ -94,2 +88,6 @@ | ||
profile(message, option) { | ||
this.winston.profile(message, option); | ||
} | ||
set level(level) { | ||
@@ -115,7 +113,9 @@ this.winston.level = _interface.LogLevel[level]; | ||
const winston = this.winston.child({ | ||
namespace: options.module | ||
namespace: options.module, | ||
level: options.level | ||
}); | ||
winston.level = options.level || this._level; | ||
return Object.assign(logger, { | ||
winston, | ||
_level: options.level, | ||
_level: options.level || this._level, | ||
_silent: this._silent | ||
@@ -125,12 +125,10 @@ }); | ||
createLogEntry(level, message, context = {}) { | ||
if (this.silent || level > this._level) { | ||
createLogEntry(level, message, context) { | ||
if (this.silent || this.winston.levels[level] > this.winston.levels[this.winston.level]) { | ||
return; | ||
} | ||
if (typeof message === "object") { | ||
this.winston.log(_interface.LogLevel[level], JSON.stringify(message)); | ||
} else { | ||
this.winston.log(_interface.LogLevel[level], message, context); | ||
} | ||
this.winston.log(level, message, { | ||
context | ||
}); | ||
} | ||
@@ -137,0 +135,0 @@ |
@@ -14,3 +14,3 @@ { | ||
}, | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"main": "lib/index.js", | ||
@@ -38,3 +38,3 @@ "files": [ | ||
"dependencies": { | ||
"@chainsafe/ssz": "^0.6.4", | ||
"@chainsafe/ssz": "^0.6.5", | ||
"bigint-buffer": "^1.1.5", | ||
@@ -44,3 +44,4 @@ "camelcase": "^5.3.1", | ||
"js-yaml": "^3.13.1", | ||
"winston": "^3.2.1" | ||
"winston": "^3.2.1", | ||
"winston-transport": "^4.3.0" | ||
}, | ||
@@ -62,3 +63,3 @@ "devDependencies": { | ||
], | ||
"gitHead": "bd8798297953a1a21553c09c9d150624b7e5eef8" | ||
"gitHead": "a7b4c5ad002f018f0682a627b7c528d5743f6647" | ||
} |
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
74219
50
859
7
+ Addedwinston-transport@^4.3.0
Updated@chainsafe/ssz@^0.6.5