Comparing version 2.15.4 to 3.0.0
@@ -12,5 +12,7 @@ "use strict"; | ||
var _isCircular = _interopRequireDefault(require("is-circular")); | ||
var _jsonStringifySafe = _interopRequireDefault(require("json-stringify-safe")); | ||
var _sprintfJs = require("sprintf-js"); | ||
var _sprintfit = require("sprintfit"); | ||
@@ -21,10 +23,2 @@ var _constants = require("../constants"); | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
const globalThis = (0, _globalthis.default)(); | ||
@@ -34,3 +28,3 @@ let domain; | ||
if (_detectNode.default) { | ||
// eslint-disable-next-line global-require | ||
// eslint-disable-next-line node/global-require | ||
domain = require('domain'); | ||
@@ -62,3 +56,5 @@ } | ||
for (const parentRoarrContext of parentRoarrContexts) { | ||
domainContext = _objectSpread(_objectSpread({}, domainContext), parentRoarrContext); | ||
domainContext = { ...domainContext, | ||
...parentRoarrContext | ||
}; | ||
} | ||
@@ -96,2 +92,4 @@ | ||
const defaultContext = {}; | ||
const createLogger = (onMessage, parentContext) => { | ||
@@ -106,26 +104,24 @@ // eslint-disable-next-line id-length, unicorn/prevent-abbreviations | ||
if (typeof a === 'string') { | ||
context = _objectSpread(_objectSpread({}, getFirstParentDomainContext()), parentContext || {}); // eslint-disable-next-line id-length, object-property-newline | ||
if (!domain || process.domain === null) { | ||
context = parentContext || defaultContext; | ||
} else { | ||
context = { ...getFirstParentDomainContext(), | ||
...parentContext | ||
}; | ||
} | ||
} else { | ||
context = { ...getFirstParentDomainContext(), | ||
...parentContext, | ||
...a | ||
}; | ||
} | ||
const args = _extends({}, { | ||
a, | ||
b, | ||
c, | ||
d, | ||
e, | ||
f, | ||
g, | ||
h, | ||
i, | ||
k | ||
}); | ||
if (context !== defaultContext && (0, _isCircular.default)(context)) { | ||
context = JSON.parse((0, _jsonStringifySafe.default)(context)); | ||
} | ||
const values = Object.keys(args).map(key => { | ||
return args[key]; | ||
}); // eslint-disable-next-line unicorn/no-reduce | ||
const hasOnlyOneParameterValued = 1 === values.reduce((accumulator, value) => { | ||
// eslint-disable-next-line no-return-assign, no-param-reassign | ||
return accumulator += typeof value === 'undefined' ? 0 : 1; | ||
}, 0); | ||
message = hasOnlyOneParameterValued ? (0, _sprintfJs.sprintf)('%s', a) : (0, _sprintfJs.sprintf)(a, b, c, d, e, f, g, h, i, k); | ||
if (typeof a === 'string' && b === undefined) { | ||
message = a; | ||
} else if (typeof a === 'string') { | ||
message = (0, _sprintfit.sprintf)(a, b, c, d, e, f, g, h, i, k); | ||
} else { | ||
@@ -136,4 +132,3 @@ if (typeof b !== 'string') { | ||
context = JSON.parse((0, _jsonStringifySafe.default)(_objectSpread(_objectSpread(_objectSpread({}, getFirstParentDomainContext()), parentContext || {}), a))); | ||
message = (0, _sprintfJs.sprintf)(b, c, d, e, f, g, h, i, k); | ||
message = (0, _sprintfit.sprintf)(b, c, d, e, f, g, h, i, k); | ||
} | ||
@@ -161,7 +156,12 @@ | ||
return createLogger(onMessage, _objectSpread(_objectSpread(_objectSpread({}, getFirstParentDomainContext()), parentContext), context)); | ||
return createLogger(onMessage, { ...getFirstParentDomainContext(), | ||
...parentContext, | ||
...context | ||
}); | ||
}; | ||
log.getContext = () => { | ||
return _objectSpread(_objectSpread({}, getFirstParentDomainContext()), parentContext || {}); | ||
return { ...getFirstParentDomainContext(), | ||
...(parentContext || defaultContext) | ||
}; | ||
}; | ||
@@ -178,3 +178,5 @@ | ||
adoptedDomain.roarr = { | ||
context: _objectSpread(_objectSpread({}, getParentDomainContext()), context) | ||
context: { ...getParentDomainContext(), | ||
...context | ||
} | ||
}; | ||
@@ -181,0 +183,0 @@ return routine(); |
@@ -17,3 +17,3 @@ "use strict"; | ||
const createNodeWriter = () => { | ||
// eslint-disable-next-line no-process-env | ||
// eslint-disable-next-line node/no-process-env | ||
const targetStream = (process.env.ROARR_STREAM || 'STDOUT').toUpperCase(); | ||
@@ -20,0 +20,0 @@ const stream = targetStream.toUpperCase() === 'STDOUT' ? process.stdout : process.stderr; |
@@ -18,8 +18,2 @@ "use strict"; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
// eslint-disable-next-line flowtype/no-weak-types | ||
@@ -36,12 +30,13 @@ const createRoarrInititialGlobalState = currentState => { | ||
versions.sort(_semverCompare.default); | ||
let newState = _objectSpread(_objectSpread({ | ||
sequence: 0 | ||
}, currentState), {}, { | ||
let newState = { | ||
sequence: 0, | ||
...currentState, | ||
versions | ||
}); | ||
}; | ||
if (_detectNode.default) { | ||
if (currentIsLatestVersion || !newState.write) { | ||
newState = _objectSpread(_objectSpread({}, newState), (0, _createNodeWriter.default)()); | ||
newState = { ...newState, | ||
...(0, _createNodeWriter.default)() | ||
}; | ||
} | ||
@@ -48,0 +43,0 @@ } |
@@ -12,2 +12,4 @@ "use strict"; | ||
var _fastJsonStringify = _interopRequireDefault(require("fast-json-stringify")); | ||
var _globalthis = _interopRequireDefault(require("globalthis")); | ||
@@ -19,2 +21,23 @@ | ||
const stringify = (0, _fastJsonStringify.default)({ | ||
properties: { | ||
context: { | ||
additionalProperties: true, | ||
type: 'object' | ||
}, | ||
message: { | ||
type: 'string' | ||
}, | ||
sequence: { | ||
type: 'integer' | ||
}, | ||
time: { | ||
type: 'integer' | ||
}, | ||
version: { | ||
type: 'string' | ||
} | ||
}, | ||
type: 'object' | ||
}); | ||
const globalThis = (0, _globalthis.default)(); | ||
@@ -26,3 +49,3 @@ const ROARR = globalThis.ROARR = (0, _factories.createRoarrInititialGlobalState)(globalThis.ROARR || {}); | ||
if (_detectNode.default) { | ||
// eslint-disable-next-line no-process-env | ||
// eslint-disable-next-line node/no-process-env | ||
const enabled = (0, _boolean.boolean)(process.env.ROARR_LOG || ''); | ||
@@ -39,3 +62,3 @@ | ||
// properties of the context from being modified by reference. | ||
const body = JSON.stringify(message); | ||
const body = stringify(message); | ||
ROARR.write(body); | ||
@@ -42,0 +65,0 @@ } |
@@ -21,8 +21,10 @@ { | ||
"dependencies": { | ||
"boolean": "^3.0.1", | ||
"boolean": "^3.0.2", | ||
"detect-node": "^2.0.4", | ||
"fast-json-stringify": "^2.3.0", | ||
"globalthis": "^1.0.1", | ||
"is-circular": "^1.0.2", | ||
"json-stringify-safe": "^5.0.1", | ||
"semver-compare": "^1.0.0", | ||
"sprintf-js": "^1.1.2" | ||
"sprintfit": "^1.0.1" | ||
}, | ||
@@ -32,24 +34,25 @@ "description": "JSON logger for Node.js and browser.", | ||
"@ava/babel": "^1.0.1", | ||
"@babel/cli": "^7.11.6", | ||
"@babel/core": "^7.11.6", | ||
"@babel/node": "^7.10.5", | ||
"@babel/plugin-transform-flow-strip-types": "^7.10.4", | ||
"@babel/preset-env": "^7.11.5", | ||
"@babel/register": "^7.11.5", | ||
"ava": "^3.12.1", | ||
"@babel/cli": "^7.12.10", | ||
"@babel/core": "^7.12.10", | ||
"@babel/node": "^7.12.10", | ||
"@babel/plugin-transform-flow-strip-types": "^7.12.10", | ||
"@babel/preset-env": "^7.12.11", | ||
"@babel/register": "^7.12.10", | ||
"ava": "^3.14.0", | ||
"babel-plugin-istanbul": "^6.0.0", | ||
"babel-plugin-transform-export-default-name": "^2.0.4", | ||
"babel-plugin-transform-export-default-name": "^2.1.0", | ||
"benchmark": "^2.1.4", | ||
"coveralls": "^3.1.0", | ||
"domain-parent": "^1.0.0", | ||
"eslint": "^7.9.0", | ||
"eslint-config-canonical": "^24.1.1", | ||
"flow-bin": "^0.133.0", | ||
"eslint": "^7.16.0", | ||
"eslint-config-canonical": "^24.4.4", | ||
"flow-bin": "^0.141.0", | ||
"flow-copy-source": "^2.0.9", | ||
"gitdown": "^3.1.3", | ||
"husky": "^4.3.0", | ||
"husky": "^4.3.6", | ||
"nyc": "^15.1.0", | ||
"semantic-release": "^17.1.1" | ||
"semantic-release": "^17.3.0" | ||
}, | ||
"engines": { | ||
"node": ">=8.0" | ||
"node": ">=10.0" | ||
}, | ||
@@ -67,2 +70,3 @@ "husky": { | ||
], | ||
"license": "BSD-3-Clause", | ||
"main": "./dist/log.js", | ||
@@ -83,3 +87,2 @@ "name": "roarr", | ||
}, | ||
"license": "BSD-3-Clause", | ||
"repository": { | ||
@@ -90,2 +93,3 @@ "type": "git", | ||
"scripts": { | ||
"benchmark": "ROARR_LOG=true babel-node test/benchmark.js", | ||
"build": "rm -fr ./dist && NODE_ENV=production babel ./src --out-dir ./dist --copy-files --source-maps && flow-copy-source src dist", | ||
@@ -97,3 +101,3 @@ "create-readme": "gitdown ./.README/README.md --output-file ./README.md", | ||
}, | ||
"version": "2.15.4" | ||
"version": "3.0.0" | ||
} |
<a name="roarr"></a> | ||
# Roarr | ||
[![GitSpo Mentions](https://gitspo.com/badges/mentions/gajus/roarr?style=flat-square)](https://gitspo.com/mentions/gajus/roarr) | ||
[![Travis build status](http://img.shields.io/travis/gajus/roarr/master.svg?style=flat-square)](https://travis-ci.org/gajus/roarr) | ||
@@ -39,5 +38,7 @@ [![Coveralls](https://img.shields.io/coveralls/gajus/roarr.svg?style=flat-square)](https://coveralls.io/github/gajus/roarr) | ||
* [Logging errors](#roarr-recipes-logging-errors) | ||
* [Using with Elasticsearch](#roarr-recipes-using-with-elasticsearch) | ||
* [Using with Scalyr](#roarr-recipes-using-with-scalyr) | ||
* [Documenting use of Roarr](#roarr-recipes-documenting-use-of-roarr) | ||
* [Integrations](#roarr-integrations) | ||
* [Using with Sentry](#roarr-integrations-using-with-sentry) | ||
* [Using with Elasticsearch](#roarr-integrations-using-with-elasticsearch) | ||
* [Using with Scalyr](#roarr-integrations-using-with-scalyr) | ||
* [Documenting use of Roarr](#roarr-documenting-use-of-roarr) | ||
@@ -599,3 +600,11 @@ | ||
<a name="roarr-recipes-using-with-elasticsearch"></a> | ||
<a name="roarr-integrations"></a> | ||
## Integrations | ||
<a name="roarr-integrations-using-with-sentry"></a> | ||
### Using with Sentry | ||
https://github.com/gajus/roarr-sentry | ||
<a name="roarr-integrations-using-with-elasticsearch"></a> | ||
### Using with Elasticsearch | ||
@@ -654,3 +663,3 @@ | ||
<a name="roarr-recipes-using-with-scalyr"></a> | ||
<a name="roarr-integrations-using-with-scalyr"></a> | ||
### Using with Scalyr | ||
@@ -678,4 +687,4 @@ | ||
<a name="roarr-recipes-documenting-use-of-roarr"></a> | ||
### Documenting use of Roarr | ||
<a name="roarr-documenting-use-of-roarr"></a> | ||
## Documenting use of Roarr | ||
@@ -687,5 +696,5 @@ If your package is using Roarr, include instructions in `README.md` describing how to enable logging, e.g. | ||
This package is using [`roarr`](https://www.npmjs.com/package/roarr) logger to log the program's state. | ||
This project uses [`roarr`](https://www.npmjs.com/package/roarr) logger to log the program's state. | ||
Export `ROARR_LOG=true` environment variable to enable log printing to stdout. | ||
Export `ROARR_LOG=true` environment variable to enable log printing to `stdout`. | ||
@@ -692,0 +701,0 @@ Use [`roarr-cli`](https://github.com/gajus/roarr-cli) program to pretty-print the logs. |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
330
699
66452
8
21
+ Addedfast-json-stringify@^2.3.0
+ Addedis-circular@^1.0.2
+ Addedsprintfit@^1.0.1
+ Addedajv@6.12.6(transitive)
+ Addeddeepmerge@4.3.1(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedfast-json-stringify@2.7.13(transitive)
+ Addedis-circular@1.0.2(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedrfdc@1.4.1(transitive)
+ Addedsprintfit@1.0.1(transitive)
+ Addedstring-similarity@4.0.4(transitive)
+ Addeduri-js@4.4.1(transitive)
- Removedsprintf-js@^1.1.2
- Removedsprintf-js@1.1.3(transitive)
Updatedboolean@^3.0.2