diff --git a/lib/log4js-node.js b/lib/log4js-node.js index b34f062..9c2b571 100644 --- a/lib/log4js-node.js +++ b/lib/log4js-node.js @@ -1,4 +1,4 @@ -var posix = require('posix'), sys = require('sys'); +var fs = require('fs'), sys = require('sys'); var DEFAULT_CATEGORY = '[default]'; var ALL_CATEGORIES = '[all]'; @@ -146,13 +146,7 @@ var log4js = { }, configure: function(configurationFile) { - var config; - posix - .cat(configurationFile) - .addCallback( - function(contents) { config = JSON.parse(contents); } - ).wait(); - + var config = JSON.parse(fs.readFileSync(configurationFile)); configureAppenders(config.appenders); configureLevels(config.levels); }, @@ -382,16 +376,16 @@ consoleAppender = function (layout) { fileAppender = function(file, layout) { layout = layout || basicLayout; file = file || "log4js.log"; - //waits are generally bad, but we need + //syncs are generally bad, but we need //the file to be open before we start doing any writing. - var logFile = posix.open(file, process.O_APPEND | process.O_WRONLY | process.O_CREAT, 0644).wait(); + var logFile = fs.openSync(file, process.O_APPEND | process.O_WRONLY | process.O_CREAT, 0644); //register ourselves as listeners for shutdown //so that we can close the file. //not entirely sure this is necessary, but still. - process.addListener("exit", function() { posix.close(logFile); }); + process.addListener("exit", function() { fs.close(logFile); }); return function(loggingEvent) { - posix.write(logFile, layout(loggingEvent)+'\n', null, "utf-8"); + fs.write(logFile, layout(loggingEvent)+'\n', null, "utf-8"); }; }; diff --git a/spec/spec.logging.js b/spec/spec.logging.js index e49296d..269f3fd 100644 --- a/spec/spec.logging.js +++ b/spec/spec.logging.js @@ -1,12 +1,12 @@ -posix = require('posix'); +fs = require('fs'), events = require('events'); waitForWriteAndThenRead = function (filename) { //here's the tricky part - writes are asynchronous //so I'm going to make a promise, wait a bit and then //try to read the file. - var content, promise = new process.Promise(); + var content, promise = new events.Promise(); promise.addCallback(function() { - content = posix.cat(filename).timeout(500).wait(); + content = posix.readFileSync(filename); }); setTimeout(function() { promise.emitSuccess(); @@ -185,12 +185,12 @@ describe 'log4js' before_each log4js.clearAppenders(); try { - posix.unlink('./tmp-tests.log').wait(); + posix.unlinkSync('./tmp-tests.log'); } catch(e) { print('Could not delete tmp-tests.log: '+e.message); } try { - posix.unlink('./tmp-tests-warnings.log').wait(); + posix.unlinkSync('./tmp-tests-warnings.log'); } catch (e) { print('Could not delete tmp-tests-warnings.log: '+e.message); } diff --git a/tests.js b/tests.js index ce335d0..3af4f2d 100644 --- a/tests.js +++ b/tests.js @@ -3,7 +3,7 @@ require("jspec"); log4js = require("log4js-node"); -var sys = require("sys"), posix = require("posix"); +var sys = require("sys"), fs = require("fs"); quit = process.exit print = sys.puts @@ -11,11 +11,7 @@ print = sys.puts readFile = function(path) { var result; try { - posix - .cat(path) - .addCallback( - function(contents){ result = contents; } - ).wait(); + result = fs.readFileSync(path); } catch (e) { throw e; } @@ -28,13 +24,7 @@ if (process.ARGV[2]) { specsFound = true; JSpec.exec('spec/spec.' + process.ARGV[2] + '.js'); } else { - var files; - posix - .readdir('spec/') - .addCallback( - function(dirFiles) { files = dirFiles; } - ).wait(); - + var files = fs.readdirSync('spec/'); files.filter( function (file) { return file.indexOf('spec.') === 0;