Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
447 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
tmp | ||
node_modules | ||
*._ | ||
*.tmp | ||
.monitor | ||
*.diff | ||
*.err | ||
*.orig | ||
*.log | ||
*.rej | ||
*.swo | ||
*.swp | ||
*.vi | ||
*~ | ||
.DS_Store | ||
Thumbs.db | ||
.cache | ||
.project | ||
.settings | ||
.tmproj | ||
*.esproj | ||
nbproject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
TESTS = test/*.test.js | ||
|
||
test: | ||
@NODE_ENV=test ./node_modules/.bin/mocha \ | ||
--require should \ | ||
--reporter spec \ | ||
$(TESTS) | ||
|
||
clean: | ||
rm -f examples/tmp/* | ||
|
||
.PHONY: test clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Logme | ||
|
||
Minimalistic logger for Node.js. | ||
|
||
![screenshot](http://img17.imageshack.us/img17/3241/screenshot20111209at120.png) | ||
|
||
## Features. | ||
|
||
- Error levels | ||
- Tokens | ||
- Custom templates | ||
- Custom everything | ||
|
||
## How to install it? | ||
|
||
$ npm install logme | ||
|
||
## Neat. Now what? | ||
|
||
var logme = require('logme'); | ||
logme.critical('The base is under atack'); | ||
|
||
## Whaaaat? | ||
|
||
For more complete examples see "examples/". | ||
|
||
## Tests. | ||
|
||
Sure. | ||
|
||
$ npm install | ||
$ make test | ||
|
||
## Contributing to this library. | ||
|
||
Anytime. | ||
|
||
## Inspiration. | ||
|
||
- [log.js](https://github.com/visionmedia/log.js) | ||
- [express](https://github.com/visionmedia/express) | ||
- [mongoose](https://github.com/LearnBoost/mongoose) | ||
|
||
## License. | ||
|
||
MIT License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Logme - Minimalistic logging. | ||
* | ||
* Author: Veselin Todorov <hi@vesln.com> | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
var logme = require('../'); | ||
|
||
/** | ||
* Different levels. | ||
*/ | ||
logme.debug('Lol, coffescript.'); | ||
logme.info('Logme is sexy.'); | ||
logme.warning('Danger!'); | ||
logme.error('Ooops, something went wrong.'); | ||
logme.critical('The base is under atack.'); | ||
|
||
// or... | ||
logme.log('debug', 'Lol, coffescript.'); | ||
logme.log('info', 'Logme is sexy.'); | ||
logme.log('warning', 'Danger!'); | ||
logme.log('error', 'Ooops, something went wrong.'); | ||
logme.log('critical', 'The base is under atack.'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Logme - Minimalistic logging. | ||
* | ||
* Author: Veselin Todorov <hi@vesln.com> | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
var colors = require('colors'); | ||
colors.mode = 'none'; | ||
|
||
var Logme = require('../').Logme; | ||
var fs = require('fs'); | ||
var stream = fs.createWriteStream(__dirname + '/tmp/file.log', { flags: 'a' }) | ||
var logme = new Logme({ stream: stream }); | ||
|
||
logme.error('Pro Tip: It logs to files.'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Logme - Minimalistic logging. | ||
* | ||
* Author: Veselin Todorov <hi@vesln.com> | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
var Logme = require('../').Logme; | ||
var logme = new Logme({ level: 'error' }); | ||
|
||
logme.debug('This will not be logged.'); | ||
logme.info('This will not be logged.'); | ||
|
||
logme.error('Win!'); | ||
logme.critical('Double win!'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Logme - Minimalistic logging. | ||
* | ||
* Author: Veselin Todorov <hi@vesln.com> | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
var logme = require('../'); | ||
|
||
logme.templates['info'] = 'logme -NFO- :message'; | ||
logme.info('Custom templates'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Logme - Minimalistic logging. | ||
* | ||
* Author: Veselin Todorov <hi@vesln.com> | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
var logme = require('../'); | ||
|
||
logme.templates['info'] = ':date - INFO - :message'; | ||
logme.info('Custom templates'); | ||
|
||
|
||
logme.tokens['random'] = function() { | ||
return Math.random(); | ||
}; | ||
|
||
logme.templates['info'] = ':date - INFO - :message (:random)'; | ||
logme.info('Custom templates'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Logme - Minimalistic logging. | ||
* | ||
* Author: Veselin Todorov <hi@vesln.com> | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
/** | ||
* Exports the lib. | ||
*/ | ||
module.exports = require('./lib/logme'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/** | ||
* Logme - Minimalistic logging. | ||
* | ||
* Author: Veselin Todorov <hi@vesln.com> | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
/** | ||
* Dependencies. | ||
*/ | ||
var colors = require('colors'); | ||
|
||
/** | ||
* Logme constructor. | ||
* | ||
* @class | ||
*/ | ||
function Logme(config) { | ||
this.options = { | ||
stream: process.stdout, | ||
level: 'debug' | ||
}; | ||
|
||
if (config === Object(config)) { | ||
for (var key in config) { | ||
this.options[key] = config[key]; | ||
} | ||
} | ||
}; | ||
|
||
/** | ||
* Tokens map, used by the message method. | ||
* | ||
* @type {Object} | ||
*/ | ||
Logme.prototype.tokens = { | ||
date: function() { | ||
return new Date().toUTCString(); | ||
} | ||
}; | ||
|
||
/** | ||
* Log levels. | ||
* | ||
* @type {Object} | ||
*/ | ||
Logme.prototype.levels = { | ||
debug: 0, | ||
info: 1, | ||
warning: 2, | ||
error: 3, | ||
critical: 4 | ||
}; | ||
|
||
/** | ||
* Templates. | ||
* | ||
* @type {Object} | ||
*/ | ||
Logme.prototype.templates = { | ||
debug: '- DEBUG -'.magenta + ' :message', | ||
info: '- INFO -'.cyan + ' :message', | ||
warning: '- WARNING -'.yellow + ' :message', | ||
error: '- ERROR -'.red + ' :message', | ||
critical: '- CRITICAL -'.red.bold + ' :message' | ||
}; | ||
|
||
/** | ||
* Formats a log message. | ||
* | ||
* @param {String} level | ||
* @param {String} str | ||
* @returns {String} | ||
*/ | ||
Logme.prototype.message = function(level, str) { | ||
var message = this.templates[level]; | ||
for (var token in this.tokens) { | ||
message = message.replace(':' + token, this.tokens[token]()); | ||
} | ||
return message.replace(':message', str); | ||
}; | ||
|
||
/** | ||
* Writes a message to the stream. | ||
* | ||
* @param {String} level | ||
* @param {String} str | ||
*/ | ||
Logme.prototype.log = function(level, str) { | ||
if (this.levels[level] < this.levels[this.options.level]) return; | ||
var msg = this.message(level, str); | ||
this.options.stream.write(msg + "\n"); | ||
}; | ||
|
||
|
||
/** | ||
* Logs debug message. | ||
* | ||
* @param {String} str | ||
*/ | ||
Logme.prototype.debug = function(str) { | ||
return this.log('debug', str) | ||
}; | ||
|
||
/** | ||
* Logs info message. | ||
* | ||
* @param {String} str | ||
*/ | ||
Logme.prototype.info = function(str) { | ||
return this.log('info', str) | ||
}; | ||
|
||
/** | ||
* Logs warning message. | ||
* | ||
* @param {String} str | ||
*/ | ||
Logme.prototype.warning = function(str) { | ||
return this.log('warning', str) | ||
}; | ||
|
||
/** | ||
* Logs error message. | ||
* | ||
* @param {String} str | ||
*/ | ||
Logme.prototype.error = function(str) { | ||
return this.log('error', str) | ||
}; | ||
|
||
/** | ||
* Logs critical message. | ||
* | ||
* @param {String} str | ||
*/ | ||
Logme.prototype.critical = function(str) { | ||
return this.log('critical', str) | ||
}; | ||
|
||
/** | ||
* Exposing the lib. | ||
*/ | ||
module.exports = exports = new Logme; | ||
|
||
/** | ||
* Exports Logme constructor. | ||
*/ | ||
exports.Logme = Logme; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "logme" | ||
, "version": "0.0.1" | ||
, "description": "Minimalistic stream logger" | ||
, "keywords": ["logger", "logging", "log"] | ||
, "author": "Veselin Todorov <hi@vesln.com>" | ||
, "dependencies": { | ||
"colors": "0.5.1" | ||
} | ||
, "devDependencies": { | ||
"mocha": "0.3.3" | ||
, "should": "0.3.2" | ||
} | ||
, "main": "index" | ||
, "engines": { "node": ">= 0.6.0 < 0.7.0" } | ||
} |
Oops, something went wrong.