consolidation / robo

Modern task runner for PHP
http://robo.li
Other
2.66k stars 305 forks source link

Console logging #746

Open rklak opened 6 years ago

rklak commented 6 years ago

Is there a possibility to change the console output of a Robo? Now it looks like this: image

so it will look more like this (phing like): image

I can write a plugin or something? Maybe there are other formats? Its hard to read when theres no space between commands.

greg-1-anderson commented 6 years ago

I agree that Robo console log formatting could use some love. Currently, it is not possible for a RoboFile to modify how the logger works; however, I'd be open to a PR to improve things in Robo core for everyone.

Applications that use Robo as a Framework can modify the logger and customize the formatting. You should take a look at Provision for Aegir (can't find the right project link at the moment) -- it does a really good job at formatting the console output. Maybe @jonpugh would be willing to help out or at least provide guidance for a Robo PR to improve things.

jonpugh commented 6 years ago

The project is here: https://github.com/provision4/provision

To get it to work I had to completely replace 4 classes: https://github.com/provision4/provision/tree/4.x/src/Provision/Robo

So I'm not really sure how I would proceed here.

Perhaps somewhere in robo, we could look for a special method in the Robofile.php class that could be used to override the default output behaviors?

jonpugh commented 6 years ago

Most of it is here: https://github.com/provision4/provision/blob/4.x/src/Provision/Robo/ProvisionCollection.php

greg-1-anderson commented 6 years ago

Because of some chicken-and-egg problems with dependency injection container initialization, a plugin mechanism for log formatting is a non-goal. We could do it by creating a PSR-3 adapter that accepted another PSR-3 logger to dynamically change the logging mechanism post-DI container creation; however, I don't think we should introduce that sort of complexity into Robo.

Instead, what I think would be a good idea would be to migrate Provision log formatting into Robo core, so that all RoboFiles produced output that looked like provision's output. I haven't really looked into your specific implementation to see if your enhancements could just become PRs in this project, or if it would require some generalization / rework, but there should be something we could do that would produce good results for not too much effort.

jonpugh commented 6 years ago

This sounds like something that would be really fun to work on when I'm sitting at the beach next week.

I'm not sure what it will take but I don't see it being a huge lift now that I'm much more familiar.

Another thing to consider is I'm working on adding monolog to capture all output of @provision4 to send it to the web front end via REST.

Right now provision/aegir bootstraps hostmaster Drupal so it can send messages directly from drush_log() to the web front end. This is why we have such big drush8/9 problems.

Would you be interested in supporting that use case directly in robo?

greg-1-anderson commented 6 years ago

Which use case do you mean, @jonpugh? Multiple autoloaders in Robo is a non-starter, so bootstrapping the hostmaster is out. Adding monolog? Maybe.

jonpugh commented 6 years ago

Just talking about Monolog.

On Fri, Jul 20, 2018, 9:48 AM Greg Anderson notifications@github.com wrote:

Which use case do you mean, @jonpugh https://github.com/jonpugh? Multiple autoloaders in Robo is a non-starter, so bootstrapping the hostmaster is out. Adding monolog? Maybe.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/consolidation/Robo/issues/746#issuecomment-406605995, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGftHeuxF4AKRpuB7NN-QUk44b4zq8zks5uId-8gaJpZM4VE8bd .

greg-1-anderson commented 6 years ago

I was thinking about something like this for Drush, which has similar issues vis-a-vis its logger. Drush 8 allowed folks to swap out Drush's logger, but Drush 9 injects the logger in all sorts of different objects when the DI container is initialized, so changing the logger later would not work. What I figured would work, though, would be to inject a log proxy into the DI container, and let that proxy be injected everywhere. Then, if anyone wanted to change the logger later, they could just grab a reference to the log proxy, and add / remove loggers as desired.

I think that monolog has a logger that could serve this purpose. I also considered just making a trivial one, since it would only be a few lines, and I'm not sure if we would need to pull in all of Monolog.

So, the same applies to Robo. Make a case for including it. Ideally, @DavertMik would 👍 the request before we put it in.

rklak commented 6 years ago

Any update on this?