public Object getValue ( final String fieldName , final LoggingEvent event ) { String upperField = fieldName . toUpperCase ( Locale . US ) ; if ( LOGGER_FIELD . equals ( upperField ) ) { return event . getLoggerName ( ) ; } else if ( LEVEL_FIELD . equals ( upperField ) ) { return event . getLevel ( ) ; } else if ( MSG_FIELD . equals ( upperField ) ) { return event . getMessage ( ) ; } else if ( NDC_FIELD . equals ( upperField ) ) { String ndcValue = event . getNDC ( ) ; return ( ( ndcValue == null ) ? EMPTY_STRING : ndcValue ) ; } else if ( EXCEPTION_FIELD . equals ( upperField ) ) { String [ ] throwableRep = event . getThrowableStrRep ( ) ; if ( throwableRep == null ) { return EMPTY_STRING ; } else { return getExceptionMessage ( throwableRep ) ; } } else if ( TIMESTAMP_FIELD . equals ( upperField ) ) { return new Long ( event . timeStamp ) ; } else if ( THREAD_FIELD . equals ( upperField ) ) { return event . getThreadName ( ) ; } else if ( upperField . startsWith ( PROP_FIELD ) ) { //note: need to use actual fieldname since case matters Object propValue = event . getMDC ( fieldName . substring ( 5 ) ) ; if ( propValue == null ) { //case-specific match didn't work, try case insensitive match String lowerPropKey = fieldName . substring ( 5 ) . toLowerCase ( ) ; Set entrySet = event . getProperties ( ) . entrySet ( ) ; for ( Iterator iter = entrySet . iterator ( ) ; iter . hasNext ( ) ; ) { Map . Entry thisEntry = ( Map . Entry ) iter . next ( ) ; if ( thisEntry . getKey ( ) . toString ( ) . equalsIgnoreCase ( lowerPropKey ) ) { propValue = thisEntry . getValue ( ) ; } } } return ( ( propValue == null ) ? EMPTY_STRING : propValue . toString ( ) ) ; } else { LocationInfo info = event . getLocationInformation ( ) ; if ( CLASS_FIELD . equals ( upperField ) ) { return ( ( info == null ) ? EMPTY_STRING : info . getClassName ( ) ) ; } else if ( FILE_FIELD . equals ( upperField ) ) { return ( ( info == null ) ? EMPTY_STRING : info . getFileName ( ) ) ; } else if ( LINE_FIELD . equals ( upperField ) ) { return ( ( info == null ) ? EMPTY_STRING : info . getLineNumber ( ) ) ; } else if ( METHOD_FIELD . equals ( upperField ) ) { return ( ( info == null ) ? EMPTY_STRING : info . getMethodName ( ) ) ; } } //there wasn't a match, so throw a runtime exception throw new IllegalArgumentException ( "Unsupported field name: " + fieldName ) ; }
Get value of field .