Menu

#6 support for accessing fields and methods without parameters of an object in log expressions

1.1.0
open
nobody
None
2014-04-09
2014-04-09
No

probably it can be useful to let access fields and methods without parameters of an object in log expressions

e.g
${args[0].someMethod()}
or
${args[0].someField}

on the other side forcing programmer to use getters for field acceess is good practice.

This ticket is under consideration and won't go to initial release

Discussion

  • Vitaliy Semochkin

    aslo consider addign expressions
    e.g ${args[0].property=true}

    to implement this we will have to use StringTemplate or FreeMarker,
    the cons of this approach is that it can make the logging the cause of an error, and it is never a good idea.

     
    • Illia Krokhmalov

      Vitaliy, it's could be very usefull. For example I don't want to logging full collection, I just want's to logging size ("args[0].size()"). I reccomend to make it as a plugin, with default implementation (current). Or it can be integrate it with spring-expressions, if Spring-exp contains in a classpath.
      On first access:

          Expression expression = new SpelExpressionParser().parseExpression(property)
      

      on logging time:
      instead of LogFormatter::private String toString(Object bean, String property)
      300: toString(stringBuilder, PropertyUtils.getProperty(bean, property));
      can be replaced to
      toString(stringBuilder, expression.getValue(bean))
      (or to the plugin call)

       

Log in to post a comment.

MongoDB Logo MongoDB