moleculer

Selectively filter debug logs for Moleculer


I have healthcheck actions within my services that are called to determine whether the service is up. Due to the frequent calls from automated systems, there are a lot of noise in the debug logs. Is there a way to filter out the system generated debug logs that is printed on each call?

I added logging:false to the routes section and that helped to filter out most of the logging in info but 2 debug logs still gets generated on each healthcheck call

  1. {"ts":1684139586416,"level":"debug","msg":" Alias: \u001b[35m GET\u001b[39m \u001b[36m/api/healthcheck\u001b[39m\u001b[90m => \u001b[39mapi.healthcheck","nodeID":"abc","ns":"","mod":"api","svc":"api"}

  2. {"ts":1684139586417,"level":"debug","msg":"Call action locally. { action: 'api.healthcheck', requestID: '0e62a5bd-7dfe-41b2-af84-f4186758cc99' }","nodeID":"abc","ns":"","mod":"broker"}

I tried to put {type: "Console", options: {level: {"API": false, "**": "debug"},formatter: "json",}} in moleculer.config.ts and that helped to suppress the first debug log but the call action locally log still gets generated.

Is there a better way to not have those 2 debug logs appear, only and only if they are healthcheck related calls? I would still like to maintain the default system logging behaviour for all other api calls.


Solution

  • The second log is a debug message ServiceBroker and there is no way to filter it out of the box by the message's text. You can make your own logger and add message-filtering logic there.

    Or you can add in level disabling of all broker's messages { BROKER: false }

    You can disable any group of messages grouped by the name set in the initialization instance embedded logger. In your output name, mod points to the name of the instance logger as a group of logs.

    You can write this name in uppercase in the configuration in the level object and set the desired logger level. It supports a mask instead of specifying the service version V1.TEST. You can write *.TEST to set the logging level for any TEST service version.