private String format ( LogEvent event ) { JsonObject jsonEvent = new JsonObject ( ) ; jsonEvent . addProperty ( "v" , 0 ) ; jsonEvent . addProperty ( "level" , BUNYAN_LEVEL . get ( event . getLevel ( ) ) ) ; jsonEvent . addProperty ( "levelStr" , event . getLevel ( ) . toString ( ) ) ; jsonEvent . addProperty ( "name" , event . getLoggerName ( ) ) ; try { jsonEvent . addProperty ( "hostname" , InetAddress . getLocalHost ( ) . getHostName ( ) ) ; } catch ( UnknownHostException e ) { jsonEvent . addProperty ( "hostname" , "unkown" ) ; } jsonEvent . addProperty ( "pid" , event . getThreadId ( ) ) ; jsonEvent . addProperty ( "time" , formatAsIsoUTCDateTime ( event . getTimeMillis ( ) ) ) ; jsonEvent . addProperty ( "msg" , event . getMessage ( ) . getFormattedMessage ( ) ) ; jsonEvent . addProperty ( "src" , event . getSource ( ) . getClassName ( ) ) ; if ( event . getLevel ( ) . isMoreSpecificThan ( Level . WARN ) && event . getThrown ( ) != null ) { JsonObject jsonError = new JsonObject ( ) ; Throwable e = event . getThrown ( ) ; jsonError . addProperty ( "message" , e . getMessage ( ) ) ; jsonError . addProperty ( "name" , e . getClass ( ) . getSimpleName ( ) ) ; StringWriter sw = new StringWriter ( ) ; PrintWriter pw = new PrintWriter ( sw ) ; e . printStackTrace ( pw ) ; jsonError . addProperty ( "stack" , sw . toString ( ) ) ; jsonEvent . add ( "err" , jsonError ) ; } return GSON . toJson ( jsonEvent ) + "\n" ; }
Format the event as a Bunyan style JSON object .