Skip to content

Conversation

@mblythe86
Copy link
Contributor

Allow for anonymous functions in logging calls.
The function is only called if the message is logged. (e.g. if the verbosity is turned up high enough.)
This allows for expensive operations to be avoided in cases where the logging won't happen.

The idea is that this provides a performance benefit. I don't know how "expensive" an operation must be
to actually realize a performance benefit, though.

I added an example in server.ts...
It's probably "expensive" to dump the configuration to JSON, then stringify that JSON for logging.

I originally implemented something similar in my 'digikam-connector' extension, where I used it to log the inputs/outputs of the extension hooks while I was developing and debugging. I figured that running util.inspect() on everything was undesirable in a production environment, but didn't want to remove all my logging statements. So, this seemed like a good compromise.

In my local testing, the typescript still compiles OK, and the messages from server.ts print out exactly as they did before.

Allow for anonymous functions in logging calls.
The function is only called if the message is logged.
(e.g. if the verbosity is turned up high enough.)
This allows for expensive operations to be avoided
in cases where the logging won't happen.

The idea is that this provides a performance benefit.
I don't know how "expensive" an operation must be
to actually realize a performance benefit, though.

I added an example in server.ts...
It's probably "expensive" to dump the configuration
to JSON, then stringify that JSON for logging.
@bpatrik
Copy link
Owner

bpatrik commented Mar 3, 2024

Sounds good to me!

I don't think it matters much tho.

@bpatrik bpatrik merged commit f5f34c5 into bpatrik:master Mar 3, 2024
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

Successfully merging this pull request may close these issues.

2 participants