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

Serializer on error and custom fields #677

Open
GaikwadPratik opened this issue Dec 17, 2021 · 0 comments
Open

Serializer on error and custom fields #677

GaikwadPratik opened this issue Dec 17, 2021 · 0 comments

Comments

@GaikwadPratik
Copy link

Hi @trentm,

I'm trying to add below test case because I've something similar in my application. But the serializer function is never called.

test('custom serializer on error and params', function (t) {
    var records = [];

    function customSerializer(message) {
        console.log({ message });
        let _maskedMessage = { ...message };
        let _isString = true;
        if (typeof message !== "string") {
            _maskedMessage = JSON.stringify(message);
            _isString = false;
        }
        _maskedMessage = _maskedMessage.replace(/"password":(["])(?:(?=(\\?))\2.)*?\1/gmi, "\"password\": \"*******\"");
        if (_isString === true) {
            return _maskedMessage;
        }
        const _parsed = JSON.parse(_maskedMessage);
        return _parsed;     
    }

    var log = createLogger({ "msg": customSerializer, "_data": customSerializer, "_message": customSerializer, "realm": customSerializer, "params": customSerializer, "serviceAccount": customSerializer, "_msg": customSerializer }, records);
    const err = new Error("T");
    log.info(err, {password: "test"}, "Testing serialization");
    t.has(records[0].msg, "*****");
    t.end();
});

Are the serializers not applied for internal keywords? If that is not the case, what am I missing here?

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