Logging in Joomla platform 11 JLog
Asked Answered
F

2

5

I'm playing with the new Joomla 1.7 system built on the Joomla platform 11-- and all my logging code from earlier versions of Joomla no longer work (they appear to be writing log entries but with improper syntax, so the messages are blank).

Does anyone know the proper syntax for the new version of JLog? Here's my existing code--

$log = &JLog::getInstance('test.log.php');
$log->addEntry(array('COMMENT' => 'A test Logging message'));

This creates the log file, but the actual log entry looks like this:

#<?php die('Forbidden.'); ?>
#Date: 2011-08-08 16:59:42 UTC
#Software: Joomla Platform 11.1 Stable+Modified [ Ember ] 01-Jun-2011 06:00 GMT

#Fields: date   time    priority    clientip    category    message
2011-08-08  16:59:42    INFO    127.0.0.1   -

I've searched the Joomla docs and the web and found no examples of how to use this class.

Thanks!

Formalin answered 28/9, 2011 at 16:4 Comment(1)
For anyone looking for this information, it appears that they have kept the existing Joomla 1.5 logging functions for backward-compatibility. However, for some reason the all caps "COMMENT" no longer works-- you must use "comment"Formalin
I
8

Yes, the logging changed a bit indeed in Joomla 1.7:

// Include the JLog class.
jimport('joomla.log.log');

// Add the logger.
JLog::addLogger(
     // Pass an array of configuration options
    array(
            // Set the name of the log file
            'text_file' => 'test.log.php',
            // (optional) you can change the directory
            'text_file_path' => 'somewhere/logs'
     )
);

// start logging...
JLog::add('Starting to log');
Intensive answered 30/9, 2011 at 6:50 Comment(0)
M
0

@hbit thx a lot..I fixed like this and it work..

but I created as function..

<?php 
function logWrite($level, $values, $file='%s.php',$path='',$showOnTop=0,
   $option='',$component=''){
/****
jlog Joomla 3.4
created by:gundambison (2015.04.26). 
THX: hbit@stackoverflow
****/
    jimport('joomla.log.log'); 
    $level=strtoupper($level);  
//You can change this com_name
    $component= $component==''? 'com_gundambison': $component;
    $date= date("Ymd");
    $filename= sprintf($file, $date);
    $format= $option=='' ?"{TIME}\t{CLIENTIP}\t{CATEGORY}\t{MESSAGE}": $option;

// create options and text
    $txt = is_array($values)? json_encode($values): $values;
    $options = array('text_file' => $filename,'text_entry_format'=>$format );
    $options['text_file_path']=$path==''?'logs': $path; 
    JLog::addLogger ($options);
/*
if you want the error to show in your page. 
*/  
    if($showOnTop==1){
        JLog::add("$level\t$txt");
    }else{ 
        JLog::add("$level\t$txt",$level,$component);
    }
}
/****
result:
  14:28:39  ::1 com_whatever    ALERT   task:error
****/
?>

Hope this Help

Macule answered 26/4, 2015 at 15:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.