Hi,
steps to reproduce:
$ lb4 example log-extension$ lb4 app getting-started$ cd getting-started$ npm install ../loopback4-example-log-extensionimport {LogMixin, LOG_LEVEL} from '@loopback/example-log-extension';export class GettingStartedApplication extends LogMixin( BootMixin(ServiceMixin(RepositoryMixin(RestApplication))), )this.logLevel(LOG_LEVEL.ERROR);this.projectRoot = __dirname;import {log, LOG_LEVEL} from '@loopback/example-log-extension';// Map toGET /ping @get('/ping', { responses: { '200': PING_RESPONSE, }, }) @log(LOG_LEVEL.DEBUG) ping(): object {npm startcurl -X GET "http://[::1]:3000/ping" -H "accept: application/json"{"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?
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.
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);
}
}
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?