From ae4112194291fab3da8ed48120bc6c5b64667bb2 Mon Sep 17 00:00:00 2001 From: fatshotty Date: Mon, 25 Jun 2012 15:40:05 +0200 Subject: [PATCH 1/5] use util instead of sys. Use stdout instead of sys.print --- logger.js | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/logger.js b/logger.js index 33e5690..b5f53a5 100644 --- a/logger.js +++ b/logger.js @@ -29,11 +29,11 @@ OTHER DEALINGS IN THE SOFTWARE. */ var path = require('path'), - sys = require('sys'), + sys = require('util'), fs = require('fs'); -var makeArray = function(nonarray) { - return Array.prototype.slice.call(nonarray); +var makeArray = function(nonarray) { + return Array.prototype.slice.call(nonarray); }; // Create a new instance of Logger, logging to the file at `log_file_path` @@ -42,23 +42,37 @@ var Logger = function(log_file_path) { // default write is STDOUT this.write = sys.print; this.log_level_index = 3; - + // if a path is given, try to write to it if (log_file_path) { // Write to a file - log_file_path = path.normalize(log_file_path); - this.stream = fs.createWriteStream(log_file_path, {flags: 'a', encoding: 'utf8', mode: 0666}); - this.stream.write("\n"); - this.write = function(text) { this.stream.write(text); }; + this.useFile( log_file_path ); + } else { + // write log into stdout + this.stream = process.stdout; } + + this.stream.write("\n"); + this.write = function(text) { this.stream.write(text); }; + + return this; }; Logger.levels = ['fatal', 'error', 'warn', 'info', 'debug']; + +// This method make Logger uses a file +Logger.prototype.useFile = function(path) { + log_file_path = path.normalize(log_file_path); + this.stream = fs.createWriteStream(log_file_path, {flags: 'a', encoding: 'utf8', mode: 0666}); + this.stream.write("\n"); + return this; +}; + // The default log formatting function. The default format looks something like: // // error [Sat Jun 12 2010 01:12:05 GMT-0400 (EDT)] message -// +// Logger.prototype.format = function(level, date, message) { return [level, ' [', date, '] ', message].join(''); }; @@ -79,8 +93,8 @@ Logger.prototype.log = function() { message = ''; // if you're just default logging - if (log_index === -1) { - log_index = this.log_level_index; + if (log_index === -1) { + log_index = this.log_level_index; } else { // the first arguement actually was the log level args.shift(); From 423175f86b0d4ddd5b20db107e57cc19ed661ef0 Mon Sep 17 00:00:00 2001 From: fatshotty Date: Mon, 25 Jun 2012 15:42:31 +0200 Subject: [PATCH 2/5] fix typo --- logger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logger.js b/logger.js index b5f53a5..7220a72 100644 --- a/logger.js +++ b/logger.js @@ -62,7 +62,7 @@ Logger.levels = ['fatal', 'error', 'warn', 'info', 'debug']; // This method make Logger uses a file -Logger.prototype.useFile = function(path) { +Logger.prototype.useFile = function(log_file_path) { log_file_path = path.normalize(log_file_path); this.stream = fs.createWriteStream(log_file_path, {flags: 'a', encoding: 'utf8', mode: 0666}); this.stream.write("\n"); From 654016ddc50afed6c61717eff635c70f1fee7b72 Mon Sep 17 00:00:00 2001 From: fatshotty Date: Thu, 11 Oct 2012 15:59:48 +0200 Subject: [PATCH 3/5] change versione and name of the project --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 9bc52c1..de9d1cb 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ -{ "name" : "logger" -, "version" : "0.0.1" -, "description" : "A simple logging library that combines the simple APIs of Ruby's logger.rb and browser-js console.log()" -, "author" : "Aaron Quint " +{ "name" : "fat-logger" +, "version" : "1.0.0" +, "description" : "This is a simple fork of https://github.com/quirkey/node-logger" +, "author" : "Fatshotty " , "main" : "logger" , "engines" : { "node" : ">=0.1.90" } } From 52b96876afdbddf34ecc854adff4c4266adb0917 Mon Sep 17 00:00:00 2001 From: fatshotty Date: Thu, 11 Oct 2012 16:00:59 +0200 Subject: [PATCH 4/5] docs --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4ee163d..8feab2f 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ ## SUMMARY +Removed the `sys.print` because it is obsolete A simple logging library that combines the simple APIs of Ruby's logger.rb and browser-js console.log() ## USAGE @@ -11,14 +12,14 @@ A simple logging library that combines the simple APIs of Ruby's logger.rb and b A logger has 5 different levels of logging in a specific order: 'fatal', 'error', 'warn', 'info', 'debug' - -Each of these log levels has its own method on the logging instance. You can set the maximum log level on a logger at runtime. + +Each of these log levels has its own method on the logging instance. You can set the maximum log level on a logger at runtime. By default, a logger writes to STDOUT, but given a writeable file path, it will log directly to a file. ### Instantiation: - // node/common.js style + // node/common.js style var logger = require('./logger').createLogger(); // logs to STDOUT var logger = require('./logger').createLogger('development.log'); // logs to a file @@ -43,7 +44,7 @@ You can completely customize the look of the log by overriding the `format()` me }; logger.debug('message'); //=> 1276365362167; message - + ## COMMENTS/ISSUES: F-f-fork it, baby. From 5b80950a6a3850cc37c69db7d8944f349f2c707f Mon Sep 17 00:00:00 2001 From: fatshotty Date: Thu, 11 Oct 2012 16:01:43 +0200 Subject: [PATCH 5/5] name --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index de9d1cb..afeb3ba 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,4 @@ -{ "name" : "fat-logger" +{ "name" : "simple-logger" , "version" : "1.0.0" , "description" : "This is a simple fork of https://github.com/quirkey/node-logger" , "author" : "Fatshotty "