TomFrost / Bristol

Insanely configurable logging for Node.js
MIT License
113 stars 19 forks source link

"TypeError: path must be a string" #16

Closed Hannessa closed 8 years ago

Hannessa commented 8 years ago

Hi,

Getting an error when trying to save to a file. Logging to console works, but I get an error after I add the following line to app.js (I'm using Express v4.13.4 and Node.js v5.10.1):

log.addTarget('file', path.join(__dirname, 'logs', 'errors.log'));

When I try to log something, I get this error in the console:

TypeError: path must be a string
    at TypeError (native)
    at Object.fs.open (fs.js:575:11)
    at WriteStream.open (fs.js:1918:6)
    at new WriteStream (fs.js:1904:10)
    at Object.fs.createWriteStream (fs.js:1859:10)
    at getStream (node_modules\bristol\lib\targets\file.js:23:22)
    at Function.log (node_modules\bristol\lib\targets\file.js:40:12)
    at Bristol._logToTarget (node_modules\bristol\lib\Bristol.js:342:10)
    at node_modules\bristol\lib\Bristol.js:150:8
    at Array.forEach (native)

The folder exists, and I tried changing the path to a string, but still getting the error. Could I be missing something else?

TomFrost commented 8 years ago

You're so close! The second argument to addTarget must be an object. What you want is:

log.addTarget('file', {
  file: path.join(__dirname, 'logs', 'errors.log'))
});
Hannessa commented 8 years ago

Wow, how could I miss that! So embarrassing. Thanks a lot for answering :) Love your library! It's got the perfect mix of features and simplicity.