2121
2222class Logger
2323{
24- private InputInterface $ input ;
2524 private OutputInterface $ output ;
2625 private HandlerInterface $ fileLog ;
2726
2827 private ?float $ startTime = null ;
2928
30- public function __construct (InputInterface $ input , OutputInterface $ output , HandlerInterface $ log )
29+ public function __construct (OutputInterface $ output , HandlerInterface $ log )
3130 {
32- $ this ->input = $ input ;
3331 $ this ->output = $ output ;
3432 $ this ->fileLog = $ log ;
3533 }
@@ -40,6 +38,7 @@ public function command(Host $host, string $type, string $command): void
4038 if ($ this ->output ->isVerbose ()) {
4139 $ this ->output ->writeln ("[ $ host] <fg=green;options=bold> $ type</> $ command " );
4240 }
41+ $ this ->fileLog ->log ("[ {$ host ->getAlias ()}] $ type: $ command " );
4342 }
4443
4544 /**
@@ -62,21 +61,13 @@ public function callback(Host $host, bool $forceOutput): callable
6261 public function printBuffer (string $ type , Host $ host , string $ buffer ): void
6362 {
6463 foreach (explode ("\n" , rtrim ($ buffer )) as $ line ) {
65- $ this ->writeln ($ type , $ host , $ line );
66- }
67- }
68-
69- public function writeln (string $ type , Host $ host , string $ line ): void
70- {
71- // Omit empty lines
72- if (empty ($ line )) {
73- return ;
64+ if (empty ($ line )) {
65+ return ;
66+ }
67+ $ this ->output ->writeln ("[ $ host] $ line " );
7468 }
75-
76- $ this ->output ->writeln ("[ $ host] $ line " );
7769 }
7870
79-
8071 public function startTask (Task $ task ): void
8172 {
8273 $ this ->startTime = round (microtime (true ) * 1000 );
@@ -89,6 +80,7 @@ public function startTask(Task $task): void
8980 } else {
9081 $ this ->output ->writeln ("<fg=cyan;options=bold>task</> {$ task ->getName ()}" );
9182 }
83+ $ this ->fileLog ->log ("# task {$ task ->getName ()}" );
9284 }
9385
9486 public function endTask (Task $ task ): void
@@ -113,10 +105,7 @@ public function endTask(Task $task): void
113105 $ this ->output ->writeln ("<fg=yellow;options=bold>done</> {$ task ->getName ()} $ taskTime " );
114106 }
115107
116- if (!empty ($ this ->input ->getOption ('profile ' ))) {
117- $ line = sprintf ("%s \t%s \n" , $ task ->getName (), $ taskTime );
118- file_put_contents ($ this ->input ->getOption ('profile ' ), $ line , FILE_APPEND );
119- }
108+ $ this ->fileLog ->log ("# done {$ task ->getName ()} $ taskTime " );
120109 }
121110
122111 public function endOnHost (Host $ host ): void
@@ -129,7 +118,6 @@ public function endOnHost(Host $host): void
129118 public function renderException (Throwable $ exception , Host $ host ): void
130119 {
131120 if ($ exception instanceof RunException) {
132-
133121 $ message = "[ $ host] <fg=white;bg=red> error </> <comment>in {$ exception ->getTaskFilename ()} on line {$ exception ->getTaskLineNumber ()}:</> \n" ;
134122 if ($ this ->output ->getVerbosity () === OutputInterface::VERBOSITY_NORMAL ) {
135123 $ message .= "[ $ host] <fg=green;options=bold>run</> {$ exception ->getCommand ()}\n" ;
@@ -148,7 +136,6 @@ public function renderException(Throwable $exception, Host $host): void
148136 }
149137 $ message .= "[ $ host] <fg=red>exit code</> {$ exception ->getExitCode ()} ( {$ exception ->getExitCodeText ()}) \n" ;
150138 $ this ->output ->write ($ message );
151-
152139 } else {
153140 $ message = "" ;
154141 $ class = get_class ($ exception );
@@ -178,6 +165,8 @@ public function renderException(Throwable $exception, Host $host): void
178165 $ this ->output ->write ($ message );
179166 }
180167
168+ $ this ->fileLog ->log ($ exception ->__toString ());
169+
181170 if ($ exception ->getPrevious ()) {
182171 $ this ->renderException ($ exception ->getPrevious (), $ host );
183172 }
0 commit comments