Skip to content

Commit

Permalink
Add configurable log directory path
Browse files Browse the repository at this point in the history
  • Loading branch information
rudijs committed Aug 21, 2014
1 parent d2c1d85 commit d52c89a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 6 additions & 2 deletions README.md
Expand Up @@ -68,10 +68,14 @@ Default use will create two log files:

Log files have daily rotation and keeps 3 back copies.

Currently the only supported config options are `name` which configures the log file name and name property of the log entry.
Currently the only supported config options are:

-`name` which configures the log file name and name property of the log entry.
-`path` which configures the log directory (relative) to use.

app.use(koaJsonLogger({
name: 'myCoolApp'
name: 'myCoolApp',
path: 'logs'
}));

When you throw an application error it's best to always use `this.throw`
Expand Down
10 changes: 6 additions & 4 deletions lib/koa-json-logger.js
@@ -1,6 +1,7 @@
'use strict';

var bunyan = require('bunyan'),
var path = require('path'),
bunyan = require('bunyan'),
uuid = require('uuid');

function reqSerializer(ctx) {
Expand Down Expand Up @@ -33,7 +34,8 @@ module.exports = function koaLogger(opts) {

opts = opts || {};

var defaultName = opts.name || 'myapp';
var defaultName = opts.name || 'myapp',
defaultPath = opts.path || 'log';

// Standard Logger
// daily rotation
Expand All @@ -50,7 +52,7 @@ module.exports = function koaLogger(opts) {
streams: [
{
level: 'info',
path: 'log/' + defaultName + '.log',
path: path.join(defaultPath, defaultName + '.log'),
period: '1d',
count: 3
}
Expand All @@ -74,7 +76,7 @@ module.exports = function koaLogger(opts) {
streams: [
{
level: 'error',
path: 'log/' + defaultName + '_error.log',
path: path.join(defaultPath, defaultName + '_error.log'),
period: '1d',
count: 3
}
Expand Down

0 comments on commit d52c89a

Please sign in to comment.