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

Apply regexp matching over patterns only once #1345

Open
Mumeii opened this issue Nov 11, 2022 · 0 comments
Open

Apply regexp matching over patterns only once #1345

Mumeii opened this issue Nov 11, 2022 · 0 comments

Comments

@Mumeii
Copy link
Contributor

Mumeii commented Nov 11, 2022

Hi

On current log4js version (v6.7.0), I've noticed a potential performance enhancement on PatternLayouts :

This while code block seems to be underachieving the pattern processing, in the way it's applying the regular expression as many times as they are log events.

Is it possible to find a way to have this regular expression applied only once, and have a function return after its processing, that itself would directly produce the awaited formatedString ?

For exemple, turning the following pattern :

|%[{blue}%r|%[%p|%[{yellow}%c|%]%m|

into the following function :

logEvt => util.format(
    "|%s%s|%s%s|%s%s|%s%s|",
    ...[
        replaceToken( '[', logEvt, 'blue' ),
        replaceToken( 'r', logEvt, undefined ),
        replaceToken( '[', logEvt, undefined ),
        replaceToken( 'p', logEvt, undefined ),
        replaceToken( '[', logEvt, 'yellow' ),
        replaceToken( 'c', logEvt, undefined ),
        replaceToken( ']', logEvt, undefined ),
        replaceToken( 'm', logEvt, undefined )
    ]
)

Disclaimer : I'm not certain that what I'm proposing here would enhance performances in any way, it's juste an idea 😉

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