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

Feature: Log before function #125

Closed
DeanAyalon opened this issue Feb 2, 2024 · 3 comments
Closed

Feature: Log before function #125

DeanAyalon opened this issue Feb 2, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request released

Comments

@DeanAyalon
Copy link
Contributor

DeanAyalon commented Feb 2, 2024

Please follow the general troubleshooting steps first:

  • I've searched on the issue tracker before creating one.
  • I'm running the latest package version.
  • I'm ready to provide help with enhancement if needed.
  • Feature will not break current functionality 👍

Describe the solution you'd like
I would actually like two features:

  • The main is allowing logger[level] to take in either the function as it currently does, or two functions, 'before' and 'after', like so:
{ 
    logger: { 
       error: { 
            before: data => {}, 
            after: data => {} 
        }
    }
}

So that @log could record both before and after the function is executed

Edit

Maybe it should be a different property entirely, so it can be appended to an existing logger decorator without the need to pass the 'after' function again.

  • A 'time' option in the config to measure the runtime of the decorated functions (I believe utilizing console.time should suffice)

And additionally, I have cloned the repository and made a small fix to two issues, if possible, I'd like to push a branch and make a pull request

Example:

@log({
    name: 'appname',
    logger: { 
        info: { 
            before: data => console.log(data.method + ' started', data),
            after: data => console.log(data.method + ' ended', data)
        }
    },
    time: true
})
test = () => console.log('testing') 
test started {
    application: "appname"    // Fixed on my branch 👍 
    <loggerdata, no result/error>
}
testing
test ended {
    application: "appname"
    <loggerdata>
    time: <execution time>    // e.g. 27ms
}

Thank you :)

@DeanAyalon DeanAyalon added the enhancement New feature or request label Feb 2, 2024
@pustovitDmytro
Copy link
Owner

Hi

  1. allowing logger[level] to take in either the function as it currently does, or two functions, 'before' and 'after'

I don't think this API is good because it is impossible to understand whether this should be an error or info before the function actually runs. Additionally, this will break the "classical" logger API.

I guess something like this would be better:

{
    paramsLevel: 'verbose',
    logger: {
        verbose: () => console.log() // Logs are passed here when decorated functions receive params, and params will be added to the payload.
    }
}
  1. A 'time' option in the config
    A 'time' option in the config is not needed, as there is already a benchmark property in the payload, which returns runtime in ms.

  2. You can fork and pull request, but read the contributing guide first: Contributing Guide

@pustovitDmytro
Copy link
Owner

added paramsLevel configuration

pustovitDmytro pushed a commit that referenced this issue Feb 3, 2024
# [1.8.0](v1.7.0...v1.8.0) (2024-02-03)

### New

* adds paramsLevel prop. closes #125 ([1d87f0a](1d87f0a)), closes [#125](#125)
@pustovitDmytro
Copy link
Owner

🎉 This issue has been resolved in version 1.8.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants