Socket
Socket
Sign inDemoInstall

roarr

Package Overview
Dependencies
Maintainers
1
Versions
150
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

roarr - npm Package Compare versions

Comparing version 7.12.3 to 7.13.0

67

dist/src/factories/createLogger.js

@@ -8,2 +8,3 @@ "use strict";

const fast_printf_1 = require("fast-printf");
const fast_safe_stringify_1 = __importDefault(require("fast-safe-stringify"));
const globalthis_1 = __importDefault(require("globalthis"));

@@ -48,2 +49,26 @@ const config_1 = require("../config");

};
const createChildLogger = (log, logLevel) => {
return (a, b, c, d, e, f, g, h, i, j) => {
log.child({
logLevel,
})(a, b, c, d, e, f, g, h, i, j);
};
};
const MAX_ONCE_ENTRIES = 1000;
const createOnceChildLogger = (log, logLevel) => {
return (a, b, c, d, e, f, g, h, i, j) => {
const key = (0, fast_safe_stringify_1.default)({ a, b, c, d, e, f, g, h, i, j, logLevel });
const onceLog = getGlobalRoarrContext().onceLog;
if (onceLog.has(key)) {
return;
}
onceLog.add(key);
if (onceLog.size > MAX_ONCE_ENTRIES) {
onceLog.clear();
}
log.child({
logLevel,
})(a, b, c, d, e, f, g, h, i, j);
};
};
const createLogger = (onMessage, parentMessageContext = {}, transforms = []) => {

@@ -206,34 +231,16 @@ const log = (a, b, c, d, e, f, g, h, i, j) => {

};
log.trace = (a, b, c, d, e, f, g, h, i, j) => {
log.child({
logLevel: constants_1.logLevels.trace,
})(a, b, c, d, e, f, g, h, i, j);
};
log.debug = (a, b, c, d, e, f, g, h, i, j) => {
log.child({
logLevel: constants_1.logLevels.debug,
})(a, b, c, d, e, f, g, h, i, j);
};
log.info = (a, b, c, d, e, f, g, h, i, j) => {
log.child({
logLevel: constants_1.logLevels.info,
})(a, b, c, d, e, f, g, h, i, j);
};
log.warn = (a, b, c, d, e, f, g, h, i, j) => {
log.child({
logLevel: constants_1.logLevels.warn,
})(a, b, c, d, e, f, g, h, i, j);
};
log.error = (a, b, c, d, e, f, g, h, i, j) => {
log.child({
logLevel: constants_1.logLevels.error,
})(a, b, c, d, e, f, g, h, i, j);
};
log.fatal = (a, b, c, d, e, f, g, h, i, j) => {
log.child({
logLevel: constants_1.logLevels.fatal,
})(a, b, c, d, e, f, g, h, i, j);
};
log.debug = createChildLogger(log, constants_1.logLevels.debug);
log.debugOnce = createOnceChildLogger(log, constants_1.logLevels.debug);
log.error = createChildLogger(log, constants_1.logLevels.error);
log.errorOnce = createOnceChildLogger(log, constants_1.logLevels.error);
log.fatal = createChildLogger(log, constants_1.logLevels.fatal);
log.fatalOnce = createOnceChildLogger(log, constants_1.logLevels.fatal);
log.info = createChildLogger(log, constants_1.logLevels.info);
log.infoOnce = createOnceChildLogger(log, constants_1.logLevels.info);
log.trace = createChildLogger(log, constants_1.logLevels.trace);
log.traceOnce = createOnceChildLogger(log, constants_1.logLevels.trace);
log.warn = createChildLogger(log, constants_1.logLevels.warn);
log.warnOnce = createOnceChildLogger(log, constants_1.logLevels.warn);
return log;
};
exports.createLogger = createLogger;

@@ -1,2 +0,2 @@

import type { Logger, MessageContext, MessageEventHandler } from '../types';
export declare const createMockLogger: (onMessage: MessageEventHandler, parentContext?: MessageContext) => Logger;
import type { Logger, MessageEventHandler } from '../types';
export declare const createMockLogger: (onMessage: MessageEventHandler, parentContext?: import("../types").JsonObject | undefined) => Logger;

@@ -5,2 +5,9 @@ "use strict";

const constants_1 = require("../constants");
const createChildLogger = (log, logLevel) => {
return (a, b, c, d, e, f, g, h, i, j) => {
log.child({
logLevel,
})(a, b, c, d, e, f, g, h, i, j);
};
};
const createMockLogger = (onMessage, parentContext) => {

@@ -19,34 +26,16 @@ const log = () => {

};
log.trace = (a, b, c, d, e, f, g, h, i, j) => {
log.child({
logLevel: constants_1.logLevels.trace,
})(a, b, c, d, e, f, g, h, i, j);
};
log.debug = (a, b, c, d, e, f, g, h, i, j) => {
log.child({
logLevel: constants_1.logLevels.debug,
})(a, b, c, d, e, f, g, h, i, j);
};
log.info = (a, b, c, d, e, f, g, h, i, j) => {
log.child({
logLevel: constants_1.logLevels.info,
})(a, b, c, d, e, f, g, h, i, j);
};
log.warn = (a, b, c, d, e, f, g, h, i, j) => {
log.child({
logLevel: constants_1.logLevels.warn,
})(a, b, c, d, e, f, g, h, i, j);
};
log.error = (a, b, c, d, e, f, g, h, i, j) => {
log.child({
logLevel: constants_1.logLevels.error,
})(a, b, c, d, e, f, g, h, i, j);
};
log.fatal = (a, b, c, d, e, f, g, h, i, j) => {
log.child({
logLevel: constants_1.logLevels.fatal,
})(a, b, c, d, e, f, g, h, i, j);
};
log.debug = createChildLogger(log, constants_1.logLevels.debug);
log.debugOnce = createChildLogger(log, constants_1.logLevels.debug);
log.error = createChildLogger(log, constants_1.logLevels.error);
log.errorOnce = createChildLogger(log, constants_1.logLevels.error);
log.fatal = createChildLogger(log, constants_1.logLevels.fatal);
log.fatalOnce = createChildLogger(log, constants_1.logLevels.fatal);
log.info = createChildLogger(log, constants_1.logLevels.info);
log.infoOnce = createChildLogger(log, constants_1.logLevels.info);
log.trace = createChildLogger(log, constants_1.logLevels.trace);
log.traceOnce = createChildLogger(log, constants_1.logLevels.trace);
log.warn = createChildLogger(log, constants_1.logLevels.warn);
log.warnOnce = createChildLogger(log, constants_1.logLevels.warn);
return log;
};
exports.createMockLogger = createMockLogger;

@@ -21,2 +21,3 @@ "use strict";

let newState = {
onceLog: new Set(),
sequence: 0,

@@ -23,0 +24,0 @@ ...currentState,

@@ -21,2 +21,3 @@ /// <reference types="node" />

asyncLocalStorage?: AsyncLocalStorage<AsyncLocalContext>;
onceLog: Set<string>;
sequence: number;

@@ -48,8 +49,14 @@ serializeMessage?: MessageSerializer;

debug: LogMethod<Z>;
debugOnce: LogMethod<Z>;
error: LogMethod<Z>;
errorOnce: LogMethod<Z>;
fatal: LogMethod<Z>;
fatalOnce: LogMethod<Z>;
getContext: () => MessageContext;
info: LogMethod<Z>;
infoOnce: LogMethod<Z>;
trace: LogMethod<Z>;
traceOnce: LogMethod<Z>;
warn: LogMethod<Z>;
warnOnce: LogMethod<Z>;
};

@@ -56,0 +63,0 @@ export declare type MessageEventHandler = (message: Message<MessageContext>) => void;

@@ -6,7 +6,3 @@ "use strict";

if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {

@@ -13,0 +9,0 @@ if (k2 === undefined) k2 = k;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {

@@ -410,2 +406,18 @@ if (k2 === undefined) k2 = k;

});
(0, ava_1.default)('*Once methods log only once', (t) => {
const log = createLoggerWithHistory();
log.traceOnce('foo');
log.traceOnce('foo');
t.deepEqual(log.messages, [
{
context: {
logLevel: 10,
},
message: 'foo',
sequence: '0',
time,
version,
},
]);
});
(0, ava_1.default)('does not produce an error when message contains % without an associated parameter', (t) => {

@@ -412,0 +424,0 @@ const log = createLoggerWithHistory();

@@ -75,3 +75,3 @@ {

"typings": "./dist/src/Roarr.d.ts",
"version": "7.12.3"
"version": "7.13.0"
}

@@ -29,2 +29,8 @@ <a name="roarr"></a>

* [`fatal`](#roarr-api-fatal)
* [`traceOnce`](#roarr-api-traceonce)
* [`debugOnce`](#roarr-api-debugonce)
* [`infoOnce`](#roarr-api-infoonce)
* [`warnOnce`](#roarr-api-warnonce)
* [`errorOnce`](#roarr-api-erroronce)
* [`fatalOnce`](#roarr-api-fatalonce)
* [Utilities](#roarr-utilities)

@@ -483,2 +489,19 @@ * [`getLogLevelName`](#roarr-utilities-getloglevelname)

<a name="roarr-api-traceonce"></a>
### <code>traceOnce</code>
<a name="roarr-api-debugonce"></a>
### <code>debugOnce</code>
<a name="roarr-api-infoonce"></a>
### <code>infoOnce</code>
<a name="roarr-api-warnonce"></a>
### <code>warnOnce</code>
<a name="roarr-api-erroronce"></a>
### <code>errorOnce</code>
<a name="roarr-api-fatalonce"></a>
### <code>fatalOnce</code>
Just like the regular logger methods, but logs the message only once.
Note: Internally, Roarr keeps a record of the last 1,000 `Once` invocations. If this buffer overflows, then the message is going to be logged again until the next time the buffer overflows again.
<a name="roarr-utilities"></a>

@@ -506,2 +529,3 @@ ## Utilities

```
<a name="roarr-middlewares"></a>

@@ -508,0 +532,0 @@ ## Middlewares

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