title: intercept field access to log with bytebuddy
body: <p>I am trying to log field writes with bytebuddy. After reading some earlier posts, I started using <code>MemberSubstitution</code> and got something going using the following code:</p>
  <pre><code>private static Method FIELD_INTERCEPTOR = // reflective reference to interceptFieldWrite
  AsmVisitorWrapper VISITOR = MemberSubstitution.relaxed()
    .field(ElementMatchers.any())
    .onWrite()
    .replaceWith(FIELD_INTERCEPTOR)
    .on(ElementMatchers.isMethod());
  ..
  public static void interceptFieldWrite(Object object,Object value) {
     System.out.println(&quot;intercepted field write in object &quot; + object + &quot; , attempt to set value to &quot; + value);
  }
  ..
  </code></pre>
  <p>The part I am struggling with is how to pass a reference to the field for which the access is intercepted to <code>interceptFieldWrite</code> (as string or instance of <code>Field</code>). If possible I would of course like to avoid reflection completely. I don't actually want to completely substitute field access, but just want to add a method with some checks just before it takes place. Is there a feature in bytebuddy to do this, or do I have to use something more low-level than ASM to achieve this ?</p>