mathew-kurian / Scribe.js

:scroll: Node.js logging made simple! Online access to logs and more...
https://mathew-kurian.github.io/Scribe.js/
MIT License
284 stars 44 forks source link

SyntaxError: Unexpected token o #65

Open ybitso opened 8 years ago

ybitso commented 8 years ago

I get the error of

                                            SyntaxError: Unexpected token o
    at Object.parse (native)
    at Z:\casu\system\node_modules\scribe-js\lib\logWriter.js:81:45
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
sdfsdfsd

from commandline i run

node server.js

which is

//setup logging
var scribe      = require('scribe-js')({createDefaultConsole : false}); //loads Scribe
var console     = scribe.console({logWriter : {rootPath : ".\\logs\\Server"}}); //set log dir app
//setup global vars
global.scribe   = scribe;
require('./app/runtest'); //run app     

runtest.js is simply:

setTimeout(function() {
     console.log('sdfsdfsd')
     process.exit();
}, 500);

If i put process.exit() outside, everything works Any operation\method\async that I run, it throws the error, but data will still complete

It was working fine last week (on different files, havent tested them again because they are in production. I upgraded my dev of node to 4.1.1 and removed\installed clean scribe and scribe-js

when looking at logWriter.js:81, I added a console.log(data) and the output is not in correct JSON format

{"dates":{"1441944000000":["logs\\Server\\2015\\Sep\\11_sep_15.log.json","logs\\Server\\2015\\Sep\\11_sep_15.error.json"],"1442030400000":["logs\\Server\\2015\\Sep\\12_sep_15.log.json","logs\\Server\\2015\\Sep\\12_sep_15.error.json"],"1442203200000":["logs\\Server\\2015\\Sep\\14_sep_15.log.json","logs\\Server\\2015\\Sep\\14_sep_15.error.json"],"1442808000000":["logs\\Server\\2015\\Sep\\21_sep_15.log.json","logs\\Server\\2015\\Sep\\21_sep_15.error.json"],"1442894400000":["logs\\Server\\2015\\Sep\\22_sep_15.log.json","logs\\Server\\2015\\Sep\\22_sep_15.error.json"],"1442980800000":["logs\\Server\\2015\\Sep\\23_sep_15.log.json"]}}ogs\\Server\\2015\\Sep\\23_sep_15.error.json"]}} 

Notice the last line, it has an extra:

}ogs\\Server\\2015\\Sep\\23_sep_15.error.json"]}}
ybitso commented 8 years ago

I rewrote that file form scratch and didnt get an error, but now working on another file and getting that same error

doit('http:\\www.something.com\getthisfile.zip','c:\\helloworld.zip')

function doit(url,localfile) {
    async.waterfall([
        function(callback) { //download file
            //### if i do console.log here, this line outputs ##Before error
            if (url) {
                var file = fs.createWriteStream(localpath + localfile);
                http.get({
                    url: url,
                    binary: true
                }, function (err, res){
                    if(err) {                         
                        console.error(err);
                        console.log('Error in Download')                      
                        callback(null)                
                    }
                    else {
                        file.write(res.body);
                        file.end(function () {
                         //### if i do console.log here, this line outputs ##After error
                          callback(null)                
                        })                
                    }
                });
            }
            else {
                console.log('Bad URL')
                callback(null)                    
                //### if i do console.log here, this line outputs ##After error
            }
           //### if i do console.log here, this line outputs ##Before error            
        },

        function (callback){        
           //### if i do console.log here, this line outputs ##After error
            //some processing

       }], function (error, results) { //done
           //####never gets here
    });
}
lostcolony commented 8 years ago

I don't know the cause of this, but the fix is to blow away your logs directory. Per what you indicated, it's likely because something was written incorrectly. It's known that calling fs.write multiple times on the same file without waiting for the callback is unsafe; I assume the scribe writes are non-blocking, so that may be the issue, that multiple calls to log aren't properly serialized, leading to writes clobbering each other, leading to corrupted existing logs, which breaks scribe on startup.

marcosPerezRubio commented 8 years ago

Hello,

I'm facing the same problem, if the server crash for any reason the file is corrupted and the only solution that i have found is to dlete the logs folder. Is there a fix or roundabout for this?

Thanks in advance

mathew-kurian commented 8 years ago

Dev branch has a new build using a mongodb backing. perhaps that might be of use