User tests: Successful: Unsuccessful:
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.
Title |
|
I would use 3.4 for now. We can always change it when/before we merge it.
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.
The logs will be written by the FTP user.
Status | New | ⇒ | Pending |
Labels |
Removed:
?
|
Category | ⇒ | Libraries |
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.
Labels |
Added:
?
|
Rebased with the current staging branch
Easy | No | ⇒ | Yes |
This should not have failed. Please rerun Travis.
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).
I have tested this item 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.
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.
I have tested this item successfully on 04ee997
Status | Pending | ⇒ | Ready to Commit |
Labels |
Labels |
Added:
?
|
Milestone |
Added: |
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 |
Awesome. Forgot all about this.
Labels |
Removed:
?
|
Milestone |
Milestone |
Added: |
Milestone |
Added: |
Milestone |
By the way, I don't know what the
@since
should be for these new functions. 3.4?