Loopback-next: log example: not able to make working

Created on 2 Dec 2019  路  9Comments  路  Source: strongloop/loopback-next

Hi,
steps to reproduce:

  1. $ lb4 example log-extension
  2. $ lb4 app getting-started
    and select all default settings
  3. $ cd getting-started
  4. $ npm install ../loopback4-example-log-extension
  5. modified application.ts file accordingly to instructions https://github.com/strongloop/loopback-next/tree/master/examples/log-extension (actually I was not able to follow instructions directly)
    import {LogMixin, LOG_LEVEL} from '@loopback/example-log-extension';
    ...
    export class GettingStartedApplication extends LogMixin( BootMixin(ServiceMixin(RepositoryMixin(RestApplication))), )
    ...
    added
    this.logLevel(LOG_LEVEL.ERROR);
    after
    this.projectRoot = __dirname;
  6. modified ping.controller.ts
    import {log, LOG_LEVEL} from '@loopback/example-log-extension';
    ...
    // Map toGET /ping @get('/ping', { responses: { '200': PING_RESPONSE, }, }) @log(LOG_LEVEL.DEBUG) ping(): object {
  7. npm start
  8. curl -X GET "http://[::1]:3000/ping" -H "accept: application/json"
    and response is
    {"greeting":"Hello from LoopBack","date":"2019-12-02T18:05:37.436Z","url":"/ping","headers":{"host":"[::1]:3000","user-agent":"curl/7.64.1","accept":"application/json"}}

I'm expecting to see some logging info in terminal where app is started, but nothing happens.
Do I do something wrong?
or
Did I miss something in code?
or
Are my expectations wrong?
or
Is example actually working?

bug

Most helpful comment

this is from documentation
Example Usage
import {LogMixin, LOG_LEVEL, log} from 'loopback4-example-log-extension';
// Other imports ...

class LogApp extends LogMixin(BootMixin(RestApplication)) {
constructor(options?: ApplicationConfig) {
super(options);

this.projectRoot = __dirname;
this.logLevel(LOG_LEVEL.ERROR);

}
}

class MyController {
@log(LOG_LEVEL.WARN)
@get('/')
hello() {
return 'Hello LoopBack';
}

@log(LOG_LEVEL.ERROR)
@get('/name')
helloName() {
return 'Hello Name';
}
}

It means documentation setup is not working ???
Why we have that documentation?
To frustrate people?

All 9 comments

You set logLevel to ERROR but the method is decorated with @log(LOG_LEVEL.DEBUG). DEBUG < ERROR. As a result, the debug logging is not enabled.

this is from documentation
Example Usage
import {LogMixin, LOG_LEVEL, log} from 'loopback4-example-log-extension';
// Other imports ...

class LogApp extends LogMixin(BootMixin(RestApplication)) {
constructor(options?: ApplicationConfig) {
super(options);

this.projectRoot = __dirname;
this.logLevel(LOG_LEVEL.ERROR);

}
}

class MyController {
@log(LOG_LEVEL.WARN)
@get('/')
hello() {
return 'Hello LoopBack';
}

@log(LOG_LEVEL.ERROR)
@get('/name')
helloName() {
return 'Hello Name';
}
}

It means documentation setup is not working ???
Why we have that documentation?
To frustrate people?

I changed code in application.ts
this.logLevel(LOG_LEVEL.DEBUG);
still nothing...
Can you please, before answering, reproduce steps above (it takes max 15 mins) and fix example code or documentation?
Thank you.

@ochemerys I understand that you are frustrated. But I wish that your comments have been more CONSTRUCTIVE. Please be aware that open source projects are community driven and they require collaboration and contribution to make the projects better. There might be bugs in documentation as well as in code. It's great that you reported the issue. We're trying our best to help you.

The log level was an obvious issue that I spotted. The README uses ERROR/WARN but you used DEBUG. In addition, you need to update your sequence.ts to add the logging action. See https://github.com/strongloop/loopback-next/blob/master/examples/log-extension/src/__tests__/acceptance/log.extension.acceptance.ts#L196-L226 as an example.

Hi,
Thank you for pointing me to sequence.ts. I had to make a small modification
if (result) await this.logger(request, args, result);
now it works.

@ochemerys and @raymondfeng , Thank you. You helped me a lot

@ochemerys and @raymondfeng , Thank you. You helped me a lot

+1 thx

Might be a good idea to mention the sequence changes in the example README.md too.

Hi @Drane, sounds like a good idea! Would you like to contribute with a PR? Contribute to LoopBack 4 has some helpful resources to get started.

Was this page helpful?
0 / 5 - 0 ratings