? ? Success

User tests: Successful: Unsuccessful:

avatar okonomiyaki3000
okonomiyaki3000
11 Jul 2014

So the problem is in JLogLoggerFormattedtext::initFile() which should open a log file for writing.
The first thing this function does is create the parent folder for the file in case it doesn't exist. It does this using JFolder::create which will use your FTP settings if using FTP for file i/o or else php's mkdir. Depending on which is used, the new folder will be owned by the FTP user or the PHP user (usually this is the Apache user but there are various reasons it might be someone else entirely).
Next, the log file itself will be opened for appending. No matter what your FTP settings are, this will be done with fopen (because JFile does not have an append function for some reason). So, if the PHP user (let's say apache for simplicity's sake) does not have access to the file, the operation will fail.
I believe there is one half-assed solution to this problem, one good solution, and one excellent solution:
half-assed: Stop using JFolder::create to create directories here. Peform all file operations as the PHP (Apache) user by using PHP's built in file i/o functions.
good solution: continue to use JFolder::create, make a new function JFile::append and use that it for writing files. Whether to use FTP or not will be determined inside that function as it is determined inside JFolder::create.
excellend solution: Do the good solution + make JLogLoggerFormattedtext recognize an option for file i/o which will have three possible values: system (use the Joomla global settings, this will be default), native (use the php native file i/o functions even when FTP is set in the global settings), and ftp (use ftp even when the Joomla global settings are not configured that way). Obviously, if ftp is set here, the ftp host, port, username, password, and root directory also need to be included in the logger options because they may not have been set in the global settings. This opens up an interesting possibility though. I suppose, in this case, you'd be able to configure your logger to write logs to a remote location on a completely different host machine.

How to reproduce the problem and/or test the patch::
1) Enable FTP for filesystem operations.
2) Configure a 'JLogLoggerFormattedtext' logger to write logs into a non-existent subfolder of your logs folder.
3) Try to write some logs.

avatar okonomiyaki3000 okonomiyaki3000 - open - 11 Jul 2014
avatar okonomiyaki3000 okonomiyaki3000 - change - 11 Jul 2014
Title
Jlogloggerformattedtext use ftp when configured
[#33870] Jlogloggerformattedtext use ftp when configured
avatar okonomiyaki3000
okonomiyaki3000 - comment - 11 Jul 2014

By the way, I don't know what the @since should be for these new functions. 3.4?

avatar Bakual
Bakual - comment - 11 Jul 2014

I would use 3.4 for now. We can always change it when/before we merge it.

avatar okonomiyaki3000
okonomiyaki3000 - comment - 25 Jul 2014

Setup

  • Configure Joomla to use FTP to write to files.
  • Configure a formattedtext logger.

Before

When the logs are written, you will notice that they are being written not by the ftp user but by the apache user (or other depending on how you are actually running PHP). This could be a big problem. You might be using FTP because of some permissions issues, maybe your apache user can't even write to files. Then you'll never have any logs.

After

The logs will be written by the FTP user.

avatar brianteeman brianteeman - change - 21 Aug 2014
Status New Pending
avatar nicksavov nicksavov - change - 21 Aug 2014
Labels Removed: ?
avatar brianteeman brianteeman - change - 21 Sep 2014
Category Libraries
avatar brianteeman brianteeman - change - 21 Sep 2014
The description was changed
avatar okonomiyaki3000
okonomiyaki3000 - comment - 1 Dec 2014

:+1:

avatar mbabker
mbabker - comment - 27 Jun 2015

Looks good to me and improves our filesystem & FTP APIs. I'd say let's get this rebased and look at merging for 3.5.

avatar joomla-cms-bot joomla-cms-bot - change - 29 Jun 2015
Labels Added: ?
avatar okonomiyaki3000
okonomiyaki3000 - comment - 29 Jun 2015

Rebased with the current staging branch

avatar zero-24 zero-24 - change - 29 Jun 2015
Easy No Yes
avatar okonomiyaki3000
okonomiyaki3000 - comment - 30 Jun 2015

This should not have failed. Please rerun Travis.

avatar mbabker
mbabker - comment - 30 Jun 2015

It didn't fail. Travis-CI has been rather subpar lately with builds, consistently timing out (the errored builds were because the jobs stalled for 10 minutes).

avatar RickR2H RickR2H - test_item - 15 Apr 2016 - Tested successfully
avatar RickR2H
RickR2H - comment - 15 Apr 2016

I have tested this item :white_check_mark: successfully on 04ee997

Works!

Instructions for the non technical user:
Start with a site that can be accessed by FTP
Add a custom_html module to the website
Add the following code to the bottom of the html/default.php file
<?php
// Include the JLog class.
jimport('joomla.log.log');

// Log to a specific text file.
JLog::addLogger(
array(
'text_file_path' => 'logs/subfolder'
)
);

JLog::add('Logged');
?>

First test without FTP and see if the folder: logs/subfolder is created
Remove the subfolder
Then enable FTP and see if the folder is created again
To make sure FTP is used you have to change the configuration.php via FTP add wrong FTP credentials.
Refreshing the site gives a blank page. That way there was an error writing the log using FTP.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/3875.

avatar RickR2H
RickR2H - comment - 15 Apr 2016

Works!

Instructions for the non technical user:
Start with a site that can be accessed by FTP
Add a custom_html module to the website
Add the following code to the bottom of the html/default.php file
<?php
// Include the JLog class.
jimport('joomla.log.log');

// Log to a specific text file.
JLog::addLogger(
array(
'text_file_path' => 'logs/subfolder'
)
);

JLog::add('Logged');
?>

First test without FTP and see if the folder: logs/subfolder is created
Remove the subfolder
Then enable FTP and see if the folder is created again
To make sure FTP is used you have to change the configuration.php via FTP add wrong FTP credentials.
Refreshing the site gives a blank page. That way there was an error writing the log using FTP.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/3875.

avatar hvdmeer hvdmeer - test_item - 15 Apr 2016 - Tested successfully
avatar hvdmeer
hvdmeer - comment - 15 Apr 2016

I have tested this item :white_check_mark: successfully on 04ee997


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/3875.

avatar brianteeman brianteeman - change - 15 Apr 2016
Status Pending Ready to Commit
Labels
avatar brianteeman
brianteeman - comment - 15 Apr 2016

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/3875.

avatar joomla-cms-bot joomla-cms-bot - change - 15 Apr 2016
Labels Added: ?
avatar brianteeman brianteeman - change - 15 Apr 2016
Milestone Added:
avatar rdeutz rdeutz - change - 15 Apr 2016
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2016-04-15 15:30:18
Closed_By rdeutz
avatar rdeutz rdeutz - reference | 7f22421 - 15 Apr 16
avatar rdeutz rdeutz - merge - 15 Apr 2016
avatar rdeutz rdeutz - close - 15 Apr 2016
avatar okonomiyaki3000
okonomiyaki3000 - comment - 15 Apr 2016

Awesome. Forgot all about this.

avatar joomla-cms-bot joomla-cms-bot - change - 15 Apr 2016
Labels Removed: ?
avatar rdeutz rdeutz - change - 1 May 2016
Milestone
avatar rdeutz rdeutz - change - 1 May 2016
Milestone Added:
avatar rdeutz rdeutz - change - 1 May 2016
Milestone Added:
avatar rdeutz rdeutz - change - 1 May 2016
Milestone

Add a Comment

Login with GitHub to post a comment