Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: loggelf in lib/errors.js is not overridable #768

Open
titanism opened this issue Dec 14, 2024 · 1 comment
Open

Bug: loggelf in lib/errors.js is not overridable #768

titanism opened this issue Dec 14, 2024 · 1 comment

Comments

@titanism
Copy link
Contributor

Currently several parts of the codebase have this line:

const errors = require('../../lib/errors.js');

This requires this module: https://github.com/nodemailer/wildduck/blob/master/lib/errors.js

Specifically this code

wildduck/lib/errors.js

Lines 75 to 90 in 7daa0e3

try {
module.exports.gelf.handler.emit('gelf.log', message);
} catch (err) {
// might fail on non-JSONizable input
try {
console.error(err);
console.error(util.inspect(message, false, 3));
} catch (err) {
//ignore
}
}
};
module.exports.notify = (...args) => {
loggelf(...args);
};

When errors.notifyConnection(this.this, err); is called throughout the codebase, it uses this default loggelf and outputs to console:

module.exports.gelf.handler = gelfconf.enabled
    ? new Gelf(gelfconf.options)
    : {
          emit: (channel, message) => console.error(util.inspect(message, false, 3))
      };

This uses wild-config and it is documented here

WildDuck sends gelf-formatted log messages to a Graylog server. Set `log.gelf.enabled=true` in [config](https://github.com/nodemailer/wildduck/blob/2019fd9db6bce1c3167f08e363ab4225b8c8a296/config/default.toml#L59-L66) to use it. Also make sure that the same Gelf settings are set for _zonemta-wildduck_ and _haraka-plugin-wildduck_ in order to get consistent logs about messages throughout the system.

There's no way to disable this programmatically, as it has to be read from a config file:

[log.gelf]
enabled=false
hostname=false # defaults to os.hostname()
component="wildduck"
[log.gelf.options]
graylogPort=12201
graylogHostname='127.0.0.1'
connection='lan'

I suppose we can create a config/default.toml file with this override:

[log]
    [log.gelf]
        enabled=false
        hostname=false # defaults to os.hostname()
        component="wildduck"

However I feel like this should be configurable via code options, e.g. when passed logger option or via server.loggelf.

Curious your thoughts, right now this causes unwanted output in the console for those of us using WildDuck components programmatically.

@titanism
Copy link
Contributor Author

Yes this is a bug, because even if logger is disabled, and if gelf is disabled via the example config above, it will still output to console due to this line:

emit: (channel, message) => console.error(util.inspect(message, false, 3))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant