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

setConfig can't update/re-set adapterOptions - bug? #101

Open
FingerlessGlov3s opened this issue Jan 24, 2025 · 2 comments
Open

setConfig can't update/re-set adapterOptions - bug? #101

FingerlessGlov3s opened this issue Jan 24, 2025 · 2 comments
Assignees

Comments

@FingerlessGlov3s
Copy link

Hi,

If I want to change out the adapter host or port for example, using setConfig(), it'll work unless I've logged at least one message. If I have sent a log message, then I have to null out the adapter property for setConfig() to work for the new adapterOptions.

I'm not sure if this wanted behaviour or if setConfig should be nulling the property when adapterOptions is updated. Would you say this is a bug or wanted behaviour?

Example below, just changing port number.

var log = require("gelf-pro");

log.setConfig({
    adapterOptions: {
        host: "GraylogServer.lan",
        port: 10001,
        family: 4,
        timeout: 1000,
        key: fs.readFileSync(`${root}/tls/cert.key`), // tcp-tls only
        cert: fs.readFileSync(`${root}/tls/cert.pem`), // tcp-tls only
    },
});

log.info(`Should error because wrong port`, {}, function (err, bytesSent) {
    if (err) {
        console.log(`Error in log:`, err);
    }
});

setTimeout(function () {
    log.setConfig({
        adapterOptions: {
            host: "GraylogServer.lan",
            port: 10002,
            family: 4,
            timeout: 1000,
            key: fs.readFileSync(`${root}/tls/cert.key`),
            cert: fs.readFileSync(`${root}/tls/cert.pem`),
        },
    });
    log.adapter = null; // Without this the below will error because it didn't get an updated adapter property, as it's created on first log message from the config provided by setConfig() above
    log.info(`should use 10002 input on the graylog server not 10001`, {}, function (err, bytesSent) {
        if (err) {
            console.log(`Error in log:`, err);
        }
    });
}, 5000);
@kkamkou
Copy link
Owner

kkamkou commented Jan 26, 2025

Thx for the detailed issue report. You're absolutely right. I'll address this in the upcoming custom_aliases branch.
This library was initially designed with a cloning concept in mind, utilizing Object.create. However, it seems this approach is not widely adopted. The 1.x branch will maintain the current behavior.

You posted this at a very convenient time, aligning perfectly with the scope of the mentioned branch. kudo.

@kkamkou kkamkou self-assigned this Jan 26, 2025
@FingerlessGlov3s
Copy link
Author

No problem, I look forward to what changes 2.x brings.

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

No branches or pull requests

2 participants