Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'json' of undefined #1137

Closed
xeoncross opened this issue Nov 10, 2017 · 10 comments
Closed

Cannot read property 'json' of undefined #1137

xeoncross opened this issue Nov 10, 2017 · 10 comments

Comments

@xeoncross
Copy link

Using the example on the homepage, I get the following error:

/Users/owner/path/log.js:7
    format: winston.format.json(),
                          ^

TypeError: Cannot read property 'json' of undefined
    at Object.setupLogging (/Users/owner/path/log.js:7:27)
    at Object.<anonymous> (/Users/owner/path/server.js:35:8)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Function.Module.runMain (module.js:609:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:578:3
const winston = require('winston');

function setupLogging(app) {
  const logger = winston.createLogger({
    level: 'info',
    format: winston.format.json(),
    transports: [
      //
      // - Write to all logs with level `info` and below to `combined.log`
      // - Write all logs error (and below) to `error.log`.
      //
      new winston.transports.File({ filename: 'error.log', level: 'error' }),
      new winston.transports.File({ filename: 'combined.log' }),
    ],
  });

  //
  // If we're not in production then log to the `console` with the format:
  // `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
  //
  if (process.env.NODE_ENV !== 'production') {
    logger.add(new winston.transports.Console({
      format: winston.format.simple(),
      colorize: true,
    }));
  }

}

module.exports = {
  setupLogging,
};

package.json lists "winston": "^2.4.0"

@xeoncross
Copy link
Author

xeoncross commented Nov 10, 2017

console.log(winston);

Output:

{ version: '2.4.0',
  transports: 
   { Console: [Getter],
     File: [Getter],
     Http: [Getter],
     Memory: [Getter] },
  hash: [Function],
  clone: [Function],
  longestElement: [Function],
  exception: 
   { getAllInfo: [Function],
     getProcessInfo: [Function],
     getOsInfo: [Function],
     getTrace: [Function] },
  config: 
   { allColors: 
      { ... },
     addColors: [Function],
     colorize: [Function],
     cli: { levels: [Object], colors: [Object] },
     npm: { levels: [Object], colors: [Object] },
     syslog: { levels: [Object], colors: [Object] } },
  addColors: [Function],
  Container: [Function],
  Logger: 
   { [Function]
     super_: 
      { [Function: EventEmitter]
        EventEmitter: [Circular],
        usingDomains: false,
        defaultMaxListeners: [Getter/Setter],
        init: [Function],
        listenerCount: [Function] } },
  Transport: 
   { [Function]
     super_: 
      { [Function: EventEmitter]
        EventEmitter: [Circular],
        usingDomains: false,
        defaultMaxListeners: [Getter/Setter],
        init: [Function],
        listenerCount: [Function] } },
  loggers: { loggers: {}, options: {}, default: { transports: [Array] } },
  levels: { error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5 },
  error: [Function],
  warn: [Function],
  info: [Function],
  verbose: [Function],
  debug: [Function],
  silly: [Function],
  log: [Function],
  query: [Function],
  stream: [Function],
  add: [Function],
  remove: [Function],
  clear: [Function],
  profile: [Function],
  startTimer: [Function],
  extend: [Function],
  cli: [Function],
  handleExceptions: [Function],
  unhandleExceptions: [Function],
  configure: [Function],
  setLevels: [Function] }

There does not appear to be a createLogger or format property.

The source shows createLogger is on the exports object.

@xeoncross
Copy link
Author

xeoncross commented Nov 10, 2017

Solved: The readme.md is for version 3. I have version 2.

The homepage shows v3 usage but npm still defaults to v2.

The homepage should probably mention this clearly.

screen shot 2017-11-10 at 4 51 49 pm

@isaachinman
Copy link

It's been three months and this is still the case.

@aral
Copy link
Contributor

aral commented Jan 31, 2018

Just got bitten by this too.

See PR: #1198

@aprudnikoff
Copy link

Got into the same trap. But who cares ¯_(ツ)_/¯

@benwinding
Copy link

Upgrade to v3:

npm i winston@next --save

@ghost
Copy link

ghost commented Feb 14, 2018

benwinding thanks ... a ton ... however, now with BOT Builder Framework from Microsoft (using TypeScript) ... now gives this error: TypeError: Cannot create property 'Symbol(level)' on string 'h'

any help?

@benwinding
Copy link

@sanjivsingh22 Not sure what that is. But if I were debugging.

  1. Comment out as much code as possible until Typescript trans-piles the source correctly.
  2. Find the exact line of code that causes the error
  3. Try putting different TypeScript annotations on that code eg: String, Number. Any...

Hopefully this will lead to closer to a solution.

@DABH
Copy link
Contributor

DABH commented Apr 21, 2018

Going to go ahead and close this since the README has been updated and v3 will be shipping soon. Feel free to open a new issue if any new problems arise. Thanks!

@DABH DABH closed this as completed Apr 21, 2018
@Harkirat99
Copy link

how to check the version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants