I have a custom extension where I need to write information to a log file. For this I am using this code:

jimport('joomla.log.log'); // Include the log library
$priorities = JLog::ALL ^ JLog::WARNING; // exclude warning (because of deprecated)
$logFileName = 'myextension.log.php';
$logCategory = 'com_myextension';
try {
    JLog::addLogger(array('text_file' => $logFileName), $priorities, $logCategory);
    JLog::add($msg, JLog::INFO, $logCategory);
} catch (Exception $e) {
    // logging failed because of unknown reasons, no further action / attempts

This works excellent on all Joomla installs 2.x to 3.x - except for the ones which have the FTP Layer enabled.

I have read on the Joomla Dev CMS list that JLog does not support the FTP layer.

How can I deal with it? Or more specifically: how can I write my own version of JLogLoggerFormattedtext that uses FTP when that layer is enabled?


1 Answer 1


You can override the JLogLoggerFormattedtext class with your own version in one of two ways:

System Plugin

Via a System plugin that triggers onAfterInitialise():

* Registers core library overrides.
* @return   void
public function onAfterInitialise()
    // Override /libraries/joomla/log/logger/formattedtext.php 
    JLoader::register('JLogLoggerFormattedtext', JPATH_LIBRARIES . '/custom/core-overrides/joomla/log/logger/formattedtext.php');

However, by the time onAfterInitialise() is called many core classes have already been initialized and so this method wont work. I don't know if JLogLoggerFormattedtext falls into this category or not.

Core Hack

First, obviously, core hacks are evil. But I've yet to find a working solution when the plugin method doesn't work.

Modify /ROOT/index.php and/or /ROOT/administrator/index.php (depending on if you need this modification for back-end or front-end executions. Put this code:

require_once JPATH_LIBRARIES . '/custom/core-overrides/coreOverrideAutoloader.php';
spl_autoload_register('CoreOverrideAutoloader::loader', true, true);

directly before:

require_once JPATH_BASE . '/includes/framework.php';

(both index.php files have that line)

Create /custom/core-overrides/coreOverrideAutoloader.php:

class CoreOverrideAutoloader

    public static $requested = array();
    public static $filesLoaded = array();
    public static $filesNotLoaded = array();

    public static function loader($class)
        CoreOverrideAutoloader::$requested[] = $class;

        $filename = __DIR__ . '/' . strtolower($class) . '.php';

        if (!file_exists($file))
            CoreOverrideAutoloader::$filesNotLoaded[] = $file;
            return false;
        include $file;
        CoreOverrideAutoloader::$filesLoaded[] = $file;

Then create /custom/core-overrides/jlogloggerformattedtext.php

That'll hold your modified JLogLoggerFormattedtext class:

defined('JPATH_PLATFORM') or die;


class JLogLoggerFormattedtext extends JLogLogger

Creating any other library overrides is as simple as creating additional jclassname.php files in that same folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.