var should = require('should');
var logger = require('../index');
var defaultLogger = require('../index').logger;
var sinon = require('sinon-restore');
var logged = "";
var oldConsoleLog = console.log;

/* NOTE: console.log is mocked in these tests, so any uses of it will be
 * appended to the variabled "logged".  This will include any calls you
 * make to console.log() for the purpose of debugging in these tests.
 *
 * use oldConsoleLog() instead if you need to console.log() for
 * debugging;
 */


describe("logdriver", function(){
  beforeEach(function(){
    logged = "";
    sinon.stub(console, 'log', function(str){
      logged += str + "\n";
    });
  });
  afterEach(function(){
    sinon.restoreAll();
    console.log = oldConsoleLog;
    logged = "";
  });
  it ("provides a default instance of logger with default levels", function(){
    var mylogger = defaultLogger;
    should.exist(mylogger.error);
    should.exist(mylogger.warn);
    should.exist(mylogger.info);
    should.exist(mylogger.debug);
    should.exist(mylogger.trace);
    mylogger.level.should.equal('trace');
  });
  it ("allows log level possibilities to be specified", function(){
    var mylogger = logger({ levels : 
                              ['superimportant', 
                               'checkthisout', 
                               'whocares']});
    should.exist(mylogger.superimportant);
  });
  it ("allows log level to be specified, and doesn't log below that level", function(){
    var mylogger = logger({ level : false});
    mylogger.info("info test"); 
    mylogger.warn("warn test"); 
    mylogger.error("error test"); 
    mylogger.trace("trace test"); 
    logged.should.equal('');
  });
  it ("allows you to specify a log level of false to suppress all output", function(){
    var mylogger = logger({ level : 'info'});
    mylogger.info("info test"); 
    mylogger.warn("warn test"); 
    mylogger.error("error test"); 
    mylogger.trace("trace test"); 
    var lines = logged.split("\n");
    lines[0].should.include('[info]');
    lines[1].should.include('[warn]');
    lines[2].should.include('[error]');
    lines[0].should.include('info test');
    lines[1].should.include('warn test');
    lines[2].should.include('error test');

  });


  it ("allows you to override the default format", function(){
    var mylogger = logger({
      format : function(){
        return JSON.stringify(arguments);
      }
    });
    mylogger.error("here's an error");
    JSON.parse(logged).should.eql({"0":"error","1":"here's an error"});
  });
});

@@ -2003,24 +2003,34 @@
 (%22%5Cn%22);%0A    
+should.ok(
 lines%5B0%5D.sho
@@ -2026,30 +2026,24 @@
 ines%5B0%5D.
-should.
 include
+s
 ('%5Binfo%5D
@@ -2044,22 +2044,33 @@
 %5Binfo%5D')
+)
 ;%0A    
+should.ok(
 lines%5B1%5D
@@ -2070,30 +2070,24 @@
 ines%5B1%5D.
-should.
 include
+s
 ('%5Bwarn%5D
@@ -2088,22 +2088,33 @@
 %5Bwarn%5D')
+)
 ;%0A    
+should.ok(
 lines%5B2%5D
@@ -2114,30 +2114,24 @@
 ines%5B2%5D.
-should.
 include
+s
 ('%5Berror
@@ -2133,22 +2133,33 @@
 error%5D')
+)
 ;%0A    
+should.ok(
 lines%5B0%5D
@@ -2159,30 +2159,24 @@
 ines%5B0%5D.
-should.
 include
+s
 ('info t
@@ -2176,30 +2176,41 @@
 'info test')
+)
 ;%0A    
+should.ok(
 lines%5B1%5D.sho
@@ -2206,30 +2206,24 @@
 ines%5B1%5D.
-should.
 include
+s
 ('warn t
@@ -2227,22 +2227,33 @@
 n test')
+)
 ;%0A    
+should.ok(
 lines%5B2%5D
@@ -2257,22 +2257,16 @@
 %5B2%5D.
-should.
 include
+s
 ('er
@@ -2275,18 +2275,18 @@
 r test')
+)
 ;
-%0A
 %0A  %7D);%0A%0A

stop using should monkey-patch syntax.