Skip to content

Commit

Permalink
Fix package index to use CLogger class as default.
Browse files Browse the repository at this point in the history
  • Loading branch information
incredible-io committed Aug 22, 2014
1 parent 303166e commit 07def2c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 42 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###
Expand All @@ -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...');
Expand All @@ -49,17 +49,17 @@ 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() {
return new Date().toDateString;
}
}
}),
new clogger.transports.Console({
new CLogger.transports.Console({
'colors': {
'info': 'grey',
'warn': 'yellow',
Expand Down
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -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');
10 changes: 5 additions & 5 deletions lib/clogger.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var _ = require('lodash')
, util = require('util')
, CConf = require('node-cconf').CConf
, CConf = require('node-cconf')
, transports = require('./transport');

/**
Expand All @@ -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']
* });
Expand Down Expand Up @@ -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...');
Expand Down
10 changes: 0 additions & 10 deletions lib/index.js

This file was deleted.

8 changes: 4 additions & 4 deletions lib/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down Expand Up @@ -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: {
Expand All @@ -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) {
Expand Down Expand Up @@ -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!');
}
};

Expand Down
33 changes: 17 additions & 16 deletions test/clogger.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}));
Expand All @@ -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/);
}
Expand All @@ -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'
},
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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
})
]
Expand All @@ -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() {
Expand All @@ -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\:/);
Expand Down

0 comments on commit 07def2c

Please sign in to comment.