dominhhai / koa-log4js

log4js-node supports Koa-middleware
https://www.npmjs.com/package/koa-log4
MIT License
82 stars 16 forks source link

AssertionError: app.use() requires a generator function #2

Closed alt-jero closed 8 years ago

alt-jero commented 8 years ago

Hello!

I've been trying to get this to work in a fairly basic Koa app, and though I finally succeeded I had to make a hackish workaround to do so...

According to the example app and the README.md, this should work:

app.use(log4js.koaLogger(log4js.getLogger('http'), { level: 'auto' }));

However I was getting an error:

AssertionError: app.use() requires a generator function

So I browsed the source, did some googling, did some more source browsing and some tinkering which finally amounted to this:

app.use(function *(next) {
  let x = () => {return next};
  yield log4js.koaLogger(log4js.getLogger('http'), { level: 'auto' })(this, x);
});

It looks like the co.wrap() returns a promise? Console.log:

{ [Function: createPromise] __generatorFunction__: [Function] }

So I tried yielding to it with next, but the logger calls yield next() which then complains that next isn't a function. So I wrapped that too.

Am I missing something, or did this just not get updated from Koa 1.x yet? As it is, it works for me now and turns out to be less applicable than I thought to my particular project, but I figured I would open an issue to bring it to your attention anyway.

alt-jero commented 8 years ago

Yay! First GitHub Contribution! Closing this issue, as once the pull request is merged, this will no longer be relevant.