This commit is contained in:
Tutur33
2023-11-24 22:35:41 +01:00
parent 3c0b507a93
commit 7644b2a0f7
45165 changed files with 4803356 additions and 3 deletions
+30
View File
@@ -0,0 +1,30 @@
/// <reference path="../adonis-typings/logger.d.ts" />
import Pino from 'pino';
import { LoggerConfig } from '@ioc:Adonis/Core/Logger';
import { Logger } from './Logger';
/**
* Fake logger that sets a custom logger stream and returns
* the log messages as an array vs writing them to `stdout`.
*/
export declare class FakeLogger extends Logger {
constructor(config: LoggerConfig, pino?: Pino.Logger);
/**
* An array of in-memory logs
*/
get logs(): any[];
/**
* Returns the child fake logger. All logs from the child
* are writte to the same top level stream
*/
child(bindings: {
level?: Pino.Level | string;
serializers?: {
[key: string]: Pino.SerializerFn;
};
[key: string]: any;
}): FakeLogger;
/**
* Clear in-memory logs
*/
clear(): void;
}
+65
View File
@@ -0,0 +1,65 @@
"use strict";
/*
* @adonisjs/logger
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.FakeLogger = void 0;
const Logger_1 = require("./Logger");
/**
* Fake logger that sets a custom logger stream and returns
* the log messages as an array vs writing them to `stdout`.
*/
class FakeLogger extends Logger_1.Logger {
constructor(config, pino) {
/**
* Config is only used when we are not receiving an
* existing instance of pino.
*/
if (!pino) {
const cloned = Object.assign({}, config, {
prettyPrint: false,
stream: {
logs: [],
write: function writer(line) {
const log = JSON.parse(line);
delete log.timestamp;
this.logs.push(log);
},
},
});
super(cloned);
}
else {
super(config, pino);
}
}
/**
* An array of in-memory logs
*/
get logs() {
return this.config.stream.logs;
}
/**
* Returns the child fake logger. All logs from the child
* are writte to the same top level stream
*/
child(bindings) {
if (!this.config.enabled) {
return this;
}
return new FakeLogger(this.config, this.pino.child(bindings));
}
/**
* Clear in-memory logs
*/
clear() {
;
this.config.stream.logs = [];
}
}
exports.FakeLogger = FakeLogger;
+92
View File
@@ -0,0 +1,92 @@
/// <reference path="../adonis-typings/logger.d.ts" />
import Pino from 'pino';
import { LoggerConfig, LoggerContract } from '@ioc:Adonis/Core/Logger';
/**
* Logger class built on top of pino with couple of changes in
* the configuration. You can access the underlying `pino`
* object using `logger.pino`.
*/
export declare class Logger implements LoggerContract {
protected config: LoggerConfig;
pino: Pino.Logger;
constructor(config: LoggerConfig, pino?: Pino.Logger);
/**
* A map of levels
*/
get levels(): Pino.LevelMapping;
/**
* Returns the current logger level
*/
get level(): string;
/**
* Update logger level
*/
set level(level: string);
/**
* Returns the current logger level number
*/
get levelNumber(): number;
/**
* Returns the pino version
*/
get pinoVersion(): string;
/**
* Returns a boolean telling if level is enabled or
* not.
*/
isLevelEnabled(level: string): boolean;
/**
* Log message for any named level
*/
log(level: string, message: string, ...values: any[]): void;
log(level: string, mergingObject: any, message: string, ...values: any[]): void;
/**
* Log message at trace level
*/
trace(message: string, ...values: any[]): void;
trace(mergingObject: any, message: string, ...values: any[]): void;
/**
* Log message at debug level
*/
debug(message: string, ...values: any[]): void;
debug(mergingObject: any, message: string, ...values: any[]): void;
/**
* Log message at info level
*/
info(message: string, ...values: any[]): void;
info(mergingObject: any, message: string, ...values: any[]): void;
/**
* Log message at warn level
*/
warn(message: string, ...values: any[]): void;
warn(mergingObject: any, message: string, ...values: any[]): void;
/**
* Log message at error level
*/
error(message: string, ...values: any[]): void;
error(mergingObject: any, message: string, ...values: any[]): void;
/**
* Log message at fatal level
*/
fatal(message: string, ...values: any[]): void;
fatal(mergingObject: any, message: string, ...values: any[]): void;
/**
* Returns a child logger instance
*/
child(bindings: {
serializers?: {
[key: string]: Pino.SerializerFn;
};
[key: string]: any;
}, options?: {
level?: Pino.Level | string;
redact?: string[] | Pino.redactOptions;
serializers?: {
[key: string]: Pino.SerializerFn;
};
}): Logger;
/**
* Returns default bindings for the logger
*/
bindings(): Pino.Bindings;
}
+153
View File
@@ -0,0 +1,153 @@
"use strict";
/*
* @adonisjs/logger
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = void 0;
/// <reference path="../adonis-typings/logger.ts" />
const pino_1 = __importDefault(require("pino"));
const abstract_logging_1 = __importDefault(require("abstract-logging"));
const getPino_1 = require("./getPino");
const STATIC_LEVELS = {
labels: {
10: 'trace',
20: 'debug',
30: 'info',
40: 'warn',
50: 'error',
60: 'fatal',
},
values: {
fatal: 60,
error: 50,
warn: 40,
info: 30,
debug: 20,
trace: 10,
},
};
/**
* Logger class built on top of pino with couple of changes in
* the configuration. You can access the underlying `pino`
* object using `logger.pino`.
*/
class Logger {
constructor(config, pino) {
this.config = config;
if (!this.config.enabled) {
this.pino = abstract_logging_1.default;
}
else {
this.pino = pino || (0, getPino_1.getPino)(this.config);
}
}
/**
* A map of levels
*/
get levels() {
if (!this.config.enabled) {
return STATIC_LEVELS;
}
return this.pino.levels;
}
/**
* Returns the current logger level
*/
get level() {
if (!this.config.enabled) {
return this.config.level;
}
return this.pino.level;
}
/**
* Update logger level
*/
set level(level) {
if (!this.config.enabled) {
this.config.level = level;
return;
}
this.pino.level = level;
}
/**
* Returns the current logger level number
*/
get levelNumber() {
if (!this.config.enabled) {
return STATIC_LEVELS.values[this.config.level];
}
return this.pino.levelVal;
}
/**
* Returns the pino version
*/
get pinoVersion() {
return pino_1.default.version;
}
/**
* Returns a boolean telling if level is enabled or
* not.
*/
isLevelEnabled(level) {
if (!this.config.enabled) {
return false;
}
return this.pino.isLevelEnabled(level);
}
log(level, mergingObject, message, ...values) {
if (values.length) {
this.pino[level](mergingObject, message, ...values);
}
else if (message) {
this.pino[level](mergingObject, message);
}
else {
this.pino[level](mergingObject);
}
}
trace(mergingObject, message, ...values) {
this.log('trace', mergingObject, message, ...values);
}
debug(mergingObject, message, ...values) {
this.log('debug', mergingObject, message, ...values);
}
info(mergingObject, message, ...values) {
this.log('info', mergingObject, message, ...values);
}
warn(mergingObject, message, ...values) {
this.log('warn', mergingObject, message, ...values);
}
error(mergingObject, message, ...values) {
this.log('error', mergingObject, message, ...values);
}
fatal(mergingObject, message, ...values) {
this.log('fatal', mergingObject, message, ...values);
}
/**
* Returns a child logger instance
*/
child(bindings, options) {
if (!this.config.enabled) {
return this;
}
return new Logger(this.config, this.pino.child(bindings, options));
}
/**
* Returns default bindings for the logger
*/
bindings() {
if (!this.config.enabled) {
return {};
}
return this.pino.bindings();
}
}
exports.Logger = Logger;
+7
View File
@@ -0,0 +1,7 @@
/// <reference path="../adonis-typings/logger.d.ts" />
import Pino from 'pino';
import { LoggerConfig } from '@ioc:Adonis/Core/Logger';
/**
* Returns an instance of pino logger by adjusting the config options
*/
export declare function getPino(options: LoggerConfig): Pino.Logger;
+40
View File
@@ -0,0 +1,40 @@
"use strict";
/*
* @adonisjs/logger
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPino = void 0;
/// <reference path="../adonis-typings/logger.ts" />
const pino_1 = __importDefault(require("pino"));
/**
* Mapping pino timestamp formatters to keywords
*/
const TimestampFormatters = {
iso: pino_1.default.stdTimeFunctions.isoTime,
epoch: pino_1.default.stdTimeFunctions.epochTime,
unix: pino_1.default.stdTimeFunctions.unixTime,
};
/**
* Returns an instance of pino logger by adjusting the config options
*/
function getPino(options) {
const pinoOptions = Object.assign({}, options);
/**
* Use pino formatters when a keyword is used
*/
if (pinoOptions.timestamp &&
typeof pinoOptions.timestamp === 'string' &&
TimestampFormatters[pinoOptions.timestamp]) {
pinoOptions.timestamp = TimestampFormatters[pinoOptions.timestamp];
}
return options.stream ? (0, pino_1.default)(pinoOptions, options.stream) : (0, pino_1.default)(pinoOptions);
}
exports.getPino = getPino;