2011-09-28 16 views
5

Estoy jugando con el nuevo sistema Joomla 1.7 construido en la plataforma Joomla 11-- y todos mis códigos de registro de versiones anteriores de Joomla ya no funcionan (parecen estar escribiendo entradas de registro pero con sintaxis incorrecta, por lo que los mensajes están en blanco).Iniciando sesión en la plataforma Joomla 11 JLog

¿Alguien sabe la sintaxis adecuada para la nueva versión de JLog? Aquí está mi existente code--

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

Esto crea el archivo de registro, pero la entrada del registro actual es el siguiente:

#<?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 - 

He buscado en la documentación de Joomla y la web y no encontró ejemplos de cómo usar esta clase.

Gracias!

+0

para aquellos que buscan esta información, parece que han mantenido los existi ng Joomla 1.5 funciones de registro para compatibilidad con versiones anteriores. Sin embargo, por alguna razón, el "COMENTARIO" de mayúsculas ya no funciona-- debe usar "comment" – julio

Respuesta

8

Sí, el registro cambiado un poco de hecho en 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'); 
+0

@ hbit-- ¡gracias! eso es exactamente lo que necesitaba. – julio

0

@hbit THX una lot..I fija como este y que funcione ..

pero crea como función ..

<?php 
function logWrite($level, $values, $file='%s.php',$path='',$showOnTop=0, 
    $option='',$component=''){ 
/**** 
jlog Joomla 3.4 
created by:gundambison (2015.04.26). 
THX: [email protected] 
****/ 
    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 
****/ 
?> 

Espero que esta ayuda

Cuestiones relacionadas