3131
3232package org .scijava .module .process ;
3333
34+ import static org .junit .Assert .assertEquals ;
3435import static org .junit .Assert .assertTrue ;
3536
3637import java .util .concurrent .ExecutionException ;
3940import org .scijava .Context ;
4041import org .scijava .command .Command ;
4142import org .scijava .command .CommandService ;
43+ import org .scijava .log .DefaultLogger ;
44+ import org .scijava .log .LogLevel ;
4245import org .scijava .log .LogService ;
46+ import org .scijava .log .LogSource ;
4347import org .scijava .log .Logger ;
4448import org .scijava .log .TestLogListener ;
4549import org .scijava .plugin .Parameter ;
4650
47- import static org .junit .Assert .assertEquals ;
48-
4951/**
5052 * Tests {@link LoggerPreprocessor}.
5153 *
@@ -64,6 +66,25 @@ public void testInjection() throws InterruptedException, ExecutionException {
6466 assertTrue (listener .hasLogged (m -> m .source ().path ().contains (CommandWithLogger .class .getSimpleName ())));
6567 }
6668
69+ /** Tests redirection of a command's log output. */
70+ @ Test
71+ public void testCustomLogger () throws ExecutionException ,
72+ InterruptedException
73+ {
74+ // setup
75+ final Context context = new Context (CommandService .class );
76+ final CommandService commandService = context .service (CommandService .class );
77+ final TestLogListener listener = new TestLogListener ();
78+ final LogSource source = LogSource .newRoot ();
79+ final DefaultLogger customLogger = new DefaultLogger (listener , source ,
80+ LogLevel .TRACE );
81+ // process
82+ commandService .run (CommandWithLogger .class , true , "log" , customLogger )
83+ .get ();
84+ // test
85+ assertTrue (listener .hasLogged (m -> m .source ().equals (source )));
86+ }
87+
6788 public static class CommandWithLogger implements Command {
6889
6990 @ Parameter
0 commit comments