@Test public void formatNonLogMessage_without_add_time() { Log4jKettleLayout layout = new Log4jKettleLayout( false ); String actualResult = layout.format( mock( LoggingEvent.class ) ); assertThat( actualResult, equalTo( "<null>" ) ); }
public String format( LoggingEvent event ) { StringBuffer line = new StringBuffer(); String dateTimeString = ""; if ( timeAdded ) { dateTimeString = LOCAL_SIMPLE_DATE_PARSER.get().format( new Date( event.timeStamp ) ) + " - "; } Object object = event.getMessage(); if ( object instanceof LogMessage ) { LogMessage message = (LogMessage) object; String[] parts = message.getMessage().split( Const.CR ); for ( int i = 0; i < parts.length; i++ ) { line.append( dateTimeString ); if ( message.getSubject() != null ) { line.append( message.getSubject() ); if ( message.getCopy() != null ) { line.append( "." ).append( message.getCopy() ); } line.append( " - " ); } if ( message.isError() ) { BuildVersion buildVersion = BuildVersion.getInstance(); line.append( ERROR_STRING ); line.append( " (version " ); line.append( buildVersion.getVersion() ); if ( !Utils.isEmpty( buildVersion.getRevision() ) ) { line.append( ", build " ); line.append( buildVersion.getRevision() ); } if ( !Utils.isEmpty( buildVersion.getBuildDate() ) ) { line.append( " from " ); line.append( buildVersion.getBuildDate() ); } if ( !Utils.isEmpty( buildVersion.getBuildUser() ) ) { line.append( " by " ); line.append( buildVersion.getBuildUser() ); } line.append( ") : " ); } line.append( parts[i] ); if ( i < parts.length - 1 ) { line.append( Const.CR ); } } } else { line.append( dateTimeString ); line.append( ( object != null ? object.toString() : "<null>" ) ); } return line.toString(); }
Log4jKettleLayout extends Layout implements Log4JLayoutInterface { public String format( LoggingEvent event ) { StringBuffer line = new StringBuffer(); String dateTimeString = ""; if ( timeAdded ) { dateTimeString = LOCAL_SIMPLE_DATE_PARSER.get().format( new Date( event.timeStamp ) ) + " - "; } Object object = event.getMessage(); if ( object instanceof LogMessage ) { LogMessage message = (LogMessage) object; String[] parts = message.getMessage().split( Const.CR ); for ( int i = 0; i < parts.length; i++ ) { line.append( dateTimeString ); if ( message.getSubject() != null ) { line.append( message.getSubject() ); if ( message.getCopy() != null ) { line.append( "." ).append( message.getCopy() ); } line.append( " - " ); } if ( message.isError() ) { BuildVersion buildVersion = BuildVersion.getInstance(); line.append( ERROR_STRING ); line.append( " (version " ); line.append( buildVersion.getVersion() ); if ( !Utils.isEmpty( buildVersion.getRevision() ) ) { line.append( ", build " ); line.append( buildVersion.getRevision() ); } if ( !Utils.isEmpty( buildVersion.getBuildDate() ) ) { line.append( " from " ); line.append( buildVersion.getBuildDate() ); } if ( !Utils.isEmpty( buildVersion.getBuildUser() ) ) { line.append( " by " ); line.append( buildVersion.getBuildUser() ); } line.append( ") : " ); } line.append( parts[i] ); if ( i < parts.length - 1 ) { line.append( Const.CR ); } } } else { line.append( dateTimeString ); line.append( ( object != null ? object.toString() : "<null>" ) ); } return line.toString(); } }
Log4jKettleLayout extends Layout implements Log4JLayoutInterface { public String format( LoggingEvent event ) { StringBuffer line = new StringBuffer(); String dateTimeString = ""; if ( timeAdded ) { dateTimeString = LOCAL_SIMPLE_DATE_PARSER.get().format( new Date( event.timeStamp ) ) + " - "; } Object object = event.getMessage(); if ( object instanceof LogMessage ) { LogMessage message = (LogMessage) object; String[] parts = message.getMessage().split( Const.CR ); for ( int i = 0; i < parts.length; i++ ) { line.append( dateTimeString ); if ( message.getSubject() != null ) { line.append( message.getSubject() ); if ( message.getCopy() != null ) { line.append( "." ).append( message.getCopy() ); } line.append( " - " ); } if ( message.isError() ) { BuildVersion buildVersion = BuildVersion.getInstance(); line.append( ERROR_STRING ); line.append( " (version " ); line.append( buildVersion.getVersion() ); if ( !Utils.isEmpty( buildVersion.getRevision() ) ) { line.append( ", build " ); line.append( buildVersion.getRevision() ); } if ( !Utils.isEmpty( buildVersion.getBuildDate() ) ) { line.append( " from " ); line.append( buildVersion.getBuildDate() ); } if ( !Utils.isEmpty( buildVersion.getBuildUser() ) ) { line.append( " by " ); line.append( buildVersion.getBuildUser() ); } line.append( ") : " ); } line.append( parts[i] ); if ( i < parts.length - 1 ) { line.append( Const.CR ); } } } else { line.append( dateTimeString ); line.append( ( object != null ? object.toString() : "<null>" ) ); } return line.toString(); } Log4jKettleLayout();  Log4jKettleLayout( boolean addTime ); }
Log4jKettleLayout extends Layout implements Log4JLayoutInterface { public String format( LoggingEvent event ) { StringBuffer line = new StringBuffer(); String dateTimeString = ""; if ( timeAdded ) { dateTimeString = LOCAL_SIMPLE_DATE_PARSER.get().format( new Date( event.timeStamp ) ) + " - "; } Object object = event.getMessage(); if ( object instanceof LogMessage ) { LogMessage message = (LogMessage) object; String[] parts = message.getMessage().split( Const.CR ); for ( int i = 0; i < parts.length; i++ ) { line.append( dateTimeString ); if ( message.getSubject() != null ) { line.append( message.getSubject() ); if ( message.getCopy() != null ) { line.append( "." ).append( message.getCopy() ); } line.append( " - " ); } if ( message.isError() ) { BuildVersion buildVersion = BuildVersion.getInstance(); line.append( ERROR_STRING ); line.append( " (version " ); line.append( buildVersion.getVersion() ); if ( !Utils.isEmpty( buildVersion.getRevision() ) ) { line.append( ", build " ); line.append( buildVersion.getRevision() ); } if ( !Utils.isEmpty( buildVersion.getBuildDate() ) ) { line.append( " from " ); line.append( buildVersion.getBuildDate() ); } if ( !Utils.isEmpty( buildVersion.getBuildUser() ) ) { line.append( " by " ); line.append( buildVersion.getBuildUser() ); } line.append( ") : " ); } line.append( parts[i] ); if ( i < parts.length - 1 ) { line.append( Const.CR ); } } } else { line.append( dateTimeString ); line.append( ( object != null ? object.toString() : "<null>" ) ); } return line.toString(); } Log4jKettleLayout();  Log4jKettleLayout( boolean addTime ); String format( LoggingEvent event ); boolean ignoresThrowable(); void activateOptions(); boolean isTimeAdded(); void setTimeAdded( boolean addTime ); }
Log4jKettleLayout extends Layout implements Log4JLayoutInterface { public String format( LoggingEvent event ) { StringBuffer line = new StringBuffer(); String dateTimeString = ""; if ( timeAdded ) { dateTimeString = LOCAL_SIMPLE_DATE_PARSER.get().format( new Date( event.timeStamp ) ) + " - "; } Object object = event.getMessage(); if ( object instanceof LogMessage ) { LogMessage message = (LogMessage) object; String[] parts = message.getMessage().split( Const.CR ); for ( int i = 0; i < parts.length; i++ ) { line.append( dateTimeString ); if ( message.getSubject() != null ) { line.append( message.getSubject() ); if ( message.getCopy() != null ) { line.append( "." ).append( message.getCopy() ); } line.append( " - " ); } if ( message.isError() ) { BuildVersion buildVersion = BuildVersion.getInstance(); line.append( ERROR_STRING ); line.append( " (version " ); line.append( buildVersion.getVersion() ); if ( !Utils.isEmpty( buildVersion.getRevision() ) ) { line.append( ", build " ); line.append( buildVersion.getRevision() ); } if ( !Utils.isEmpty( buildVersion.getBuildDate() ) ) { line.append( " from " ); line.append( buildVersion.getBuildDate() ); } if ( !Utils.isEmpty( buildVersion.getBuildUser() ) ) { line.append( " by " ); line.append( buildVersion.getBuildUser() ); } line.append( ") : " ); } line.append( parts[i] ); if ( i < parts.length - 1 ) { line.append( Const.CR ); } } } else { line.append( dateTimeString ); line.append( ( object != null ? object.toString() : "<null>" ) ); } return line.toString(); } Log4jKettleLayout();  Log4jKettleLayout( boolean addTime ); String format( LoggingEvent event ); boolean ignoresThrowable(); void activateOptions(); boolean isTimeAdded(); void setTimeAdded( boolean addTime ); static final String ERROR_STRING; }