joomlatools / joomlatools-composer

Composer extension installer for Joomla.
https://www.joomlatools.com/developer/tools/composer/
GNU General Public License v3.0
52 stars 13 forks source link

Add joomla logger to stdout #4

Closed cdekok closed 9 years ago

cdekok commented 9 years ago

When there is an error in the installer joomla simply logs it, by adding the echo logger you see the output in the terminal example:

    Cloning a13e35d8a70ba28789667b054dd2cfaf32cf3a2a

    Installing into Joomla

WARNING: JInstaller: :Install: File does not exist tmp/picturae/com_searchall/administrator/components/com_search_all/search_all.xml [jerror]
WARNING: Component Install: Failed to copy admin files. [jerror]

  [RuntimeException]
  Error while installing picturae/com_searchall
stevenrombauts commented 9 years ago

@Mech7 Thank you Chris, this is an excellent addition!

However, I get errors when testing this. The authenticate() call to Application fails because the error logger already put out some warnings:

Installing dependencies (including require-dev)
...

WARNING: JRequest is deprecated. [deprecated]
WARNING: JDatabase::getErrorNum() is deprecated, use exception handling instead. [deprecated]
DEBUG: SELECT `data`
FROM `j_session`
WHERE `session_id` = '36bb1818427e4973dc89a2d8e2c34b0c' [databasequery]

  [ErrorException]                                                                                                                                      
  session_start(): Cannot send session cookie - headers already sent by (output started at /var/www/joomla25/libraries/joomla/log/loggers/echo.php:48)  

We'll have to find a way to fix this first.

cdekok commented 9 years ago

Hi @stevenrombauts on which joomla version did you get this error? I tried it with 3.4 and it worked for me, i did get 2 warning notices about deprecated methods for getFile and another method, but i believe they came from the joomla cms installer code wanted to look at that a later time.

stevenrombauts commented 9 years ago

This is on 2.5 actually, have not tested on 3.2 and up yet.

cdekok commented 9 years ago

Ah it will probably be an error in 2.5 joomla code, not sure if there is workaround except by fixing the joomla code :(

cdekok commented 9 years ago

@stevenrombauts I have raised the log level and limited the category, it looks like Jinstaller only logs to a jerror category so there shouldn't be any output now with deprecated methods which log to a deprecated category and caused the session to fail.

stevenrombauts commented 9 years ago

Thanks again. I don't think we can solve this by picking another log level, as it only masks the issue.

We were thinking about moving this into a separate config flag maybe? That would mean no logging by default. If you want to debug, you can enable it by adding a debug: loglevel setting to your composer.json file.

Same way we do with setting a different user as explained here. That config is always available through $composer->getConfig().

I'll make the changes so we can try it out. Love to hear your thoughts on this.

cdekok commented 9 years ago

Yeah i guess we can try that, but one thing the deprecated warnings all come from the joomla core do we really care about that when installing a component? Also if we don't hide it should we really care about joomla 2.5 it's already end of life and not officially supported by joomla itself.

stevenrombauts commented 9 years ago

You're right about joomla 2.5 being phased out, it might not be worth the trouble. However, if you've enabled debugging you would expect to see everything. If you only raise the log level for the installation method you might be withholding important clues.

I played around with it a bit more and the solution is actually very obvious. Echo outputs to php://output but we want to output to STDOUT since we're just talking to the console.

If we output everything to php://stdout it won't end up in the output buffers, and session_start() has no more reason to complain. So I just added a custom logger that streams to STDOUT instead of using echo. (see this commit and this commit)

I've also removed the need for an extra configuration setting by adapting Composer's verbosity setting. (look in the output of composer list for verbosity) There are three available flags: -v for verbosity, -vv for extra verbosity or -vvv for debug. Based on that I'm setting the Joomla logger priorities too, see this code

Let me know if that works for you too! I've tested this on 2.5, 3.3 and 3.4. Thanks again :-)

cdekok commented 9 years ago

That looks pretty nice :+1: perhaps will be even better if it logs everything except info level to STDERR and info to STDOUT

stevenrombauts commented 9 years ago

@Mech7 Good point, stderr makes more sense. I've merged these changes and tagged a new version. You should get v1.0.4 of the installer via Composer and that will include your changes.

Thanks a lot for your contribution and advice! Greatly appreciated.