Code Monkey home page Code Monkey logo

koa-log4js's Issues

How to get request body with customize token?

The code support custom_tokens, but if the replacement is something like ctx.request.body,
I can't pass the option just like:

app.use(log4js.koaLogger(log4js.getLogger("http"), { level: 'auto',
    tokens: [
        { token: ':body', replacement: ctx.request.body}
    ],
    format: ':remote-addr - -' +
    ' ":method :url HTTP/:http-version"' +
    ' :status :content-length ":referrer"' +
    ' ":user-agent"' +
    ' :body'
}))

because ctx is not defined here.

I can use a wrapper, but is there any simple way to solve this problem?

Re: Versions

Sorry to bother you again, but I have a suggestion which may solve the version issue:
If the 2.x branch is for Koa 2.x, would it make sense to add "koa": "^2.0.0" to the package.json dependencies? (And maybe even to the 1.x branch as "koa": "^1.0.0" for consistency?

AssertionError: app.use() requires a generator function

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.

must have a property "appenders" of type object.

when i start my project.it throw new Error :must have a property "appenders" of type object. do you know how can i slove the problem? thank you very much.

Error: Problem with log4js configuration: ({ appenders:
[ { type: 'console', category: 'http' },
{ type: 'console', category: 'kafka' },
{ type: 'console', category: 'mysql' },
{ type: 'console', category: 'redis' },
{ type: 'console', category: 'info' } ] }) - must have a property "appenders" of type object.
at tests.forEach (/media/yanqi/娱乐/work_space/comments-writer-server/node_modules/_log4js@2.5.3@log4js/lib/configuration.js:43:15)

update to "log4js": "1.1.0" ?

Hi:

now the dependency log4js is 0.6

Is there any plan to update to "log4js" to "1.1.0" ?

When I use

log4js.configure(GConfig.log4jsConfig, { reloadSecs: 300 })

got warning :
WARN] log4js - Ignoring configuration reload parameter for "object" configuration.

v2.2.0 could not work with typescript 2.2.1

Hi dominhhai,
After upgrading koa-log4js to 2.2.0, it could not work well as complaining:
\node_modules\.2.2.0@koa-log4\koa-logger.js:50 return async (ctx, next) => { ^ SyntaxError: Unexpected token ( at Object.exports.runInThisContext (vm.js:76:16) at Module._compile (module.js:542:28) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19)

typescript version as:
$ tsc -v Version 2.2.1

while v2.1.0 works well;
May u kindly help on it, thanks~

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.