Giter VIP home page Giter VIP logo

Comments (2)

scottgerring avatar scottgerring commented on August 17, 2024

I fixed this in the linked branch, but I think the current behaviour in main is actually right.

When we invoke a function with a sampling rate, we decide per invocation whether or not to bump the level down to DEBUG, including more info for the current execution:

@Around(value = "callAt(logging) && execution(@Logging * *.*(..))", argNames = "pjp,logging")
public Object around(ProceedingJoinPoint pjp,
Logging logging) throws Throwable {
Object[] proceedArgs = pjp.getArgs();
setLogLevelBasedOnSamplingRate(pjp, logging);

If we decide not to, we switch back to the "normal level":

if (samplingRate > sample) {
resetLogLevels(Level.DEBUG);
LOG.debug("Changed log level to DEBUG based on Sampling configuration. " +
"Sampling Rate: {}, Sampler Value: {}.", samplingRate, sample);
} else if (LEVEL_AT_INITIALISATION != LOG.getLevel()) {
resetLogLevels(LEVEL_AT_INITIALISATION);
}
}

So what's the normal level? At the moment in main it is the level that is set after the precedence of the different configuration options are taken into account.

if (POWERTOOLS_LOG_LEVEL != null) {
Level powertoolsLevel = Level.getLevel(POWERTOOLS_LOG_LEVEL);
if (LAMBDA_LOG_LEVEL != null) {
Level lambdaLevel = Level.getLevel(LAMBDA_LOG_LEVEL);
if (powertoolsLevel.intLevel() > lambdaLevel.intLevel()) {
LOG.warn("Current log level ({}) does not match AWS Lambda Advanced Logging Controls minimum log level ({}). This can lead to data loss, consider adjusting them.",
POWERTOOLS_LOG_LEVEL, LAMBDA_LOG_LEVEL);
}
}
resetLogLevels(powertoolsLevel);
} else if (LAMBDA_LOG_LEVEL != null) {
resetLogLevels(Level.getLevel(LAMBDA_LOG_LEVEL));
}
LEVEL_AT_INITIALISATION = LOG.getLevel();

This feels like the right value to switch back to to me. If we change this to reflect the level before we consider the environment variables as in my linked PR, we'll see things like this:

  1. First execution - WARN - taken from POWERTOOLS_LOG_LEVEL
  2. Second execution - sampled - DEBUG
  3. Third execution - ERROR - reset back to the configuration before the environment variables are configured - taken from log4j2.xml

@jeromevdl it's late and I feel like i've have missed something obvious :D For that, there is the PR ready to go ;)

from powertools-lambda-java.

jeromevdl avatar jeromevdl commented on August 17, 2024

yes, the third step is not good, it should be reset to powertools log level, not log4j2.xml, we can close this issue as it's actually better like this.

from powertools-lambda-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.