log4js-node / log4js-node

A port of log4js to node.js
https://log4js-node.github.io/log4js-node/
Other
5.79k stars 774 forks source link

res.on is not a function #825

Open crycime opened 5 years ago

nomiddlename commented 5 years ago

You're going to need to give me a bit more to go on here. What version of log4js and node are you using? Can you give me a snippet of code that reproduces the error?

rachelichen commented 4 years ago

I use egg middleware ,config below has the same error , can you tell me how to solve it ? **### nodejs.TypeError: res.on is not a function [dev-be] at node_modules/log4js/lib/connect-logger.js:276:11

import { configure, getLogger, connectLogger } from 'log4js' import * as fs from 'fs' const logJson = { appenders: { app: { type: 'dateFile', filename: 'log/aa/aa', pattern: '.yyyy-MM-dd.log', alwaysIncludePattern: true, maxLogSize: 10485760, numBackups: 3, }, console: { type: 'console' }, }, categories: { default: { appenders: ['app', 'console'], level: 'DEBUG'}, }, }


try {
      fs.mkdirSync('./log')
  } catch (e) {
    if (e.code !==  'EEXIST') {
      console.error('Could not set up log directory, error was: ', e)
      process.exit(1)
    }
}
configure(logJson)
getLogger('startup')
export default () => {
    return connectLogger(getLogger('app'), { level: 'auto', format: (req, res, format) => {
        return format(`:remote-addr - ${req.c_id} - ":method :url HTTP/:http-version" :status :content-length ":referrer" ":user-agent"`);
      }})
}

@nomiddlename