Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to work with Sails 0.12.x #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
.idea
npm-debug.log
coverage/
.DS_Store
4 changes: 2 additions & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
// Prohibit use of a variable before it is defined.
"latedef": true,

// Enforce line length to 80 characters
"maxlen": 80,
// Enforce line length to 120 characters
"maxlen": 120,

// Require capitalized names for constructor functions.
"newcap": true,
Expand Down
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# sails-hook-bunyan changelog

## v2.3.0 (2020-08-05)

* Updated `config` to `bunyanConfigObject` as `config` is reserved in sails @^0.12
* Updated linting rules to something more sensible as nobody uses a vt100 with only 80 characters

## v2.2.0 (2017-01-17)

* Updated sails peerdep to include 0.12
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
![dependencies](https://david-dm.org/building5/sails-hook-bunyan.svg)

A [sails hook][] replacing the Sails default logger with Bunyan. Supports sails
0.11.x.
0.12.x.

> For Sails 0.10.x support, see the old [sails-bunyan][].

Expand Down
30 changes: 15 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = function (sails) {
defaults: function () {
var _this = this;
var fileStream;
var config = {};
var bunyanConfigObject = {};
var oldConfig = sails.config.log;
var bunyanConfig = {
/** If true, a child logger is injected on each request */
Expand All @@ -52,7 +52,7 @@ module.exports = function (sails) {
// these config objects
},
};
config[this.configKey] = bunyanConfig;
bunyanConfigObject[this.configKey] = bunyanConfig;

if (oldConfig.bunyan) {
bunyanConfig.logger = oldConfig.bunyan;
Expand Down Expand Up @@ -88,14 +88,14 @@ module.exports = function (sails) {
bunyanConfig.injectRequestLogger = oldConfig.injectRequestLogger;
}

return config;
return bunyanConfigObject;
},

/**
* Hook configuration function.
*/
configure: function () {
var config = sails.config[this.configKey];
var bunyanConfigObject = sails.config[this.configKey];

// the ship drawing looks pretty silly in JSON
sails.config.log.noShip = true;
Expand All @@ -104,33 +104,33 @@ module.exports = function (sails) {
sails.config.log.colors = false;

// setup some defaults
config.logger.name = config.logger.name || 'sails';
config.logger.serializers =
config.logger.serializers || bunyan.stdSerializers;
bunyanConfigObject.logger.name = bunyanConfigObject.logger.name || 'sails';
bunyanConfigObject.logger.serializers =
bunyanConfigObject.logger.serializers || bunyan.stdSerializers;

this.reqSerializer = config.logger.serializers.req ||
function (x) { return x; };
this.reqSerializer = bunyanConfigObject.logger.serializers.req ||
function (x) { return x; };

this.logger = bunyan.createLogger(config.logger);
this.logger = bunyan.createLogger(bunyanConfigObject.logger);
},

/**
* Hook initialization function.
*/
initialize: function (done) {
var config = sails.config[this.configKey];
var bunyanConfigObject = sails.config[this.configKey];

_this = this;

// If a rotationSignal is given, listen for it
if (config.rotationSignal) {
process.on(config.rotationSignal, function () {
if (bunyanConfigObject.rotationSignal) {
process.on(bunyanConfigObject.rotationSignal, function () {
_this.logger.reopenFileStreams();
});
}

// If logUncaughtException is set, log those, too
if (config.logUncaughtException) {
if (bunyanConfigObject.logUncaughtException) {
process.on('uncaughtException', function (err) {
_this.logger.fatal({ err: err }, 'Uncaught exception');
process.exit(1);
Expand All @@ -147,7 +147,7 @@ module.exports = function (sails) {
var bunyanLevel = logLevels[sailsLevel];
if (bunyanLevel) {
log[sailsLevel] = function () {
var logger = config.getLogger();
var logger = bunyanConfigObject.getLogger();
logger[bunyanLevel].apply(logger, arguments);
};
} else {
Expand Down
Loading