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

@adonisjs/logger

Package Overview
Dependencies
Maintainers
3
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@adonisjs/logger - npm Package Compare versions

Comparing version 5.4.2-5 to 5.4.2-6

build/chunk-7KCDY32J.js

27

build/factories/main.d.ts

@@ -1,1 +0,26 @@

export { LoggerFactory } from './logger.js';
import { L as Logger } from '../logger-d4410ee3.js';
import { LoggerConfig } from '../src/types.js';
import 'pino';
/**
* Logger factory is used to generate logger class instances for
* testing
*/
declare class LoggerFactory {
#private;
/**
* Define an array that will be used to writing
* logs
*/
pushLogsTo(collection: string[]): this;
/**
* Merge encryption factory options
*/
merge(options: LoggerConfig): this;
/**
* Create instance of the logger class
*/
create(): Logger<LoggerConfig>;
}
export { LoggerFactory };

@@ -1,9 +0,45 @@

/*
* @adonisjs/logger
*
* (c) AdonisJS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
export { LoggerFactory } from './logger.js';
import {
Logger
} from "../chunk-7KCDY32J.js";
// factories/logger.ts
import { Writable } from "node:stream";
function getFakeStream(fn) {
const stream = new Writable();
stream.write = fn;
return stream;
}
var LoggerFactory = class {
#options = {};
#logsCollection;
/**
* Define an array that will be used to writing
* logs
*/
pushLogsTo(collection) {
this.#logsCollection = collection;
return this;
}
/**
* Merge encryption factory options
*/
merge(options) {
Object.assign(this.#options, options);
return this;
}
/**
* Create instance of the logger class
*/
create() {
if (this.#logsCollection) {
this.#options.desination = getFakeStream((message) => {
this.#logsCollection.push(message.trim());
return true;
});
}
return new Logger(this.#options);
}
};
export {
LoggerFactory
};

@@ -1,5 +0,92 @@

export { Logger } from './src/logger.js';
export { targets } from './src/targets/main.js';
export { defineConfig } from './src/define_config.js';
export { LoggerManager } from './src/logger_manager.js';
export { transport, destination, multistream, stdSerializers, stdTimeFunctions, } from './src/pino.js';
import { L as Logger } from './logger-d4410ee3.js';
import { PrettyTargetOptions, FileTargetOptions, LoggerConfig, LoggerManagerConfig } from './src/types.js';
import { Level, TransportTargetOptions, Logger as Logger$1 } from 'pino';
export { destination, multistream, stdSerializers, stdTimeFunctions, transport } from 'pino';
/**
* Construct options object for the pino-pretty target.
*/
declare function pretty(options?: PrettyTargetOptions, level?: string | Level): TransportTargetOptions;
/**
* Construct options object for the file target.
*/
declare function file(options?: FileTargetOptions, level?: string | Level): TransportTargetOptions;
/**
* Exposes the API to construct targets array conditionally.
*/
declare class Targets {
#private;
/**
* Add target to the list of targets
*/
push(value: TransportTargetOptions): this;
/**
* Conditionally add target to the list targets. The target will only be added
* if the `conditional` is true.
*
* ```ts
* targets.if(process.env.NODE_ENV === 'development', {
* target: 'pino-pretty'
* })
* ```
*/
pushIf(conditional: boolean, value: TransportTargetOptions | (() => TransportTargetOptions)): this;
/**
* Conditionally add target to the list targets. The target will only be added
* unless the `conditional` is true.
*
* ```ts
* targets.unless(process.env.NODE_ENV === 'production', {
* target: 'pino-pretty'
* })
* ```
*/
pushUnless(conditional: boolean, value: TransportTargetOptions | (() => TransportTargetOptions)): this;
/**
* Get targets array
*/
toArray(): TransportTargetOptions[];
}
/**
* Create the targets array conditionally.
*/
declare function targets(): Targets;
declare namespace targets {
var file: typeof file;
var pretty: typeof pretty;
}
/**
* Define the logger config. The config object must have a default property
* pointing to the key within the loggers object.
*/
declare function defineConfig<KnownLoggers extends Record<string, LoggerConfig>>(config: LoggerManagerConfig<KnownLoggers>): LoggerManagerConfig<KnownLoggers>;
/**
* Logger manager is used to manage multiple instances of the Logger. The
* loggers are created using the default config and the logger instances
* are cached forever.
*/
declare class LoggerManager<KnownLoggers extends Record<string, LoggerConfig>> extends Logger<LoggerConfig> {
#private;
constructor(config: LoggerManagerConfig<KnownLoggers>);
/**
* Creates an instance of the logger
*/
protected createLogger<K extends keyof KnownLoggers>(logger: K, config: KnownLoggers[K]): Logger<KnownLoggers[K]>;
/**
* Get instance of a logger
*/
use<K extends keyof KnownLoggers>(logger: K): Logger<KnownLoggers[K]>;
use(): Logger<LoggerConfig>;
/**
* Create a logger instance from the config. The created instance
* is not managed by the manager
*/
create(config: LoggerConfig, pino?: Logger$1): Logger<LoggerConfig>;
}
export { Logger, LoggerManager, defineConfig, targets };

@@ -1,13 +0,162 @@

/*
* @adonisjs/logger
*
* (c) AdonisJS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
export { Logger } from './src/logger.js';
export { targets } from './src/targets/main.js';
export { defineConfig } from './src/define_config.js';
export { LoggerManager } from './src/logger_manager.js';
export { transport, destination, multistream, stdSerializers, stdTimeFunctions, } from './src/pino.js';
import {
Logger,
destination,
multistream,
stdSerializers,
stdTimeFunctions,
transport
} from "./chunk-7KCDY32J.js";
// src/targets/file.ts
function file(options, level) {
return {
target: "pino/file",
level: level || "info",
options: options || {}
};
}
// src/targets/create.ts
var Targets = class {
#collection = [];
/**
* Add target to the list of targets
*/
push(value) {
this.#collection.push(value);
return this;
}
/**
* Conditionally add target to the list targets. The target will only be added
* if the `conditional` is true.
*
* ```ts
* targets.if(process.env.NODE_ENV === 'development', {
* target: 'pino-pretty'
* })
* ```
*/
pushIf(conditional, value) {
if (conditional) {
this.#collection.push(typeof value === "function" ? value() : value);
}
return this;
}
/**
* Conditionally add target to the list targets. The target will only be added
* unless the `conditional` is true.
*
* ```ts
* targets.unless(process.env.NODE_ENV === 'production', {
* target: 'pino-pretty'
* })
* ```
*/
pushUnless(conditional, value) {
if (!conditional) {
this.#collection.push(typeof value === "function" ? value() : value);
}
return this;
}
/**
* Get targets array
*/
toArray() {
return this.#collection;
}
};
// src/targets/pretty.ts
function pretty(options, level) {
return {
target: "pino-pretty",
level: level || "info",
options: options || {}
};
}
// src/targets/main.ts
function targets() {
return new Targets();
}
targets.file = file;
targets.pretty = pretty;
// src/define_config.ts
import { RuntimeException } from "@poppinss/utils";
function defineConfig(config) {
if (!config.loggers) {
throw new RuntimeException('Missing "loggers" property in logger config file');
}
if (!config.default) {
throw new RuntimeException(
'Missing "default" property in logger config. Specify a default logger'
);
}
if (!config.loggers[config.default]) {
throw new RuntimeException(
`Missing "loggers.${String(config.default)}". It is referenced by the "default" logger`
);
}
return config;
}
// src/debug.ts
import { debuglog } from "node:util";
var debug_default = debuglog("adonisjs:logger");
// src/logger_manager.ts
var LoggerManager = class extends Logger {
/**
* Registered config
*/
#config;
/**
* Created loggers. Logger instances are cached forever
*/
#loggers = /* @__PURE__ */ new Map();
constructor(config) {
super(config.loggers[config.default]);
this.#config = config;
debug_default("creating logger manager. config: %O", this.#config);
}
/**
* Creates an instance of the logger
*/
createLogger(logger, config) {
if (!config.name && typeof logger === "string") {
config.name = logger;
}
return new Logger(config);
}
use(logger) {
let loggerToUse = logger || this.#config.default;
if (this.#loggers.has(loggerToUse)) {
debug_default('using logger from cache. name: "%s"', logger);
return this.#loggers.get(loggerToUse);
}
const config = this.#config.loggers[loggerToUse];
debug_default('creating logger. name: "%s", config: %O', logger, config);
const loggerInstance = this.createLogger(loggerToUse, config);
this.#loggers.set(loggerToUse, loggerInstance);
return loggerInstance;
}
/**
* Create a logger instance from the config. The created instance
* is not managed by the manager
*/
create(config, pino) {
return new Logger(config, pino);
}
};
export {
Logger,
LoggerManager,
defineConfig,
destination,
multistream,
stdSerializers,
stdTimeFunctions,
targets,
transport
};

19

build/src/types.d.ts

@@ -1,9 +0,10 @@

/// <reference types="node" resolution-mode="require"/>
import { Level, Bindings, LevelMapping, LoggerOptions, DestinationStream, ChildLoggerOptions, TransportTargetOptions } from 'pino';
export type TimestampKeywords = 'iso' | 'unix' | 'epoch';
export type { TransportTargetOptions, Level, LevelMapping, ChildLoggerOptions, Bindings };
import { LoggerOptions, DestinationStream, Level } from 'pino';
export { Bindings, ChildLoggerOptions, Level, LevelMapping, TransportTargetOptions } from 'pino';
type TimestampKeywords = 'iso' | 'unix' | 'epoch';
/**
* Logger config inherited from pino logger options
*/
export type LoggerConfig = Omit<LoggerOptions, 'browser' | 'timestamp'> & {
type LoggerConfig = Omit<LoggerOptions, 'browser' | 'timestamp'> & {
enabled?: boolean;

@@ -16,3 +17,3 @@ desination?: DestinationStream;

*/
export type FileTargetOptions = {
type FileTargetOptions = {
destination: string | number;

@@ -26,3 +27,3 @@ mkdir?: boolean;

*/
export type PrettyTargetOptions = {
type PrettyTargetOptions = {
hideObject?: boolean;

@@ -53,5 +54,7 @@ translateTime?: boolean | string;

*/
export type LoggerManagerConfig<KnownLoggers extends Record<string, LoggerConfig>> = {
type LoggerManagerConfig<KnownLoggers extends Record<string, LoggerConfig>> = {
default: keyof KnownLoggers;
loggers: KnownLoggers;
};
export { FileTargetOptions, LoggerConfig, LoggerManagerConfig, PrettyTargetOptions, TimestampKeywords };
{
"name": "@adonisjs/logger",
"version": "5.4.2-5",
"version": "5.4.2-6",
"description": "Logger built on top of pino to be used by AdonisJs",

@@ -8,6 +8,3 @@ "main": "build/index.js",

"files": [
"build/src",
"build/factories",
"build/index.d.ts",
"build/index.js"
"build"
],

@@ -27,3 +24,3 @@ "exports": {

"typecheck": "tsc --noEmit",
"compile": "npm run lint && npm run clean && tsc",
"compile": "npm run lint && npm run clean && tsup-node",
"build": "npm run compile",

@@ -50,24 +47,25 @@ "release": "np",

"@adonisjs/tsconfig": "^1.1.8",
"@commitlint/cli": "^17.7.1",
"@commitlint/config-conventional": "^17.7.0",
"@japa/assert": "^2.0.0-1",
"@japa/expect-type": "^2.0.0-0",
"@japa/runner": "^3.0.0-3",
"@swc/core": "^1.3.78",
"@types/node": "^20.5.3",
"@commitlint/cli": "^17.8.0",
"@commitlint/config-conventional": "^17.8.0",
"@japa/assert": "^2.0.0",
"@japa/expect-type": "^2.0.0",
"@japa/runner": "^3.0.2",
"@swc/core": "1.3.82",
"@types/node": "^20.8.6",
"c8": "^8.0.1",
"cross-env": "^7.0.3",
"del-cli": "^5.0.0",
"eslint": "^8.47.0",
"del-cli": "^5.1.0",
"eslint": "^8.51.0",
"github-label-sync": "^2.3.1",
"husky": "^8.0.3",
"np": "^8.0.4",
"prettier": "^3.0.2",
"prettier": "^3.0.3",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
"tsup": "^7.2.0",
"typescript": "^5.2.2"
},
"dependencies": {
"@poppinss/utils": "^6.5.0-5",
"@poppinss/utils": "^6.5.0",
"abstract-logging": "^2.0.1",
"pino": "^8.15.0"
"pino": "^8.16.0"
},

@@ -109,3 +107,15 @@ "repository": {

},
"prettier": "@adonisjs/prettier-config"
"prettier": "@adonisjs/prettier-config",
"tsup": {
"entry": [
"./index.ts",
"./src/types.ts",
"./factories/main.ts"
],
"outDir": "./build",
"clean": true,
"format": "esm",
"dts": true,
"target": "esnext"
}
}
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