Socket
Socket
Sign inDemoInstall

roarr

Package Overview
Dependencies
27
Maintainers
1
Versions
150
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.10.1 to 7.11.0

dist/test/roarr/integrations/serializeMessage.d.ts

2

dist/src/browser.d.ts

@@ -8,3 +8,3 @@ import { logLevels } from './constants';

}>;
export type { Logger, LogLevelName, Message, MessageEventHandler, RoarrGlobalState, TransformMessageFunction, } from './types';
export type { MessageSerializer, Logger, LogLevelName, Message, MessageEventHandler, RoarrGlobalState, TransformMessageFunction, } from './types';
export { getLogLevelName, logLevels, Roarr, ROARR, };

@@ -17,10 +17,13 @@ "use strict";

exports.ROARR = ROARR;
const serializeMessage = (message) => {
return JSON.stringify(message);
};
const Roarr = (0, createLogger_1.createLogger)((message) => {
var _a;
if (ROARR.write) {
// Stringify message as soon as it is received to prevent
// properties of the context from being modified by reference.
const body = JSON.stringify(message);
ROARR.write(body);
ROARR.write(((_a = ROARR.serializeMessage) !== null && _a !== void 0 ? _a : serializeMessage)(message));
}
});
exports.Roarr = Roarr;

@@ -8,3 +8,3 @@ import { logLevels } from './constants';

}>;
export type { Logger, LogLevelName, LogWriter, Message, MessageEventHandler, RoarrGlobalState, TransformMessageFunction, } from './types';
export type { MessageSerializer, Logger, LogLevelName, LogWriter, Message, MessageEventHandler, RoarrGlobalState, TransformMessageFunction, } from './types';
export { getLogLevelName, logLevels, Roarr, ROARR, };

@@ -45,9 +45,13 @@ "use strict";

}
const serializeMessage = (message) => {
return '{"context":' + (0, fast_safe_stringify_1.default)(message.context) + ',' + fastStringify(message).slice(1);
};
const Roarr = logFactory((message) => {
var _a;
if (ROARR.write) {
// Stringify message as soon as it is received to prevent
// properties of the context from being modified by reference.
ROARR.write('{"context":' + (0, fast_safe_stringify_1.default)(message.context) + ',' + fastStringify(message).slice(1));
ROARR.write(((_a = ROARR.serializeMessage) !== null && _a !== void 0 ? _a : serializeMessage)(message));
}
});
exports.Roarr = Roarr;

@@ -18,5 +18,7 @@ /// <reference types="node" />

export declare type AsyncLocalContext = NestedAsyncLocalContext | TopLevelAsyncLocalContext;
export declare type MessageSerializer = (message: Message<MessageContext>) => string;
export declare type RoarrGlobalState = {
asyncLocalStorage?: AsyncLocalStorage<AsyncLocalContext>;
sequence: number;
serializeMessage?: MessageSerializer;
versions: readonly string[];

@@ -23,0 +25,0 @@ write: LogWriter;

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

process.env.ROARR_LOG = writeLogs ? '1' : '0';
// This import is affected by the `process.env.ROARR_LOG` value.
const { Roarr, ROARR, } = await Promise.resolve().then(() => __importStar(require('../../src/Roarr')));

@@ -40,0 +41,0 @@ sinon.restore();

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

"typings": "./dist/src/Roarr.d.ts",
"version": "7.10.1"
"version": "7.11.0"
}

@@ -39,2 +39,3 @@ <a name="roarr"></a>

* [Recipes](#roarr-recipes)
* [Overriding message serializer](#roarr-recipes-overriding-message-serializer)
* [Logging errors](#roarr-recipes-logging-errors)

@@ -637,2 +638,23 @@ * [Anti-patterns](#roarr-anti-patterns)

<a name="roarr-recipes-overriding-message-serializer"></a>
### Overriding message serializer
Roarr is opinionated about how it serializes (converts objects to JSON string) log messages, e.g. in Node.js it uses a schema based serializer, which is very fast, but does not allow custom top-level properties.
You can override this serializer by defining `ROARR.serializeMessage`:
```ts
import type {
MessageEventHandler,
} from 'roarr';
const ROARR = globalThis.ROARR = globalThis.ROARR || {};
const serializeMessage: MessageEventHandler = (message) => {
return JSON.stringify(message);
};
ROARR.serializeMessage = serializeMessage;
```
<a name="roarr-recipes-logging-errors"></a>

@@ -639,0 +661,0 @@ ### Logging errors

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc