Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated from deprecated 'sys' usage. #17

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ OTHER DEALINGS IN THE SOFTWARE.
*/

var path = require('path'),
sys = require('sys'),
util = 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`
// if `log_file_path` is null, log to STDOUT.
var Logger = function(log_file_path) {
// default write is STDOUT
this.write = sys.print;
this.write = console.log;
this.log_level_index = 3;

// if a path is given, try to write to it
if (log_file_path) {
// Write to a file
Expand All @@ -58,7 +58,7 @@ Logger.levels = ['fatal', 'error', 'warn', 'info', 'debug'];
// 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('');
};
Expand All @@ -71,16 +71,16 @@ Logger.prototype.setLevel = function(new_level) {

// The base logging method. If the first argument is one of the levels, it logs
// to that level, otherwise, logs to the default level. Can take `n` arguments
// and joins them by ' '. If the argument is not a string, it runs `sys.inspect()`
// and joins them by ' '. If the argument is not a string, it runs `util.inspect()`
// to print a string representation of the object.
Logger.prototype.log = function() {
var args = makeArray(arguments),
log_index = Logger.levels.indexOf(args[0]),
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();
Expand All @@ -91,7 +91,7 @@ Logger.prototype.log = function() {
if (typeof arg === 'string') {
message += ' ' + arg;
} else {
message += ' ' + sys.inspect(arg, false, null);
message += ' ' + util.inspect(arg, false, null);
}
});
message = this.format(Logger.levels[log_index], new Date(), message);
Expand All @@ -112,4 +112,4 @@ Logger.levels.forEach(function(level) {
exports.Logger = Logger;
exports.createLogger = function(log_file_path) {
return new Logger(log_file_path);
};
};