2011-09-28 9 views
5

Joomla 플랫폼 11을 기반으로하는 새로운 Joomla 1.7 시스템으로 게임하고 있습니다 - 이전 Joomla 버전의 모든 로깅 코드는 더 이상 작동하지 않습니다 (로그 항목을 작성하는 것처럼 보이지만 부적절한 구문이므로 메시지가 비어 있음).Joomla 플랫폼에 로그인 11 JLog

JLog의 새 버전에 대한 올바른 구문을 아는 사람이 있습니까? 여기에 나의

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

code-- 기존의 것이 로그 파일을 만들지 만 실제 로그 항목은 다음과 같습니다 : 나는 줌라 워드 프로세서와 웹을 검색하지 않고 찾을 수 없습니다 예했습니다

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

이 클래스를 사용하는 방법.

감사합니다.

+0

, 그들이 existi를 유지 한 것으로 보인다 이전 버전과의 호환성을 위해 Joomla 1.5 로깅 기능. 그러나 어떤 이유로 모든 대문자 "COMMENT"는 더 이상 작동하지 않습니다. "comment"를 사용해야합니다 – julio

답변

8

예, 로깅은 참으로 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-- 감사합니다! 그게 내가 필요한거야. – julio

0

@hbit 들으은 lot..I은 다음과 같이 고정 작동 ..

하지만 함수로 생성 ..

<?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 
****/ 
?> 

희망이 도움이 정보를 찾고있는 사람들을위한

관련 문제