ChannelActivityLogger extends ReformattedLogger { @Override protected String reformat( String message ) { if ( channel == null ) { return message; } String dbConnectionId = getDbConnectionId(); String serverAddress = getServerAddress(); return format( "[0x%s][%s][%s] %s", localChannelId, valueOrEmpty( serverAddress ), valueOrEmpty( dbConnectionId ), message ); } ChannelActivityLogger( Channel channel, Logging logging, Class<?> owner ); private  ChannelActivityLogger( Channel channel, Logger delegate );   }
@Test void shouldReformatWhenChannelIsNull() { ChannelActivityLogger activityLogger = new ChannelActivityLogger( null, Logging.none(), getClass() ); String reformatted = activityLogger.reformat( "Hello!" ); assertEquals( "Hello!", reformatted ); }
@Test void shouldReformatWithChannelId() { EmbeddedChannel channel = new EmbeddedChannel(); ChannelActivityLogger activityLogger = new ChannelActivityLogger( channel, Logging.none(), getClass() ); String reformatted = activityLogger.reformat( "Hello!" ); assertEquals( "[0x" + channel.id() + "][][] Hello!", reformatted ); }
@Test void shouldReformatWithChannelIdAndServerAddress() { EmbeddedChannel channel = new EmbeddedChannel(); ChannelAttributes.setServerAddress( channel, new BoltServerAddress( "somewhere", 1234 ) ); ChannelActivityLogger activityLogger = new ChannelActivityLogger( channel, Logging.none(), getClass() ); String reformatted = activityLogger.reformat( "Hello!" ); assertEquals( "[0x" + channel.id() + "][somewhere:1234][] Hello!", reformatted ); }
@Test void shouldReformatWithChannelIdAndConnectionId() { EmbeddedChannel channel = new EmbeddedChannel(); ChannelAttributes.setConnectionId( channel, "bolt-12345" ); ChannelActivityLogger activityLogger = new ChannelActivityLogger( channel, Logging.none(), getClass() ); String reformatted = activityLogger.reformat( "Hello!" ); assertEquals( "[0x" + channel.id() + "][][bolt-12345] Hello!", reformatted ); }