RE: [coldbox:7121] suggestion for logEvent format

Given the fact that the extra info can by anything we want-- and in the case of an error can even be a exception bean, I think it would be important to maintain the ability of the extra info to serialize itself where possible with some pre-defined method such as $toString(). This also makes sense from a perspective of complex objects like CFCs being responsible to serializing themselves.

I posted this a while back, but here is what I currently have as my getExtraInfoAsString method in logEvent.cfc

if( isSimpleValue(info) )
{
return info;
}
else if( IsObject(info) AND structKeyExists(info,’$toString’) )
{
return info.$toString();
}
else if( IsObject(info) )
{
return “”; // CFC’s don’t support .toString(). Ideas?
}
else
{
return info.toString();
}

The last “else” statement could be made to fall back on a new extraInfoConversion setting.

Note, I started doing this because my custom exception handler started by-passing the logging plugin and an E-mail appender takes care of my bug report E-mail now. Therefore, I had to handle an exception bean being passed in as the extra info. I added a “$toString()” method to the exception bean that does the same thing as the logger plugin but its encapsulated within the object that the code pertains to.

Thanks!

~Brad

How about this according to the feedback

  1. If incoming is object and has method $toString() use it
    2 if no method then check for conversionformat property (xml,json,plain) and use conversion schema as needed.

Works for me... In the case of Brad's example, you may need to ignore
the "plain" parameter if info is an object and send back serialised
JSON/XML/something anyway -- a blank string isn't too useful and it's
no good if it throws an error.

how about this:

else if( IsObject(info) ) {
    return serializeJSON( getMetadata(info) );
}

Ok, I added my implementation to the logEvent() please check it out.
Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com