Dan Newton created AVRO-3262:
--------------------------------

             Summary: Include Avro record class name in toString
                 Key: AVRO-3262
                 URL: https://issues.apache.org/jira/browse/AVRO-3262
             Project: Apache Avro
          Issue Type: Improvement
            Reporter: Dan Newton


Avro objects output JSON when they are `toString`'d.

This makes it difficult to understand what Avro objects are being logged when 
passing the whole object into the logging string.

It would be convenient if it contained the class name of the Avro object, so 
that when used in strings or logging its easier to read.

Note, this could be bypassed manually in user code by writing something like 
`"logging ${avroObject::class.java.name} $avroObject"` (I'd write it in Java 
but my head hurts right now).

>From what I looked at, possibly changing `SpecificRecordBase.toString` to the 
>following would resolve the issue:

 
{code:java}
@Override
public String toString() {
  return this.class + " " + getSpecificData().toString(this);
}{code}
 

Possibly the solution might be more elegant than that or in a slightly 
different place.

The solution above assumes that the `toString` isn't being used for anything 
within the Avro code. If other code depends on the fact it outputs JSON then 
what I've suggested won't be suitable. In that situation, we could add a new 
method that contains the class name which can be called from user code and is 
still an improvement. On the flip side, the JSON only output could be moved and 
called from other Avro code, leaving the class name `toString` as the default.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to