Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

Commit

Permalink
馃悰 Fixed log file rotation
Browse files Browse the repository at this point in the history
closes #60

- was introduced in #59
- the initial fix of PR #59 was the correct fix
- `rotate-file` type is a real file stream (!)
- we should only register this stream type if rotation is enabled, because
  - type `file` always writes into the oldest log file
  - type `rotate-file` writes into the latest log file
- because we had ignored rotate streams for logging, which we thought is the right solution, the `file` stream has written into the oldest log file and this ended up in a huge log file after a couple of days (depends on the load)
  • Loading branch information
kirrg001 committed Jul 2, 2018
1 parent 6dff8d0 commit c8f2564
Showing 1 changed file with 24 additions and 27 deletions.
51 changes: 24 additions & 27 deletions lib/logging/GhostLogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,30 +142,6 @@ class GhostLogger {
return;
}

this.streams['file-errors'] = {
name: 'file',
log: bunyan.createLogger({
name: 'Log',
streams: [{
path: `${this.path}${sanitizedDomain}_${this.env}.error.log`,
level: 'error'
}],
serializers: this.serializers
})
};

this.streams['file-all'] = {
name: 'file',
log: bunyan.createLogger({
name: 'Log',
streams: [{
path: `${this.path}${sanitizedDomain}_${this.env}.log`,
level: this.level
}],
serializers: this.serializers
})
};

if (this.rotation.enabled) {
this.streams['rotation-errors'] = {
name: 'rotation-errors',
Expand Down Expand Up @@ -196,6 +172,30 @@ class GhostLogger {
serializers: this.serializers
})
};
} else {
this.streams['file-errors'] = {
name: 'file',
log: bunyan.createLogger({
name: 'Log',
streams: [{
path: `${this.path}${sanitizedDomain}_${this.env}.error.log`,
level: 'error'
}],
serializers: this.serializers
})
};

this.streams['file-all'] = {
name: 'file',
log: bunyan.createLogger({
name: 'Log',
streams: [{
path: `${this.path}${sanitizedDomain}_${this.env}.log`,
level: this.level
}],
serializers: this.serializers
})
};
}
}

Expand Down Expand Up @@ -306,9 +306,6 @@ class GhostLogger {
// because it would result in duplicate logs
if (type === 'error' && logger.name === 'stdout' && includes(this.transports, 'stderr')) {
return;
} else if ( logger.name.indexOf('rotation') > -1 ) {
// https://github.com/TryGhost/Ignition/pull/59
return;
}

/**
Expand Down

0 comments on commit c8f2564

Please sign in to comment.