New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@contrast/logger

Package Overview
Dependencies
Maintainers
0
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contrast/logger - npm Package Compare versions

Comparing version 1.16.0 to 1.17.0

20

lib/index.d.ts
import { Config } from '@contrast/config';
import { Messages } from '@contrast/common';
import { LoggerOptions, Logger, TransportTargetOptions } from 'pino';
import { Messages, ThreadTransferData } from '@contrast/common';
import Perf from '@contrast/perf';
import { LoggerOptions, Logger } from 'pino';
export interface Core {
threadTransferData: any;
readonly config: Config;
readonly messages: Messages;
readonly Perf: typeof Perf;
readonly threadTransferData?: ThreadTransferData;
}
export { Logger };
export declare const kChildren: unique symbol;
export declare const kTransports: unique symbol;
export interface _Logger extends Logger {
[kChildren]: Logger[];
[kTransports]: TransportTargetOptions[];
}
export default function init(core: any, //Core & { logger?: Logger },
opts?: LoggerOptions): Logger;
export { Logger };
export default function init(core: Core & {
logger?: Logger;
}, opts?: LoggerOptions): Logger;
//# sourceMappingURL=index.d.ts.map

@@ -43,12 +43,11 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.kTransports = exports.kChildren = void 0;
exports.kChildren = void 0;
const config_1 = require("@contrast/config");
const common_1 = require("@contrast/common");
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const os_1 = require("os");
const node_fs_1 = __importDefault(require("node:fs"));
const node_path_1 = __importDefault(require("node:path"));
const node_os_1 = require("node:os");
const node_worker_threads_1 = require("node:worker_threads");
const pino_1 = __importDefault(require("pino"));
const serializers = __importStar(require("./serializers"));
const utils_1 = require("./utils");
const node_worker_threads_1 = require("node:worker_threads");
const REDACT_PATHS = [

@@ -59,13 +58,10 @@ 'err.config.headers.Authorization',

exports.kChildren = Symbol('contrast.logger.children');
exports.kTransports = Symbol('contrast.logger.transports');
function extend(logger, targets) {
function extend(logger) {
Reflect.set(logger, exports.kChildren, []);
Reflect.set(logger, exports.kTransports, targets);
return logger;
}
function init(core, //Core & { logger?: Logger },
opts = {}) {
function init(core, opts = {}) {
const config = core.config.agent.logger;
const perf = new core.Perf('logger');
const targets = [];
const streams = [];
let err;

@@ -75,19 +71,11 @@ if (config.path !== '/dev/null') {

// fs methods throw if we don't have write permissions.
fs_1.default.mkdirSync(path_1.default.dirname(config.path), { recursive: true });
let destination = core.threadTransferData?.loggerFd;
if (!destination) {
destination = fs_1.default.openSync(config.path, config.append ? 'a' : 'w');
}
targets.push({
target: 'pino/file',
node_fs_1.default.mkdirSync(node_path_1.default.dirname(config.path), { recursive: true });
// check for an existing log file descriptor, or open a new one and remember it.
const fd = core.threadTransferData?.loggerFd ?? node_fs_1.default.openSync(config.path, config.append ? 'a' : 'w');
if (core.threadTransferData)
core.threadTransferData.loggerFd = fd;
streams.push({
stream: pino_1.default.destination(fd),
level: 'trace',
options: {
append: config.append,
// core.threadTransferData.loggerFd should only exist if we are in the esm-loader
// thread. It is passed to the loader thread from the main thread.
destination,
},
});
// remember it in this thread.
core.threadTransferData.loggerFd = destination;
}

@@ -101,35 +89,27 @@ catch (cause) {

if (config.stdout) {
targets.push({
target: 'pino/file',
streams.push({
stream: pino_1.default.destination(process.stdout.fd),
level: 'trace',
options: { destination: process.stdout.fd },
});
}
if (err && targets.length === 0)
if (err && streams.length === 0)
throw err;
const logger = core.logger = perf.wrapPinoInstance(extend((0, pino_1.default)({
const logger = (core.logger = perf.wrapPinoInstance(extend((0, pino_1.default)({
name: 'contrast',
level: config.level,
base: { tid: node_worker_threads_1.threadId, pid: process.pid, hostname: (0, os_1.hostname)() },
transport: {
targets,
worker: {
env: (0, utils_1.cleanEnv)(process.env),
execArgv: []
},
},
base: { tid: node_worker_threads_1.threadId, pid: process.pid, hostname: (0, node_os_1.hostname)() },
serializers,
onChild(instance) {
this[exports.kChildren].push(perf.wrapPinoInstance(extend(instance, targets)));
Reflect.get(this, exports.kChildren).push(perf.wrapPinoInstance(extend(instance)));
},
redact: {
paths: REDACT_PATHS,
censor: 'contrast-redacted'
censor: 'contrast-redacted',
},
...opts,
}), targets));
// eslint-disable-next-line
// @ts-ignore
}, pino_1.default.multistream(streams)))));
logger.on('level-change', (level, val, prevLevel, prevVal, instance) => {
instance[exports.kChildren].forEach(child => child.level = level);
Reflect.get(instance, exports.kChildren).forEach((child) => {
child.level = level;
});
});

@@ -136,0 +116,0 @@ if (core.config.getEffectiveSource('agent.logger.level') === config_1.ConfigSource.DEFAULT_VALUE) {

@@ -8,3 +8,5 @@ /// <reference types="node" />

/**
* Removes any '-r @contrast/protect' or similar strings from `process.env.NODE_OPTIONS.`.
* @deprecated this is a relic from when we used transports.
*
* Removes any `'-r @contrast/protect'` or similar strings from `process.env.NODE_OPTIONS.`.
* If we don't do this, the logger worker threads will be instrumented and those agents

@@ -11,0 +13,0 @@ * will attempt to spawn more loggers and result in infinite recursion scenario.

@@ -22,3 +22,5 @@ "use strict";

/**
* Removes any '-r @contrast/protect' or similar strings from `process.env.NODE_OPTIONS.`.
* @deprecated this is a relic from when we used transports.
*
* Removes any `'-r @contrast/protect'` or similar strings from `process.env.NODE_OPTIONS.`.
* If we don't do this, the logger worker threads will be instrumented and those agents

@@ -28,4 +30,3 @@ * will attempt to spawn more loggers and result in infinite recursion scenario.

const cleanEnv = (env) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
// @ts-expect-error exported primordials don't handle overloads very well
const NODE_OPTIONS = env.NODE_OPTIONS ? StringPrototypeReplace.call(env.NODE_OPTIONS, ENV_REGEX, '') : undefined;

@@ -32,0 +33,0 @@ return { ...env, NODE_OPTIONS };

{
"name": "@contrast/logger",
"version": "1.16.0",
"version": "1.17.0",
"description": "Centralized logging for Contrast agent services",

@@ -21,6 +21,6 @@ "license": "SEE LICENSE IN LICENSE",

"dependencies": {
"@contrast/common": "1.28.0",
"@contrast/config": "1.38.0",
"@contrast/common": "1.29.0",
"@contrast/config": "1.39.0",
"pino": "^8.15.0"
}
}

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

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