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

structured-log

Package Overview
Dependencies
Maintainers
3
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

structured-log - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

src/batchedSink.ts

129

dist/structured-log.es6.js

@@ -5,23 +5,20 @@ /**

if (typeof Object.assign != 'function') {
Object.assign = function (target, varArgs) {
'use strict';
if (target == null) {
throw new TypeError('Cannot convert undefined or null to object');
}
var to = Object(target);
for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];
if (nextSource != null) {
for (var nextKey in nextSource) {
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
Object.assign = function (target, varArgs) {
'use strict';
if (target == null) {
throw new TypeError('Cannot convert undefined or null to object');
}
}
}
return to;
};
var to = Object(target);
for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];
if (nextSource != null) {
for (var nextKey in nextSource) {
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
};
}

@@ -348,2 +345,4 @@

const stub = function () { };
// console.debug is no-op for Node, so use console.log instead.
const nodeConsole = !this.options.console && typeof process !== 'undefined' && process.versions.node;
this.console = {

@@ -353,3 +352,3 @@ error: (internalConsole && (internalConsole.error || internalConsole.log)) || stub,

info: (internalConsole && (internalConsole.info || internalConsole.log)) || stub,
debug: (internalConsole && (internalConsole.debug || internalConsole.log)) || stub,
debug: (internalConsole && ((!nodeConsole && internalConsole.debug) || internalConsole.log)) || stub,
log: (internalConsole && internalConsole.log) || stub

@@ -411,2 +410,81 @@ };

const defaultBatchedSinkOptions = {
maxSize: 100,
period: 5,
durableStore: null
};
class BatchedSink {
constructor(innerSink, options) {
this.durableStorageKey = 'structured-log-batched-sink-durable-cache';
this.innerSink = innerSink || null;
this.options = Object.assign({}, defaultBatchedSinkOptions, (options || {}));
this.batchedEvents = [];
this.cycleBatch();
if (this.options.durableStore) {
let initialBatch = [];
for (const key in this.options.durableStore) {
if (key.indexOf(this.durableStorageKey) === 0) {
const storedEvents = JSON.parse(this.options.durableStore.getItem(key))
.map(e => {
e.messageTemplate = new MessageTemplate(e.messageTemplate.raw);
return e;
});
initialBatch = initialBatch.concat(storedEvents);
this.options.durableStore.removeItem(key);
}
}
this.emit(initialBatch);
}
}
emit(events) {
if (this.batchedEvents.length + events.length <= this.options.maxSize) {
this.batchedEvents.push(...events);
this.storeEvents();
}
else {
let cursor = this.options.maxSize - this.batchedEvents.length;
this.batchedEvents.push(...events.slice(0, cursor));
this.storeEvents();
while (cursor < events.length) {
this.cycleBatch();
this.batchedEvents.push(...events.slice(cursor, cursor = cursor + this.options.maxSize));
this.storeEvents();
}
}
return events;
}
flush() {
this.cycleBatch();
const corePromise = this.flushCore();
return corePromise instanceof Promise ? corePromise : Promise.resolve();
}
emitCore(events) {
return this.innerSink.emit(events);
}
flushCore() {
return this.innerSink.flush();
}
cycleBatch() {
clearTimeout(this.batchTimeout);
if (this.batchedEvents.length) {
const emitPromise = this.emitCore(this.batchedEvents.slice(0));
if (this.options.durableStore) {
const previousBatchKey = this.batchKey;
(emitPromise instanceof Promise ? emitPromise : Promise.resolve())
.then(() => this.options.durableStore.removeItem(previousBatchKey));
}
this.batchedEvents.length = 0;
}
this.batchKey = `${this.durableStorageKey}-${new Date().getTime()}`;
if (!isNaN(this.options.period) && this.options.period > 0) {
this.batchTimeout = setTimeout(() => this.cycleBatch(), this.options.period * 1000);
}
}
storeEvents() {
if (this.options.durableStore) {
this.options.durableStore.setItem(this.batchKey, JSON.stringify(this.batchedEvents));
}
}
}
class FilterStage {

@@ -550,2 +628,3 @@ constructor(predicate) {

const deepClone = (obj) => JSON.parse(JSON.stringify(obj));
class EnrichStage {

@@ -556,4 +635,6 @@ constructor(enricher) {

emit(events) {
const extraProperties = this.enricher instanceof Function ? this.enricher() : this.enricher;
for (let i = 0; i < events.length; ++i) {
const extraProperties = this.enricher instanceof Function
? this.enricher(deepClone(events[i].properties))
: this.enricher;
Object.assign(events[i].properties, extraProperties);

@@ -589,3 +670,3 @@ }

const level = LogEventLevel[levelOrSwitch.toLowerCase()];
if (typeof level === 'undefined') {
if (typeof level === 'undefined' || level === null) {
throw new TypeError('Argument "levelOrSwitch" is not a valid LogEventLevel value.');

@@ -661,3 +742,3 @@ }

export { configure, LoggerConfiguration, LogEventLevel, Logger, ConsoleSink, DynamicLevelSwitch };
export { configure, LoggerConfiguration, LogEventLevel, Logger, ConsoleSink, BatchedSink, DynamicLevelSwitch };
//# sourceMappingURL=structured-log.es6.js.map

179

dist/structured-log.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.structuredLog = global.structuredLog || {})));
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.structuredLog = global.structuredLog || {})));
}(this, (function (exports) { 'use strict';
/**
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
*/
if (typeof Object.assign != 'function') {
Object.assign = function (target, varArgs) {
'use strict';
if (target == null) {
throw new TypeError('Cannot convert undefined or null to object');
}
var to = Object(target);
for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];
if (nextSource != null) {
for (var nextKey in nextSource) {
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
const __assign = Object.assign || function (target) {
for (var source, i = 1; i < arguments.length; i++) {
source = arguments[i];
for (var prop in source) {
if (Object.prototype.hasOwnProperty.call(source, prop)) {
target[prop] = source[prop];
}
}
}
}
return to;
};
}
return target;
};

@@ -41,2 +26,26 @@ function __extends(d, b) {

/**
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
*/
if (typeof Object.assign != 'function') {
Object.assign = function (target, varArgs) {
'use strict';
if (target == null) {
throw new TypeError('Cannot convert undefined or null to object');
}
var to = Object(target);
for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];
if (nextSource != null) {
for (var nextKey in nextSource) {
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
};
}
/**
* Represents the severity level of a log event.

@@ -66,3 +75,3 @@ */

*/
var LogEvent = (function () {
var LogEvent = /** @class */ (function () {
/**

@@ -85,3 +94,3 @@ * Creates a new log event instance.

*/
var MessageTemplate = (function () {
var MessageTemplate = /** @class */ (function () {
/**

@@ -229,3 +238,3 @@ * Creates a new MessageTemplate instance with the given template.

*/
var Logger = (function () {
var Logger = /** @class */ (function () {
/**

@@ -385,3 +394,3 @@ * Creates a new logger instance using the specified pipeline.

var ConsoleSink = (function () {
var ConsoleSink = /** @class */ (function () {
function ConsoleSink(options) {

@@ -391,2 +400,4 @@ this.options = options || {};

var stub = function () { };
// console.debug is no-op for Node, so use console.log instead.
var nodeConsole = !this.options.console && typeof process !== 'undefined' && process.versions.node;
this.console = {

@@ -396,3 +407,3 @@ error: (internalConsole && (internalConsole.error || internalConsole.log)) || stub,

info: (internalConsole && (internalConsole.info || internalConsole.log)) || stub,
debug: (internalConsole && (internalConsole.debug || internalConsole.log)) || stub,
debug: (internalConsole && ((!nodeConsole && internalConsole.debug) || internalConsole.log)) || stub,
log: (internalConsole && internalConsole.log) || stub

@@ -455,3 +466,85 @@ };

var FilterStage = (function () {
var defaultBatchedSinkOptions = {
maxSize: 100,
period: 5,
durableStore: null
};
var BatchedSink = /** @class */ (function () {
function BatchedSink(innerSink, options) {
this.durableStorageKey = 'structured-log-batched-sink-durable-cache';
this.innerSink = innerSink || null;
this.options = __assign({}, defaultBatchedSinkOptions, (options || {}));
this.batchedEvents = [];
this.cycleBatch();
if (this.options.durableStore) {
var initialBatch = [];
for (var key in this.options.durableStore) {
if (key.indexOf(this.durableStorageKey) === 0) {
var storedEvents = JSON.parse(this.options.durableStore.getItem(key))
.map(function (e) {
e.messageTemplate = new MessageTemplate(e.messageTemplate.raw);
return e;
});
initialBatch = initialBatch.concat(storedEvents);
this.options.durableStore.removeItem(key);
}
}
this.emit(initialBatch);
}
}
BatchedSink.prototype.emit = function (events) {
if (this.batchedEvents.length + events.length <= this.options.maxSize) {
(_a = this.batchedEvents).push.apply(_a, events);
this.storeEvents();
}
else {
var cursor = this.options.maxSize - this.batchedEvents.length;
(_b = this.batchedEvents).push.apply(_b, events.slice(0, cursor));
this.storeEvents();
while (cursor < events.length) {
this.cycleBatch();
(_c = this.batchedEvents).push.apply(_c, events.slice(cursor, cursor = cursor + this.options.maxSize));
this.storeEvents();
}
}
return events;
var _a, _b, _c;
};
BatchedSink.prototype.flush = function () {
this.cycleBatch();
var corePromise = this.flushCore();
return corePromise instanceof Promise ? corePromise : Promise.resolve();
};
BatchedSink.prototype.emitCore = function (events) {
return this.innerSink.emit(events);
};
BatchedSink.prototype.flushCore = function () {
return this.innerSink.flush();
};
BatchedSink.prototype.cycleBatch = function () {
var _this = this;
clearTimeout(this.batchTimeout);
if (this.batchedEvents.length) {
var emitPromise = this.emitCore(this.batchedEvents.slice(0));
if (this.options.durableStore) {
var previousBatchKey_1 = this.batchKey;
(emitPromise instanceof Promise ? emitPromise : Promise.resolve())
.then(function () { return _this.options.durableStore.removeItem(previousBatchKey_1); });
}
this.batchedEvents.length = 0;
}
this.batchKey = this.durableStorageKey + "-" + new Date().getTime();
if (!isNaN(this.options.period) && this.options.period > 0) {
this.batchTimeout = setTimeout(function () { return _this.cycleBatch(); }, this.options.period * 1000);
}
};
BatchedSink.prototype.storeEvents = function () {
if (this.options.durableStore) {
this.options.durableStore.setItem(this.batchKey, JSON.stringify(this.batchedEvents));
}
};
return BatchedSink;
}());
var FilterStage = /** @class */ (function () {
function FilterStage(predicate) {

@@ -472,3 +565,3 @@ this.predicate = predicate;

*/
var DynamicLevelSwitch = (function () {
var DynamicLevelSwitch = /** @class */ (function () {
function DynamicLevelSwitch() {

@@ -515,3 +608,3 @@ this.minLevel = null;

}());
var DynamicLevelSwitchStage = (function (_super) {
var DynamicLevelSwitchStage = /** @class */ (function (_super) {
__extends(DynamicLevelSwitchStage, _super);

@@ -532,3 +625,3 @@ function DynamicLevelSwitchStage(dynamicLevelSwitch) {

var Pipeline = (function () {
var Pipeline = /** @class */ (function () {
function Pipeline() {

@@ -605,3 +698,3 @@ this.stages = [];

var SinkStage = (function () {
var SinkStage = /** @class */ (function () {
function SinkStage(sink) {

@@ -620,3 +713,4 @@ this.sink = sink;

var EnrichStage = (function () {
var deepClone = function (obj) { return JSON.parse(JSON.stringify(obj)); };
var EnrichStage = /** @class */ (function () {
function EnrichStage(enricher) {

@@ -626,4 +720,6 @@ this.enricher = enricher;

EnrichStage.prototype.emit = function (events) {
var extraProperties = this.enricher instanceof Function ? this.enricher() : this.enricher;
for (var i = 0; i < events.length; ++i) {
var extraProperties = this.enricher instanceof Function
? this.enricher(deepClone(events[i].properties))
: this.enricher;
Object.assign(events[i].properties, extraProperties);

@@ -642,3 +738,3 @@ }

*/
var LoggerConfiguration = (function () {
var LoggerConfiguration = /** @class */ (function () {
function LoggerConfiguration() {

@@ -662,3 +758,3 @@ var _this = this;

var level_1 = exports.LogEventLevel[levelOrSwitch.toLowerCase()];
if (typeof level_1 === 'undefined') {
if (typeof level_1 === 'undefined' || level_1 === null) {
throw new TypeError('Argument "levelOrSwitch" is not a valid LogEventLevel value.');

@@ -739,2 +835,3 @@ }

exports.ConsoleSink = ConsoleSink;
exports.BatchedSink = BatchedSink;
exports.DynamicLevelSwitch = DynamicLevelSwitch;

@@ -741,0 +838,0 @@

{
"name": "structured-log",
"version": "0.1.0",
"version": "0.2.0",
"description": "A structured logging framework for JavaScript, inspired by Serilog.",

@@ -8,4 +8,5 @@ "main": "dist/structured-log.js",

"scripts": {
"test": "mocha --compilers ts:ts-node/register -r src/polyfills/objectAssign.js test/**/*.spec.ts",
"test-coverage": "ts-node node_modules/istanbul/lib/cli.js cover -e .ts -x \"*.d.ts\" -x \"*.spec.ts\" node_modules/mocha/bin/_mocha -- -r src/polyfills/objectAssign.js test/**/*.spec.ts",
"test": "jest",
"test-watch": "jest --watch",
"test-coverage": "jest --coverage",
"build-es5": "rollup -c rollup.config.es5.js",

@@ -16,2 +17,15 @@ "build-es6": "rollup -c rollup.config.es6.js",

},
"jest": {
"transform": {
"^.+\\.tsx?$": "./node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json"
]
},
"repository": {

@@ -34,11 +48,14 @@ "type": "git",

"@types/chai": "^3.4.34",
"@types/mocha": "^2.2.35",
"@types/es6-promise": "0.0.32",
"@types/jest": "^21.1.1",
"@types/node": "^6.0.57",
"chai": "^3.5.0",
"coveralls": "^2.11.15",
"istanbul": "^1.1.0-alpha.1",
"mocha": "^3.2.0",
"es6-promise": "^4.0.5",
"es6-symbol": "^3.1.0",
"jest": "^21.1.0",
"rollup": "^0.40.1",
"rollup-plugin-typescript": "^0.8.1",
"ts-node": "^2.0.0",
"ts-jest": "^21.0.1",
"ts-node": "^3.0.0",
"typemoq": "^1.1.0",

@@ -45,0 +62,0 @@ "typescript": "^2.1.4"

@@ -5,6 +5,5 @@ # structured-log

|Branch|Status|
|---|---|---|
|`master`|[![Build Status](https://travis-ci.org/structured-log/structured-log.svg?branch=master)](https://travis-ci.org/structured-log/structured-log)|
|`dev`|[![Build Status](https://travis-ci.org/structured-log/structured-log.svg?branch=dev)](https://travis-ci.org/structured-log/structured-log)|
[![npm](https://img.shields.io/npm/v/structured-log.svg)](https://www.npmjs.com/package/structured-log)
[![Bower](https://img.shields.io/bower/v/structured-log.svg)]()
[![Build Status](https://travis-ci.org/structured-log/structured-log.svg?branch=master)](https://travis-ci.org/structured-log/structured-log)

@@ -31,2 +30,6 @@ ## Basic Example

yarn add structured-log
If not using Yarn:
npm i --save structured-log

@@ -227,2 +230,21 @@

The enricher function will receive a copy of the event properties as its first argument, so that you can conditionally mask
sensitive information from the event. This can be useful when you want to log detailed information in your local console, but not to external sinks further down the pipeline.
```js
log.info('Incorrect client secret: {Secret}', secret});
// ...
.enrich((properties) => {
if (properties.secret) {
return {
secret: 'MASKED'
};
}
})
```
> The `properties` argument is a deep clone of the event properties, and cannot be used to manipulate the source object directly (e.g. `delete properties.secret`).
### Errors

@@ -249,3 +271,3 @@

```js
var consoleSink = new structuredLog.ConsoleSink({ /* options */ });
var consoleSink = new ConsoleSink({ /* options */ });
```

@@ -256,7 +278,50 @@

|Key|Description|
|---|---|
|console|An object with a console interface (providing `log()`, `info()`, etc.) that will be used by the sink when writing output. The global `console` object will be used by default.|
|includeProperties|If `true`, the properties of the log event will be written to the console in addition to the message. Defaults to `false`.|
|includeTimestamps|If `true`, timestamps will be included in the message that is written to the console. Defaults to `false`.|
|restrictedToMinimumLevel|If set, only events of the specified level or higher will be output to the console.|
|Key|Description|Default|
|---|---|---|
|`console`|An object with a console interface (providing `log()`, `info()`, etc.) that will be used by the sink when writing output.|`console` global|
|`includeProperties`|If `true`, the properties of the log event will be written to the console in addition to the message.|`false`|
|`includeTimestamps`|If `true`, timestamps will be included in the message that is written to the console.|`false`|
|`restrictedToMinimumLevel`|If set, only events of the specified level or higher will be output to the console.||
### Batched Sink
The `BatchedSink` allows for batching events periodically and/or by batch size.
It can either be used as a wrapper around existing sinks:
```js
var batchedSink = new BatchedSink(new ConsoleSink(), { /* options */ });
```
Or, if developing a sink and using ES6 or TypeScript, you can use it as a base class to add batching capabilities:
```js
class MySink extends BatchedSink {
constructor() {
super(null, { /* options */ });
}
// Override emitCore and/or flushCore to add your own sink's behavior
emitCore(events) {
// ...
}
flushCore() {
// ...
return Promise.resolve();
// If you don't return a promise,
// a resolved promise will be returned for you
}
}
```
The `options` object is optional, but can be used to modify the batching thresholds or add durability to the sink.
It supports the following properties:
|Key|Description|Default|
|---|---|---|
|`durableStore`|An instance implementing the [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API) interface (such as `localStorage` in the browser, or [node-localstorage](https://github.com/lmaccherone/node-localstorage) for Node.js applications). If this is set, it will be used as an intermediate store for events until they have been successfully flushed through the pipeline.|`null`|
|`maxSize`|The maximum number of events in a single batch. The sink will be flushed immediately when this limit is hit.|`100`|
|`period`|The interval for autmoatic flushing of batches, in seconds.|`10`|

@@ -28,2 +28,6 @@ import { LogEventLevel, LogEvent, isEnabled } from './logEvent';

const stub = function () { };
// console.debug is no-op for Node, so use console.log instead.
const nodeConsole = !this.options.console && typeof process !== 'undefined' && process.versions.node;
this.console = {

@@ -33,3 +37,3 @@ error: (internalConsole && (internalConsole.error || internalConsole.log)) || stub,

info: (internalConsole && (internalConsole.info || internalConsole.log)) || stub,
debug: (internalConsole && (internalConsole.debug || internalConsole.log)) || stub,
debug: (internalConsole && ((!nodeConsole && internalConsole.debug) || internalConsole.log)) || stub,
log: (internalConsole && internalConsole.log) || stub

@@ -36,0 +40,0 @@ };

import { PipelineStage } from './pipeline';
import { LogEvent } from './logEvent';
export type ObjectFactory = () => Object;
const deepClone = (obj: any) => JSON.parse(JSON.stringify(obj));
export type ObjectFactory = (properties?: Object) => Object;
export class EnrichStage implements PipelineStage {

@@ -14,4 +16,6 @@ private enricher: Object | ObjectFactory;

emit(events: LogEvent[]): LogEvent[] {
const extraProperties = this.enricher instanceof Function ? this.enricher() : this.enricher;
for (let i = 0; i < events.length; ++i) {
const extraProperties = this.enricher instanceof Function
? this.enricher(deepClone(events[i].properties))
: this.enricher;
Object.assign(events[i].properties, extraProperties);

@@ -18,0 +22,0 @@ }

@@ -6,2 +6,3 @@ import './polyfills/objectAssign';

export { ConsoleSink } from './consoleSink';
export { BatchedSink } from './batchedSink';
export { DynamicLevelSwitch } from './dynamicLevelSwitch';

@@ -8,0 +9,0 @@

@@ -37,3 +37,3 @@ import { LogEventLevel, LogEvent } from './logEvent';

fatal(errorOrMessageTemplate: any, ...properties: any[]) {
fatal(errorOrMessageTemplate: Error | string, ...properties: any[]) {
try {

@@ -67,3 +67,3 @@ if (errorOrMessageTemplate instanceof Error) {

error(errorOrMessageTemplate: any, ...properties: any[]) {
error(errorOrMessageTemplate: Error | string, ...properties: any[]) {
try {

@@ -97,3 +97,3 @@ if (errorOrMessageTemplate instanceof Error) {

warn(errorOrMessageTemplate: any, ...properties: any[]) {
warn(errorOrMessageTemplate: Error | string, ...properties: any[]) {
try {

@@ -127,3 +127,3 @@ if (errorOrMessageTemplate instanceof Error) {

info(errorOrMessageTemplate: any, ...properties: any[]) {
info(errorOrMessageTemplate: Error | string, ...properties: any[]) {
try {

@@ -157,3 +157,3 @@ if (errorOrMessageTemplate instanceof Error) {

debug(errorOrMessageTemplate: any, ...properties: any[]) {
debug(errorOrMessageTemplate: Error | string, ...properties: any[]) {
try {

@@ -187,3 +187,3 @@ if (errorOrMessageTemplate instanceof Error) {

verbose(errorOrMessageTemplate: any, ...properties: any[]) {
verbose(errorOrMessageTemplate: Error | string, ...properties: any[]) {
try {

@@ -190,0 +190,0 @@ if (errorOrMessageTemplate instanceof Error) {

@@ -48,3 +48,3 @@ import { Pipeline } from './pipeline';

const level = <LogEventLevel>LogEventLevel[levelOrSwitch.toLowerCase()];
if (typeof level === 'undefined') {
if (typeof level === 'undefined' || level === null) {
throw new TypeError('Argument "levelOrSwitch" is not a valid LogEventLevel value.');

@@ -51,0 +51,0 @@ }

/// <reference path="../node_modules/@types/node/index.d.ts" />
/// <reference path="../node_modules/@types/mocha/index.d.ts" />
/// <reference path="../node_modules/@types/jest/index.d.ts" />
/// <reference path="../node_modules/typemoq/dist/typemoq.d.ts" />

@@ -11,2 +11,3 @@

import { MessageTemplate } from '../src/messageTemplate';
import { ConcreteConsoleProxy } from './helpers';

@@ -16,3 +17,3 @@ describe('ConsoleSink', () => {

it('logs error messages', () => {
const consoleProxy = TypeMoq.Mock.ofType<ConsoleProxy>();
const consoleProxy = TypeMoq.Mock.ofType(ConcreteConsoleProxy);
const consoleSink = new ConsoleSink({ console: consoleProxy.object });

@@ -27,3 +28,3 @@ consoleSink.emit([

it('logs warning messages', () => {
const consoleProxy = TypeMoq.Mock.ofType<ConsoleProxy>();
const consoleProxy = TypeMoq.Mock.ofType(ConcreteConsoleProxy);
const consoleSink = new ConsoleSink({ console: consoleProxy.object });

@@ -37,3 +38,3 @@ consoleSink.emit([

it('logs info messages', () => {
const consoleProxy = TypeMoq.Mock.ofType<ConsoleProxy>();
const consoleProxy = TypeMoq.Mock.ofType(ConcreteConsoleProxy);
const consoleSink = new ConsoleSink({ console: consoleProxy.object });

@@ -47,3 +48,3 @@ consoleSink.emit([

it('logs debug and verbose messages', () => {
const consoleProxy = TypeMoq.Mock.ofType<ConsoleProxy>();
const consoleProxy = TypeMoq.Mock.ofType(ConcreteConsoleProxy);
const consoleSink = new ConsoleSink({ console: consoleProxy.object });

@@ -58,3 +59,3 @@ consoleSink.emit([

it('logs messages with an unknown log level', () => {
const consoleProxy = TypeMoq.Mock.ofType<ConsoleProxy>();
const consoleProxy = TypeMoq.Mock.ofType(ConcreteConsoleProxy);
const consoleSink = new ConsoleSink({ console: consoleProxy.object });

@@ -71,3 +72,3 @@ consoleSink.emit([

let loggedError: Error;
const consoleProxy = TypeMoq.Mock.ofType<ConsoleProxy>();
const consoleProxy = TypeMoq.Mock.ofType(ConcreteConsoleProxy);
consoleProxy.setup(m => m.info(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))

@@ -74,0 +75,0 @@ .callback((message, property, newline, error) => {

/// <reference path="../node_modules/@types/node/index.d.ts" />
/// <reference path="../node_modules/@types/mocha/index.d.ts" />
/// <reference path="../node_modules/@types/jest/index.d.ts" />
/// <reference path="../node_modules/typemoq/dist/typemoq.d.ts" />

@@ -4,0 +4,0 @@

/// <reference path="../node_modules/@types/node/index.d.ts" />
/// <reference path="../node_modules/@types/mocha/index.d.ts" />
/// <reference path="../node_modules/@types/jest/index.d.ts" />
/// <reference path="../node_modules/typemoq/dist/typemoq.d.ts" />

@@ -24,2 +24,35 @@

it('passes the event properties to the enricher to allow conditional masking', () => {
const enricherParams = [];
const enricher = (properties) => {
if (properties.password) {
return {
password: 'REDACTED'
};
}
};
const enrichStage = new EnrichStage(enricher);
const events = [
new LogEvent('', LogEventLevel.information, new MessageTemplate('Message 1'), { a: 1, password: 'secret' }),
];
const enrichedEvents = enrichStage.emit(events);
expect(enrichedEvents).to.have.length(1);
expect(enrichedEvents[0]).to.have.deep.property('properties.password', 'REDACTED');
expect(enrichedEvents[0]).to.have.deep.property('properties.a', 1);
});
it('does not allow direct manipulation of the event properties', () => {
const enricherParams = [];
const enricher = (properties) => {
delete properties.password;
};
const enrichStage = new EnrichStage(enricher);
const events = [
new LogEvent('', LogEventLevel.information, new MessageTemplate('Message 1'), { password: 'secret' }),
];
const enrichedEvents = enrichStage.emit(events);
expect(enrichedEvents).to.have.length(1);
expect(enrichedEvents[0]).to.have.deep.property('properties.password', 'secret');
});
it('enriches events with properties from a plain object', () => {

@@ -26,0 +59,0 @@ const enricher = { b: 2 };

/// <reference path="../node_modules/@types/node/index.d.ts" />
/// <reference path="../node_modules/@types/mocha/index.d.ts" />
/// <reference path="../node_modules/@types/jest/index.d.ts" />
/// <reference path="../node_modules/typemoq/dist/typemoq.d.ts" />

@@ -4,0 +4,0 @@

/// <reference path="../node_modules/@types/node/index.d.ts" />
/// <reference path="../node_modules/@types/mocha/index.d.ts" />
/// <reference path="../node_modules/@types/jest/index.d.ts" />
/// <reference path="../node_modules/typemoq/dist/typemoq.d.ts" />

@@ -4,0 +4,0 @@

/// <reference path="../node_modules/@types/node/index.d.ts" />
/// <reference path="../node_modules/@types/mocha/index.d.ts" />
/// <reference path="../node_modules/@types/jest/index.d.ts" />
/// <reference path="../node_modules/typemoq/dist/typemoq.d.ts" />

@@ -4,0 +4,0 @@

/// <reference path="../node_modules/@types/node/index.d.ts" />
/// <reference path="../node_modules/@types/mocha/index.d.ts" />
/// <reference path="../node_modules/@types/jest/index.d.ts" />
/// <reference path="../node_modules/typemoq/dist/typemoq.d.ts" />

@@ -18,3 +18,3 @@

it('logs with fatal severity', () => {
const mockPipeline = TypeMoq.Mock.ofType<Pipeline>();
const mockPipeline = TypeMoq.Mock.ofType(Pipeline);
mockPipeline.setup(m => m.emit(TypeMoq.It.is(verifyLevel(LogEventLevel.fatal))));

@@ -27,3 +27,3 @@ const logger = new Logger(mockPipeline.object);

it('logs with error severity', () => {
const mockPipeline = TypeMoq.Mock.ofType<Pipeline>();
const mockPipeline = TypeMoq.Mock.ofType(Pipeline);
mockPipeline.setup(m => m.emit(TypeMoq.It.is(verifyLevel(LogEventLevel.error))));

@@ -36,3 +36,3 @@ const logger = new Logger(mockPipeline.object);

it('logs with warning severity', () => {
const mockPipeline = TypeMoq.Mock.ofType<Pipeline>();
const mockPipeline = TypeMoq.Mock.ofType(Pipeline);
mockPipeline.setup(m => m.emit(TypeMoq.It.is(verifyLevel(LogEventLevel.warning))));

@@ -45,3 +45,3 @@ const logger = new Logger(mockPipeline.object);

it('logs with information severity', () => {
const mockPipeline = TypeMoq.Mock.ofType<Pipeline>();
const mockPipeline = TypeMoq.Mock.ofType(Pipeline);
mockPipeline.setup(m => m.emit(TypeMoq.It.is(verifyLevel(LogEventLevel.information))));

@@ -54,3 +54,3 @@ const logger = new Logger(mockPipeline.object);

it('logs with debug severity', () => {
const mockPipeline = TypeMoq.Mock.ofType<Pipeline>();
const mockPipeline = TypeMoq.Mock.ofType(Pipeline);
mockPipeline.setup(m => m.emit(TypeMoq.It.is(verifyLevel(LogEventLevel.debug))));

@@ -63,3 +63,3 @@ const logger = new Logger(mockPipeline.object);

it('logs with verbose severity', () => {
const mockPipeline = TypeMoq.Mock.ofType<Pipeline>();
const mockPipeline = TypeMoq.Mock.ofType(Pipeline);
mockPipeline.setup(m => m.emit(TypeMoq.It.is(verifyLevel(LogEventLevel.verbose))));

@@ -73,3 +73,3 @@ const logger = new Logger(mockPipeline.object);

let loggedEvents = [];
const mockPipeline = TypeMoq.Mock.ofType<Pipeline>();
const mockPipeline = TypeMoq.Mock.ofType(Pipeline);
mockPipeline.setup(m => m.emit(TypeMoq.It.is(verifyLevel(LogEventLevel.information))))

@@ -86,3 +86,3 @@ .callback(events => loggedEvents = loggedEvents.concat(events));

const error = new Error('Sample');
const mockPipeline = TypeMoq.Mock.ofType<Pipeline>();
const mockPipeline = TypeMoq.Mock.ofType(Pipeline);
mockPipeline.setup(m => m.emit(TypeMoq.It.isAny()))

@@ -108,4 +108,4 @@ .callback(events => loggedEvents = loggedEvents.concat(events));

let loggedEvents = [];
const mockPipeline = TypeMoq.Mock.ofType<Pipeline>();
const logger = new Logger(TypeMoq.Mock.ofType<Pipeline>().object);
const mockPipeline = TypeMoq.Mock.ofType(Pipeline);
const logger = new Logger(TypeMoq.Mock.ofType(Pipeline).object);
expect(() => logger.fatal(undefined)).to.not.throw();

@@ -121,4 +121,4 @@ expect(() => logger.error(undefined)).to.not.throw();

let loggedEvents = [];
const mockPipeline = TypeMoq.Mock.ofType<Pipeline>();
const logger = new Logger(TypeMoq.Mock.ofType<Pipeline>().object, false);
const mockPipeline = TypeMoq.Mock.ofType(Pipeline);
const logger = new Logger(TypeMoq.Mock.ofType(Pipeline).object, false);
expect(() => logger.fatal(undefined)).to.throw();

@@ -134,3 +134,3 @@ expect(() => logger.error(undefined)).to.throw();

it('emits events to the pipeline', () => {
const mockPipeline = TypeMoq.Mock.ofType<Pipeline>();
const mockPipeline = TypeMoq.Mock.ofType(Pipeline);
mockPipeline.setup(m => m.emit(TypeMoq.It.isAny()));

@@ -143,3 +143,3 @@ const logger = new Logger(mockPipeline.object);

it('catches errors when suppressed', () => {
const mockPipeline = TypeMoq.Mock.ofType<Pipeline>();
const mockPipeline = TypeMoq.Mock.ofType(Pipeline);
mockPipeline.setup(m => m.emit(TypeMoq.It.isAny())).throws(new Error('Error'));

@@ -151,3 +151,3 @@ const logger = new Logger(mockPipeline.object);

it('throws errors when not suppressed', () => {
const mockPipeline = TypeMoq.Mock.ofType<Pipeline>();
const mockPipeline = TypeMoq.Mock.ofType(Pipeline);
mockPipeline.setup(m => m.emit(TypeMoq.It.isAny())).throws(new Error('Error'));

@@ -161,3 +161,3 @@ const logger = new Logger(mockPipeline.object, false);

it('flushes the pipeline', () => {
const mockPipeline = TypeMoq.Mock.ofType<Pipeline>();
const mockPipeline = TypeMoq.Mock.ofType(Pipeline);
mockPipeline.setup(m => m.flush()).returns(() => Promise.resolve());

@@ -170,3 +170,3 @@ const logger = new Logger(mockPipeline.object);

it('catches errors when suppressed', () => {
const mockPipeline = TypeMoq.Mock.ofType<Pipeline>();
const mockPipeline = TypeMoq.Mock.ofType(Pipeline);
mockPipeline.setup(m => m.flush()).returns(() => Promise.reject('Error'));

@@ -178,3 +178,3 @@ const logger = new Logger(mockPipeline.object);

it('throws errors when not suppressed', () => {
const mockPipeline = TypeMoq.Mock.ofType<Pipeline>();
const mockPipeline = TypeMoq.Mock.ofType(Pipeline);
mockPipeline.setup(m => m.flush()).returns(() => Promise.reject('Error'));

@@ -181,0 +181,0 @@ const logger = new Logger(mockPipeline.object, false);

/// <reference path="../node_modules/@types/node/index.d.ts" />
/// <reference path="../node_modules/@types/mocha/index.d.ts" />
/// <reference path="../node_modules/@types/jest/index.d.ts" />
/// <reference path="../node_modules/typemoq/dist/typemoq.d.ts" />

@@ -13,2 +13,3 @@

import { DynamicLevelSwitch } from '../src/dynamicLevelSwitch';
import { ConcreteSink } from './helpers';

@@ -27,3 +28,3 @@ describe('LoggerConfiguration', () => {

let emittedEvents = [];
const sink = TypeMoq.Mock.ofType<Sink>();
const sink = TypeMoq.Mock.ofType(ConcreteSink);
sink.setup(m => m.emit(TypeMoq.It.isAny())).callback(events => emittedEvents = emittedEvents.concat(events));

@@ -55,3 +56,3 @@

let emittedEvents = [];
const sink = TypeMoq.Mock.ofType<Sink>();
const sink = TypeMoq.Mock.ofType(ConcreteSink);
sink.setup(m => m.emit(TypeMoq.It.isAny())).callback(events => emittedEvents = emittedEvents.concat(events));

@@ -91,3 +92,3 @@

let emittedEvents = [];
const sink = TypeMoq.Mock.ofType<Sink>();
const sink = TypeMoq.Mock.ofType(ConcreteSink);
sink.setup(m => m.emit(TypeMoq.It.isAny())).callback(events => emittedEvents = emittedEvents.concat(events));

@@ -113,3 +114,3 @@

let emittedEvents = [];
const sink = TypeMoq.Mock.ofType<Sink>();
const sink = TypeMoq.Mock.ofType(ConcreteSink);
sink.setup(m => m.emit(TypeMoq.It.isAny())).callback(events => emittedEvents = emittedEvents.concat(events));

@@ -136,3 +137,3 @@

let emittedEvents = [];
const sink = TypeMoq.Mock.ofType<Sink>();
const sink = TypeMoq.Mock.ofType(ConcreteSink);
sink.setup(m => m.emit(TypeMoq.It.isAny())).callback(events => emittedEvents = emittedEvents.concat(events));

@@ -163,3 +164,3 @@

let emittedEvents = [];
const sink = TypeMoq.Mock.ofType<Sink>();
const sink = TypeMoq.Mock.ofType(ConcreteSink);
sink.setup(m => m.emit(TypeMoq.It.isAny())).callback(events => emittedEvents = emittedEvents.concat(events));

@@ -192,3 +193,3 @@

let emittedEvents = [];
const sink = TypeMoq.Mock.ofType<Sink>();
const sink = TypeMoq.Mock.ofType(ConcreteSink);
sink.setup(m => m.emit(TypeMoq.It.isAny())).callback(events => emittedEvents = emittedEvents.concat(events));

@@ -212,3 +213,3 @@

let emittedEvents = [];
const sink = TypeMoq.Mock.ofType<Sink>();
const sink = TypeMoq.Mock.ofType(ConcreteSink);
sink.setup(m => m.emit(TypeMoq.It.isAny())).callback(events => emittedEvents = emittedEvents.concat(events));

@@ -232,3 +233,3 @@

let emittedEvents = [];
const sink = TypeMoq.Mock.ofType<Sink>();
const sink = TypeMoq.Mock.ofType(ConcreteSink);
sink.setup(m => m.emit(TypeMoq.It.isAny())).callback(events => emittedEvents = emittedEvents.concat(events));

@@ -252,3 +253,3 @@

let emittedEvents = [];
const sink = TypeMoq.Mock.ofType<Sink>();
const sink = TypeMoq.Mock.ofType(ConcreteSink);
sink.setup(m => m.emit(TypeMoq.It.isAny())).callback(events => emittedEvents = emittedEvents.concat(events));

@@ -272,3 +273,3 @@

let emittedEvents = [];
const sink = TypeMoq.Mock.ofType<Sink>();
const sink = TypeMoq.Mock.ofType(ConcreteSink);
sink.setup(m => m.emit(TypeMoq.It.isAny())).callback(events => emittedEvents = emittedEvents.concat(events));

@@ -292,3 +293,3 @@

let emittedEvents = [];
const sink = TypeMoq.Mock.ofType<Sink>();
const sink = TypeMoq.Mock.ofType(ConcreteSink);
sink.setup(m => m.emit(TypeMoq.It.isAny())).callback(events => emittedEvents = emittedEvents.concat(events));

@@ -350,3 +351,3 @@

let emittedEvents = [];
const sink = TypeMoq.Mock.ofType<Sink>();
const sink = TypeMoq.Mock.ofType(ConcreteSink);
sink.setup(m => m.emit(TypeMoq.It.isAny())).callback(events => emittedEvents = emittedEvents.concat(events));

@@ -353,0 +354,0 @@

/// <reference path="../node_modules/@types/node/index.d.ts" />
/// <reference path="../node_modules/@types/mocha/index.d.ts" />
/// <reference path="../node_modules/@types/jest/index.d.ts" />
/// <reference path="../node_modules/typemoq/dist/typemoq.d.ts" />

@@ -4,0 +4,0 @@

/// <reference path="../node_modules/@types/node/index.d.ts" />
/// <reference path="../node_modules/@types/mocha/index.d.ts" />
/// <reference path="../node_modules/@types/jest/index.d.ts" />
/// <reference path="../node_modules/typemoq/dist/typemoq.d.ts" />

@@ -11,2 +11,3 @@

import { MessageTemplate } from '../src/messageTemplate';
import { ConcretePipelineStage } from './helpers';

@@ -18,5 +19,5 @@ describe('Pipeline', () => {

const pipeline = new Pipeline();
const pipelineStage1 = TypeMoq.Mock.ofType<PipelineStage>();
const pipelineStage2 = TypeMoq.Mock.ofType<PipelineStage>();
const pipelineStage3 = TypeMoq.Mock.ofType<PipelineStage>();
const pipelineStage1 = TypeMoq.Mock.ofType(ConcretePipelineStage);
const pipelineStage2 = TypeMoq.Mock.ofType(ConcretePipelineStage);
const pipelineStage3 = TypeMoq.Mock.ofType(ConcretePipelineStage);
pipelineStage1.setup(m => m.emit(TypeMoq.It.isAny())).returns(events => events);

@@ -44,4 +45,4 @@ pipelineStage2.setup(m => m.emit(TypeMoq.It.isAny())).returns(events => events);

const pipeline = new Pipeline();
const pipelineStage1 = TypeMoq.Mock.ofType<PipelineStage>();
const pipelineStage2 = TypeMoq.Mock.ofType<PipelineStage>();
const pipelineStage1 = TypeMoq.Mock.ofType(ConcretePipelineStage);
const pipelineStage2 = TypeMoq.Mock.ofType(ConcretePipelineStage);
pipelineStage1.setup(m => m.emit(TypeMoq.It.isAny())).returns(events => events);

@@ -78,5 +79,5 @@ pipelineStage1.setup(m => m.flush()).returns(() => new Promise(resolve => setTimeout(resolve, 1)));

const pipeline = new Pipeline();
const pipelineStage1 = TypeMoq.Mock.ofType<PipelineStage>();
const pipelineStage2 = TypeMoq.Mock.ofType<PipelineStage>();
const pipelineStage3 = TypeMoq.Mock.ofType<PipelineStage>();
const pipelineStage1 = TypeMoq.Mock.ofType(ConcretePipelineStage);
const pipelineStage2 = TypeMoq.Mock.ofType(ConcretePipelineStage);
const pipelineStage3 = TypeMoq.Mock.ofType(ConcretePipelineStage);
pipelineStage1.setup(m => m.flush()).returns(() => Promise.resolve());

@@ -97,4 +98,4 @@ pipelineStage2.setup(m => m.flush()).returns(() => Promise.resolve());

const pipeline = new Pipeline();
const pipelineStage1 = TypeMoq.Mock.ofType<PipelineStage>();
const pipelineStage2 = TypeMoq.Mock.ofType<PipelineStage>();
const pipelineStage1 = TypeMoq.Mock.ofType(ConcretePipelineStage);
const pipelineStage2 = TypeMoq.Mock.ofType(ConcretePipelineStage);
pipelineStage1.setup(m => m.flush()).returns(() => new Promise(resolve => setTimeout(resolve, 1)));

@@ -101,0 +102,0 @@ pipelineStage2.setup(m => m.flush()).returns(() => Promise.resolve());

/// <reference path="../node_modules/@types/node/index.d.ts" />
/// <reference path="../node_modules/@types/mocha/index.d.ts" />
/// <reference path="../node_modules/@types/jest/index.d.ts" />
/// <reference path="../node_modules/typemoq/dist/typemoq.d.ts" />

@@ -12,2 +12,3 @@

import { Sink, SinkStage } from '../src/sink';
import { ConcreteSink } from './helpers';

@@ -18,3 +19,3 @@ describe('SinkStage', () => {

let emittedEvents = [];
const sink = TypeMoq.Mock.ofType<Sink>();
const sink = TypeMoq.Mock.ofType(ConcreteSink);
sink.setup(m => m.emit(TypeMoq.It.isAny())).callback(events => emittedEvents = events);

@@ -28,8 +29,8 @@ const sinkStage = new SinkStage(sink.object);

expect(emittedEvents).to.have.length(2);
expect(emittedEvents[0]).to.equal(events[0]);
expect(emittedEvents[1]).to.equal(events[1]);
expect(emittedEvents[0]).to.deep.equal(events[0]);
expect(emittedEvents[1]).to.deep.equal(events[1]);
});
it('returns the emitted events', () => {
const sink = TypeMoq.Mock.ofType<Sink>();
const sink = TypeMoq.Mock.ofType(ConcreteSink);
const sinkStage = new SinkStage(sink.object);

@@ -49,3 +50,3 @@ const events = [

it('flushes the sink', () => {
const sink = TypeMoq.Mock.ofType<Sink>();
const sink = TypeMoq.Mock.ofType(ConcreteSink);
sink.setup(m => m.flush()).returns(() => Promise.resolve());

@@ -52,0 +53,0 @@ const sinkStage = new SinkStage(sink.object);

{
"compilerOptions": {
"target": "es6"
}
"target": "es5"
},
"files": [
"**/*.ts",
"test/polyfills.ts"
]
}

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