Interface LogASTTransformation.LoggingStrategy

All Known Subinterfaces:
LogASTTransformation.LoggingStrategyV2
All Known Implementing Classes:
Commons.CommonsLoggingStrategy, Log.JavaUtilLoggingStrategy, Log4j.Log4jLoggingStrategy, Log4j2.Log4j2LoggingStrategy, LogASTTransformation.AbstractLoggingStrategy, LogASTTransformation.AbstractLoggingStrategyV2, PlatformLog.JavaUtilLoggingStrategy, Slf4j.Slf4jLoggingStrategy
Enclosing class:
LogASTTransformation

public static interface LogASTTransformation.LoggingStrategy
A LoggingStrategy defines how to wire a new logger instance into an existing class. It is meant to be used with the @Log family of annotations to allow you to write your own Log annotation provider.
  • Method Details

    • addLoggerFieldToClass

      FieldNode addLoggerFieldToClass(ClassNode classNode, String fieldName, String categoryName)
      In this method, you are given a ClassNode, a field name and a category name, and you must add a new Field onto the class. Return the result of the ClassNode.addField operations.
      Parameters:
      classNode - the class that was originally annotated with the Log transformation.
      fieldName - the name of the logger field
      categoryName - the name of the logging category
      Returns:
      the FieldNode instance that was created and added to the class
    • isLoggingMethod

      boolean isLoggingMethod(String methodName)
    • getCategoryName

      default String getCategoryName(ClassNode classNode, String categoryName)
    • wrapLoggingMethodCall

      Expression wrapLoggingMethodCall(Expression logVariable, String methodName, Expression originalExpression)
    • staticLocationUnsupportedReason

      default String staticLocationUnsupportedReason()
      Why wrapLoggingMethodCallWithLocation(org.codehaus.groovy.ast.expr.Expression, java.lang.String, org.codehaus.groovy.ast.expr.MethodCallExpression, org.codehaus.groovy.ast.expr.Expression, boolean) cannot be used with this strategy in the current compilation, for the compile error reported when staticLocation is requested anyway. A strategy whose logging API accepts a caller-supplied location returns null when that API is resolvable, and names what is missing from the compile classpath when it is not. By default compile-time locations are not implemented.
      Returns:
      the reason compile-time locations are unavailable, or null if they are supported
      Since:
      6.0.0
    • wrapLoggingMethodCallWithLocation

      default Expression wrapLoggingMethodCallWithLocation(Expression logVariable, String methodName, MethodCallExpression originalCall, Expression location, boolean guard)
      Rewrites a logging call so that the logging framework is handed the statement's location, computed at compile time, instead of walking the stack at run time (GROOVY-12378). Only called when staticLocationUnsupportedReason() returned null.
      Parameters:
      logVariable - the logger expression
      methodName - the logging method that was called, e.g. info
      originalCall - the call as written; its arguments are the call's arguments
      location - an expression yielding the StackTraceElement for the statement
      guard - whether the arguments are worth guarding with a level check (they are not all constants or variables)
      Returns:
      the replacement expression, or null to leave the call unchanged
      Since:
      6.0.0