Comparing version 2.0.2 to 2.1.0
@@ -41,8 +41,8 @@ 'use strict'; | ||
var logLevelColorMap = { | ||
DEBUG: 'gray', | ||
ERROR: 'red', | ||
FATAL: 'red', | ||
INFO: 'cyan', | ||
TRACE: 'gray', | ||
WARN: 'yellow' | ||
DEBUG: _chalk2.default.gray, | ||
ERROR: _chalk2.default.red, | ||
FATAL: _chalk2.default.red, | ||
INFO: _chalk2.default.cyan, | ||
TRACE: _chalk2.default.gray, | ||
WARN: _chalk2.default.yellow | ||
}; | ||
@@ -77,3 +77,7 @@ | ||
formattedMessage += ' ' + _chalk2.default[logLevelColorName](logLevelName + ' (' + message.context.logLevel + ')'); | ||
if (!logLevelColorName) { | ||
throw new Error('Unexpected state.'); | ||
} | ||
formattedMessage += ' ' + logLevelColorName(logLevelName + ' (' + message.context.logLevel + ')'); | ||
} | ||
@@ -80,0 +84,0 @@ |
@@ -11,8 +11,2 @@ 'use strict'; | ||
var _createRoarrInititialGlobalState = require('./createRoarrInititialGlobalState'); | ||
var _createRoarrInititialGlobalState2 = _interopRequireDefault(_createRoarrInititialGlobalState); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/*:: import type { | ||
@@ -23,6 +17,2 @@ LoggerType, | ||
} from '../types';*/ | ||
global.ROARR = global.ROARR || (0, _createRoarrInititialGlobalState2.default)(); | ||
/*:: type OnMessageEventHandlerType = (message: MessageType) => void;*/ | ||
@@ -29,0 +19,0 @@ |
@@ -6,4 +6,19 @@ 'use strict'; | ||
}); | ||
// @flow | ||
var _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; }; // @flow | ||
var _semverCompare = require('semver-compare'); | ||
var _semverCompare2 = _interopRequireDefault(_semverCompare); | ||
var _package = require('../../package.json'); | ||
var _config = require('../config'); | ||
var _createWriter = require('./createWriter'); | ||
var _createWriter2 = _interopRequireDefault(_createWriter); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/*:: import type { | ||
@@ -13,8 +28,36 @@ RoarrGlobalStateType | ||
exports.default = function () /*: RoarrGlobalStateType*/ { | ||
return { | ||
// eslint-disable-next-line flowtype/no-weak-types | ||
exports.default = function (currentState /*: Object*/) /*: RoarrGlobalStateType*/ { | ||
var versions = (currentState.versions || []).concat(); | ||
versions.sort(_semverCompare2.default); | ||
var currentIsLatestVersion = !versions.length || (0, _semverCompare2.default)(_package.version, versions[versions.length - 1]) === 1; | ||
if (!versions.includes(_package.version)) { | ||
versions.push(_package.version); | ||
} | ||
versions.sort(_semverCompare2.default); | ||
var newState = _extends({ | ||
buffer: '', | ||
prepend: {}, | ||
sequence: 0 | ||
}; | ||
}, currentState, { | ||
versions: versions | ||
}); | ||
if (currentIsLatestVersion || !newState.write) { | ||
var Writer = (0, _createWriter2.default)({ | ||
bufferSize: _config.ROARR_BUFFER_SIZE, | ||
stream: _config.ROARR_STREAM | ||
}); | ||
newState.write = Writer.write; | ||
newState.flush = Writer.flush; | ||
} | ||
return newState; | ||
}; | ||
//# sourceMappingURL=createRoarrInititialGlobalState.js.map |
@@ -7,20 +7,24 @@ 'use strict'; | ||
var _boolean = require('boolean'); | ||
var _boolean2 = _interopRequireDefault(_boolean); | ||
var _factories = require('./factories'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _config = require('./config'); | ||
// eslint-disable-next-line no-process-env | ||
// @flow | ||
var ROARR_LOG = (0, _boolean2.default)(process.env.ROARR_LOG) === true; | ||
global.ROARR = (0, _factories.createRoarrInititialGlobalState)(global.ROARR || {}); | ||
// eslint-disable-next-line no-process-env | ||
var ROARR_STREAM = (process.env.ROARR_STREAM || '').toUpperCase() === 'STDERR' ? 'STDERR' : 'STDOUT'; | ||
// We want to register just one event listener for 'exit' event | ||
// across all instances of Roarr. | ||
if (!global.ROARR.registeredFlush) { | ||
global.ROARR.registeredFlush = true; | ||
process.on('exit', function () { | ||
if (global.ROARR.flush) { | ||
global.ROARR.flush(); | ||
} | ||
}); | ||
} | ||
exports.default = (0, _factories.createLogger)(function (message) { | ||
if (!ROARR_LOG) { | ||
if (!_config.ROARR_LOG) { | ||
return; | ||
@@ -31,9 +35,4 @@ } | ||
// @todo Add browser support. | ||
if (ROARR_STREAM === 'STDOUT') { | ||
process.stdout.write(body + '\n'); | ||
} else { | ||
process.stderr.write(body + '\n'); | ||
} | ||
global.ROARR.write(body); | ||
}); | ||
//# sourceMappingURL=log.js.map |
@@ -8,6 +8,11 @@ "use strict"; | ||
};*/ | ||
/*:: export type RoarrGlobalStateType = { | ||
/*:: export type RoarrGlobalStateType = {| | ||
buffer: string, | ||
flush: (message: string) => void, | ||
prepend: SerializableObjectType, | ||
sequence: number | ||
};*/ | ||
registeredFlush: boolean, | ||
sequence: number, | ||
versions: $ReadOnlyArray<string>, | ||
write: (message: string) => void | ||
|};*/ | ||
/*:: export type SprintfArgumentType = string | number | boolean | null;*/ | ||
@@ -14,0 +19,0 @@ /*:: export type MessageContextType = SerializableObjectType;*/ |
@@ -1,1 +0,79 @@ | ||
{"author":{"email":"gajus@gajus.com","name":"Gajus Kuizinas","url":"http://gajus.com"},"ava":{"babel":"inherit","require":["babel-register"]},"bin":"./dist/bin/index.js","dependencies":{"boolean":"^0.1.3","chalk":"^2.3.0","prettyjson":"^1.2.1","split2":"^2.2.0","sprintf-js":"^1.1.1","ulid":"^2.2.1","yargs":"^10.0.3"},"description":"JSON logger for Node.js and browser.","devDependencies":{"ava":"^0.23.0","babel-cli":"^6.26.0","babel-plugin-istanbul":"^4.1.5","babel-plugin-transform-flow-comments":"^6.22.0","babel-plugin-transform-flow-strip-types":"^6.22.0","babel-plugin-transform-object-rest-spread":"^6.26.0","babel-preset-env":"^1.6.1","babel-register":"^6.26.0","coveralls":"^3.0.0","eslint":"^4.10.0","eslint-config-canonical":"^9.3.1","flow-bin":"^0.58.0","flow-copy-source":"^1.2.1","husky":"^0.14.3","nock":"^9.0.27","nyc":"^11.3.0","semantic-release":"^8.2.0","sinon":"^4.1.1"},"engines":{"node":">=8.0"},"keywords":["log","logger","json"],"main":"./dist/log.js","name":"roarr","nyc":{"include":["src/**/*.js"],"instrument":false,"reporter":["text-lcov"],"require":["babel-register"],"sourceMap":false},"repository":{"type":"git","url":"git@github.com:gajus/roarr.git"},"scripts":{"build":"rm -fr ./dist && NODE_ENV=production babel ./src --out-dir ./dist --copy-files --source-maps && flow-copy-source src dist","generate-types":"babel-node ./src/bin/generate-types.js","lint":"eslint ./src ./test && flow","test":"NODE_ENV=test ava --serial --verbose"},"version":"2.0.2"} | ||
{ | ||
"author": { | ||
"email": "gajus@gajus.com", | ||
"name": "Gajus Kuizinas", | ||
"url": "http://gajus.com" | ||
}, | ||
"ava": { | ||
"babel": "inherit", | ||
"require": [ | ||
"babel-register" | ||
] | ||
}, | ||
"bin": "./dist/bin/index.js", | ||
"dependencies": { | ||
"boolean": "^0.1.3", | ||
"chalk": "^2.3.0", | ||
"prettyjson": "^1.2.1", | ||
"semver-compare": "^1.0.0", | ||
"split2": "^2.2.0", | ||
"sprintf-js": "^1.1.1", | ||
"ulid": "^2.2.1", | ||
"yargs": "^10.0.3" | ||
}, | ||
"description": "JSON logger for Node.js and browser.", | ||
"devDependencies": { | ||
"ava": "^0.23.0", | ||
"babel-cli": "^6.26.0", | ||
"babel-plugin-istanbul": "^4.1.5", | ||
"babel-plugin-transform-flow-comments": "^6.22.0", | ||
"babel-plugin-transform-flow-strip-types": "^6.22.0", | ||
"babel-plugin-transform-object-rest-spread": "^6.26.0", | ||
"babel-preset-env": "^1.6.1", | ||
"babel-register": "^6.26.0", | ||
"coveralls": "^3.0.0", | ||
"eslint": "^4.10.0", | ||
"eslint-config-canonical": "^9.3.1", | ||
"flow-bin": "^0.58.0", | ||
"flow-copy-source": "^1.2.1", | ||
"husky": "^0.14.3", | ||
"nock": "^9.0.27", | ||
"nyc": "^11.3.0", | ||
"semantic-release": "^15.3.1", | ||
"sinon": "^4.1.1" | ||
}, | ||
"engines": { | ||
"node": ">=8.0" | ||
}, | ||
"keywords": [ | ||
"log", | ||
"logger", | ||
"json" | ||
], | ||
"main": "./dist/log.js", | ||
"name": "roarr", | ||
"nyc": { | ||
"include": [ | ||
"src/**/*.js" | ||
], | ||
"instrument": false, | ||
"reporter": [ | ||
"text-lcov" | ||
], | ||
"require": [ | ||
"babel-register" | ||
], | ||
"sourceMap": false | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:gajus/roarr.git" | ||
}, | ||
"scripts": { | ||
"build": "rm -fr ./dist && NODE_ENV=production babel ./src --out-dir ./dist --copy-files --source-maps && flow-copy-source src dist", | ||
"generate-types": "babel-node ./src/bin/generate-types.js", | ||
"lint": "eslint ./src ./test && flow", | ||
"test": "NODE_ENV=test ava --serial --verbose" | ||
}, | ||
"version": "2.1.0" | ||
} |
@@ -194,2 +194,19 @@ # Roarr | ||
If your application outputs non-JSON output, jq will fail with an error similar to: | ||
``` | ||
parse error: Invalid numeric literal at line 1, column 5 | ||
Error: write EPIPE | ||
at _errnoException (util.js:1031:13) | ||
at WriteWrap.afterWrite (net.js:873:14) | ||
``` | ||
To ignore the non-JSON output, use jq `-R` flag (raw input) in combination with [`fromjson`](https://stedolan.github.io/jq/manual/#Convertto/fromJSON), e.g. | ||
```bash | ||
ROARR_LOG=true node ./index.js | jq -cRM 'fromjson? | select(.context.logLevel > 40)' | ||
``` | ||
## Log message format | ||
@@ -365,2 +382,3 @@ | ||
|`ROARR_STREAM`|`STDOUT`, `STDERR`|Name of the stream where the logs will be written.|`STDOUT`| | ||
|`ROARR_BUFFER_SIZE`|Number|Configures the buffer size used to determine when to write the log. To disable buffering set `ROARR_BUFFER_SIZE` to `0`.|`8192`| | ||
@@ -470,2 +488,22 @@ When using `ROARR_STREAM=STDERR`, use [`3>&1 1>&2 2>&3 3>&-`](https://stackoverflow.com/a/2381643/368691) to pipe stderr output. | ||
```js | ||
import log from 'roarr'; | ||
import serializeError from 'serialize-error'; | ||
// [..] | ||
send((error, result) => { | ||
if (error) { | ||
log.error({ | ||
error: serializeError(error) | ||
}, 'message not sent due to a remote error'); | ||
return; | ||
} | ||
// [..] | ||
}); | ||
``` | ||
Without using serialisation, your errors will be logged without the error name and stack trace. | ||
@@ -472,0 +510,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
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
76594
48
494
560
8
3
+ Addedsemver-compare@^1.0.0
+ Addedsemver-compare@1.0.0(transitive)