Winston: لا يمكن قراءة الخاصية 'json' من undefined

تم إنشاؤها على ١٠ نوفمبر ٢٠١٧  ·  9تعليقات  ·  مصدر: winstonjs/winston

باستخدام المثال الموجود في الصفحة الرئيسية ، يظهر لي الخطأ التالي:

/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 قوائم "winston": "^2.4.0"

التعليق الأكثر فائدة

تم الحل: الملف readme.md مخصص للإصدار 3. لدي الإصدار 2.

تعرض الصفحة الرئيسية استخدام v3 لكن npm لا يزال افتراضيًا على v2.

ربما يجب أن تذكر الصفحة الرئيسية هذا بوضوح.

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

ال 9 كومينتر

console.log(winston);

انتاج:

{ 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] }

لا يبدو أن هناك خاصية createLogger أو format .

يظهر المصدر

تم الحل: الملف readme.md مخصص للإصدار 3. لدي الإصدار 2.

تعرض الصفحة الرئيسية استخدام v3 لكن npm لا يزال افتراضيًا على v2.

ربما يجب أن تذكر الصفحة الرئيسية هذا بوضوح.

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

لقد مرت ثلاثة أشهر ولا يزال هذا هو الحال.

لقد لدغ من هذا أيضا.

انظر العلاقات العامة: https://github.com/winstonjs/winston/pull/1198

وقع في نفس الفخ. لكن من يهتم ¯_ (ツ) _ / ¯

الترقية إلى الإصدار 3:

npm i winston<strong i="6">@next</strong> --save

شكرًا جزيلاً ... طنًا ... ومع ذلك ، الآن مع BOT Builder Framework من Microsoft (باستخدام TypeScript) ... الآن يعطي هذا الخطأ: TypeError: لا يمكن إنشاء خاصية 'Symbol (level)' في السلسلة 'h'

أي مساعدة؟

@ sanjivsingh22 لست متأكدا ما هذا. ولكن إذا كنت أقوم بالتصحيح.

  1. قم بالتعليق على أكبر قدر ممكن من التعليمات البرمجية حتى تكدس نسخة مطبوعة المصدر بشكل صحيح.
  2. ابحث عن السطر الدقيق من الكود الذي يسبب الخطأ
  3. حاول وضع تعليقات توضيحية مختلفة من TypeScript على هذا الرمز ، على سبيل المثال: String ، Number. أي...

نأمل أن يؤدي هذا إلى الاقتراب من الحل.

المضي قدمًا وإغلاق هذا منذ تحديث README وسيتم شحن الإصدار 3 قريبًا. لا تتردد في فتح عدد جديد في حالة ظهور أي مشاكل جديدة. شكرا!

هل كانت هذه الصفحة مفيدة؟
0 / 5 - 0 التقييمات