1

I am getting the following error in console window when running my NodeJs application. I am using log4js for logging. Runtime platform is express.

Error:

undefined:1
?{
^
SyntaxError: Unexpected token ? in JSON at position 0

Code:

var log4js = require('log4js');
var mylog = log4js.configure('log4jsConfig.json');
logger = log4js.getLogger("absolute-logger");

Config json:

{
    "appenders": [
              {
            "type": "file",
            "absolute": true,
            "filename": "c:/temp/log_file.log",
            "maxLogSize": 20480,
            "backups": 10,
            "category": "absolute-logger"
        }
    ]
}

Question: Any thoughts. I am thinking this is parsing error, but not sure how to resolve it.

Thanks,

duncanhall
  • 11,035
  • 5
  • 54
  • 86
sam jack
  • 11
  • 2
  • Can you paste your code, config and error as separate blocks to make it easier to read? – duncanhall Dec 22 '16 at 15:47
  • undefined:1 ?{ ^ SyntaxError: Unexpected token ? in JSON at position 0 – sam jack Dec 22 '16 at 16:29
  • var log4js = require('log4js'); var mylog = log4js.configure('log4jsConfig.json'); logger = log4js.getLogger("absolute-logger"); – sam jack Dec 22 '16 at 16:30
  • In config file (log4jsConfig.json) { "appenders": [ { "type": "file", "absolute": true, "filename": "c:/temp/log_file.log", "maxLogSize": 20480, "backups": 10, "category": "absolute-logger" } ] } – sam jack Dec 22 '16 at 16:30
  • Pasting in the comments doesn't help readability. Please edit your original post and make a separate code block for each part. – duncanhall Dec 22 '16 at 16:31
  • The code is in separate blocks. – sam jack Dec 22 '16 at 16:31
  • sorry, If you read my original post it has three sections,**Error Message:**, **Code (in app.js)**, In config file (log4jsConfig.json) – sam jack Dec 22 '16 at 16:34
  • I have edited your post for you - if this separation is not correct, please update it. – duncanhall Dec 22 '16 at 16:37
  • Thanks Duncanhall. – sam jack Dec 22 '16 at 18:48
  • Try using a json parser to get the character at position 0. It could be that the editor you are using appends file identifiers. For instance, csv files created in the ubuntu libre text editor have a set of characters added to the beginning which make the file unusable for code. – Akshar Apr 27 '17 at 19:44

1 Answers1

0

Are you on a windows system? Sometimes, parsers get upset with \r\n (carriage returns). Try converting it UNIX (new line only) style lines.