From 07def2c16efc8ef44204e52b540939ace8e7287f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20R=C3=A4del?= Date: Fri, 22 Aug 2014 14:25:22 +0200 Subject: [PATCH] Fix package index to use CLogger class as default. --- README.md | 12 ++++++------ index.js | 9 ++++++++- lib/clogger.js | 10 +++++----- lib/index.js | 10 ---------- lib/transport.js | 8 ++++---- test/clogger.spec.js | 33 +++++++++++++++++---------------- 6 files changed, 40 insertions(+), 42 deletions(-) delete mode 100644 lib/index.js diff --git a/README.md b/README.md index 64e13a3..c534f15 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ various chainable pre-defined or custom filter-functions. ## Installation ## ``` -npm install --save git+https://github.com/christian-raedel/node-clogger.git#v0.2.2 +npm install --save git+https://github.com/christian-raedel/node-clogger.git#v0.3.3 ``` ### Testing ### @@ -37,10 +37,10 @@ online](http://christian-raedel.github.io/node-clogger/index.html) ## Basic Usage ## ``` Javascript -var clogger = require('node-clogger'); +var CLogger = require('node-clogger'); // Create a new CLogger instance with reasonable defaults. -var logger = new clogger.CLogger(); +var logger = new CLogger(); logger.log('info', 'log #1'); logger.debug('log #%d', 2); logger.error('some error message: %s', 'fail...'); @@ -49,9 +49,9 @@ logger.error('some error message: %s', 'fail...'); // and a log-file. The log-file name is returned by a custom // filter-functions, just as the logger-id in the console output // (which prints 'server' in reverse). -var logger = new clogger.CLogger('server', { +var logger = new CLogger('server', { transports: [ - new clogger.transports.LogFile({ + new CLogger.transports.LogFile({ 'filename': '{{filename}}.log', filters: { filename: function() { @@ -59,7 +59,7 @@ var logger = new clogger.CLogger('server', { } } }), - new clogger.transports.Console({ + new CLogger.transports.Console({ 'colors': { 'info': 'grey', 'warn': 'yellow', diff --git a/index.js b/index.js index bb0a047..a9b848f 100644 --- a/index.js +++ b/index.js @@ -1 +1,8 @@ -module.exports = require('./lib'); +module.exports = require('./lib/clogger'); + +/** + * transports + * @namespace + * @description A collection of plugable logging-transports, required from the 'transports' sub-directory. + */ +module.exports.transports = require('./lib/transport'); diff --git a/lib/clogger.js b/lib/clogger.js index 959c619..9e3da22 100644 --- a/lib/clogger.js +++ b/lib/clogger.js @@ -1,6 +1,6 @@ var _ = require('lodash') , util = require('util') - , CConf = require('node-cconf').CConf + , CConf = require('node-cconf') , transports = require('./transport'); /** @@ -12,10 +12,10 @@ var _ = require('lodash') * array of visible log-levels. Log-levels can be given as environment-variables in the form of * 'VISIBLE=info,warn,error node app.js'. * @example - * var clogger = require('node-clogger'); - * var logger = new clogger.CLogger('server', { + * var CLogger = require('node-clogger'); + * var logger = new CLogger('server', { * transports: [ - * new clogger.transports.Console() + * new CLogger.transports.Console() * ], * visible: ['info', 'error'] * }); @@ -127,7 +127,7 @@ _.forEach(level, function(level) { * It creates a method for each log-level and stores the logger itself in 'obj._logger'. * @example * var clogger = require('node-clogger'); - * new clogger.CLogger().addTransport(new clogger.transports.LogFile({ + * new CLogger().addTransport(new CLogger.transports.LogFile({ * 'filename': __dirname + '/server.log' * })).extend(console); * console.info('This message will be printed on console and in a logfile...'); diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b986013..0000000 --- a/lib/index.js +++ /dev/null @@ -1,10 +0,0 @@ -var _ = require('lodash'); - -module.exports.CLogger = require('./clogger'); - -/** - * transports - * @namespace - * @description A collection of plugable logging-transports, required from the 'transports' sub-directory. - */ -module.exports.transports = require('./transport'); diff --git a/lib/transport.js b/lib/transport.js index cf56c4f..f7153bf 100644 --- a/lib/transport.js +++ b/lib/transport.js @@ -3,7 +3,7 @@ var _ = require('lodash') , util = require('util') , fs = require('fs') , moment = require('moment') - , CConf = require('node-cconf').CConf; + , CConf = require('node-cconf'); /** * Transport - A logging transport base class used by {@link CLogger.transports}. @@ -37,7 +37,7 @@ function Transport(name, opts) { * Filter-parameters are separated by a colon (':'). * @example * var clogger = require('node-clogger'); - * var logFileTransport = new clogger.transports.LogFile({ + * var logFileTransport = new CLogger.transports.LogFile({ * 'filename': '{{dirname}}/server.log', * 'format': '{{value:level|uppercase|colorize}}: {{value:message|capitalize|colorize:green}}', * filters: { @@ -46,7 +46,7 @@ function Transport(name, opts) { * } * } * }); - * var logger = new clogger.CLogger('server').addTransport(logFileTransport); + * var logger = new CLogger('server').addTransport(logFileTransport); * logger.info('This message goes to a logfile and the console...'); */ value: function(value, param, args) { @@ -118,7 +118,7 @@ Transport.prototype.formatString = function(str, args) { return str; } else { - throw new Error('Invalid arguments to format log message!') + throw new Error('Invalid arguments to format log message!'); } }; diff --git a/test/clogger.spec.js b/test/clogger.spec.js index dd221b9..4c84d8f 100644 --- a/test/clogger.spec.js +++ b/test/clogger.spec.js @@ -2,23 +2,23 @@ var _ = require('lodash') , expect = require('chai').expect , taffydb = require('taffydb').taffy , fs = require('fs') - , clogger = require('../lib'); + , CLogger = require('../index'); describe('CLogger', function() { it('should instanciates', function() { - expect(new clogger.CLogger()).to.be.an.instanceof(clogger.CLogger); + expect(new CLogger()).to.be.an.instanceof(CLogger); }); it('should extends an existing object with log-functions', function(done) { var called = null , obj = {} - , logger = new clogger.CLogger().addTransport(new clogger.transports.CustomFunction({ + , logger = new CLogger().addTransport(new CLogger.transports.CustomFunction({ 'function': function(args) { expect(args.timestamp).to.be.above(0); expect(args.id).to.be.equal('default'); expect(args.level).to.be.equal('info'); expect(args.message).to.be.equal('dlc'); - expect(obj._logger).to.be.an.instanceof(clogger.CLogger); + expect(obj._logger).to.be.an.instanceof(CLogger); called = true; } })); @@ -33,9 +33,9 @@ describe('CLogger', function() { }); it('should logs only to visible log-levels', function() { - var logger = new clogger.CLogger({ + var logger = new CLogger({ transports: [ - new clogger.transports.CustomFunction({ + new CLogger.transports.CustomFunction({ 'function': function(args) { expect(args.level).to.match(/info|warn|trace/); } @@ -55,9 +55,9 @@ describe('CLogger', function() { describe('CLogger:Transport:Console', function() { it('should logs to a console', function() { - var logger = new clogger.CLogger('test', { + var logger = new CLogger('test', { transports: [ - new clogger.transports.Console({ + new CLogger.transports.Console({ 'colors': { 'info': 'yellow' }, @@ -88,7 +88,7 @@ describe('CLogger:Transport:Console', function() { }); it('should logs with different log levels', function() { - var logger = new clogger.CLogger(); + var logger = new CLogger(); _.forEach(['info', 'warn', 'debug', 'error', 'trace'], function(level) { logger[level]('dlc'); @@ -98,9 +98,9 @@ describe('CLogger:Transport:Console', function() { describe('CLogger:Transport:CustomFunction', function() { it('should logs to a custom function', function(done) { - var logger = new clogger.CLogger('test', { + var logger = new CLogger('test', { transports: [ - new clogger.transports.CustomFunction({ + new CLogger.transports.CustomFunction({ 'function': function customLog(args) { expect(args.timestamp).to.be.ok; expect(args.level).to.be.equal('info'); @@ -119,9 +119,9 @@ describe('CLogger:Transport:CustomFunction', function() { describe('CLogger:Transport:TaffyDb', function() { it('should logs to a TaffyDb instance', function() { var targetdb = taffydb() - , logger = new clogger.CLogger('test', { + , logger = new CLogger('test', { transports: [ - new clogger.transports.TaffyDb({ + new CLogger.transports.TaffyDb({ targetdb: targetdb }) ] @@ -139,9 +139,9 @@ describe('CLogger:Transport:TaffyDb', function() { describe('CLogger:Transport:LogFile', function() { it('should logs to a logfile', function(done) { - var logger = new clogger.CLogger('test', { + var logger = new CLogger('test', { transports: [ - new clogger.transports.LogFile({ + new CLogger.transports.LogFile({ 'filename': '{{dirname}}/test.log', filters: { dirname: function() { @@ -155,8 +155,9 @@ describe('CLogger:Transport:LogFile', function() { logger.log('info', '%sl%s', 'd', 'c'); setTimeout(function() { + var filename = null; try { - var filename = __dirname + '/test.log'; + filename = __dirname + '/test.log'; var logdata = fs.readFileSync(filename, {encoding: 'utf8', mode: 'r'}); expect(logdata).to.match(/\[Test\]/); expect(logdata).to.match(/INFO\:/);