CodeIgniter 2.1.0에서 log_message()
에 의해 생성 된 로그의 파일 이름을 사용자 정의 할 수 있습니까? 기본적으로 파일 이름은 현재 날짜를 기반으로 생성됩니다.codeigniter의 로그 파일 이름을 사용자 정의하십시오 log_message()
답변
log_message()
기능은 일반적인 시스템 기능입니다. 그것은 로깅 오류에 대한 Log::write_log()
방법을 사용합니다. 그것의 좋은 코어 파일을 해킹. 따라서 로그 라이브러리를 확장하고 write_log()
기능을 덮어 쓸 수 있습니다.
아직 Log
클래스를 확장하지 않았다면. CI 2.1.3이이 코드를 사용하여 작업을 만들어 함께 당신의 소원
으로 작동합니다 log_message()
기능보다 파일 application/libraries/MY_Log.php
class MY_Log extends CI_Log {
function MY_Log()
{
parent::__construct();
$this->ci =& get_instance();
}
public function write_log() { //here overriding
if ($this->_enabled === FALSE)
{
return FALSE;
}
$level = strtoupper($level);
if (! isset($this->_levels[$level]) OR
($this->_levels[$level] > $this->_threshold))
{
return FALSE;
}
/* HERE YOUR LOG FILENAME YOU CAN CHANGE ITS NAME */
$filepath = $this->_log_path.'log-'.date('Y-m-d').EXT;
$message = '';
if (! file_exists($filepath))
{
$message .= "<"."?php if (! defined('BASEPATH'))
exit('No direct script access allowed'); ?".">\n\n";
}
if (! $fp = @fopen($filepath, FOPEN_WRITE_CREATE))
{
return FALSE;
}
$message .= $level.' '.(($level == 'INFO') ? ' -' : '-').' ';
$message .= date($this->_date_fmt). ' --> '.$msg."\n";
flock($fp, LOCK_EX);
fwrite($fp, $message);
flock($fp, LOCK_UN);
fclose($fp);
@chmod($filepath, FILE_WRITE_MODE);
return TRUE;
}
}
을 만듭니다. 라이브러리 폴더에 MY_Log.php를 만들었습니다. OP를 필요로하는 정확한 것은 아니지만 모두가 어떻게 modyfy를 이해할 수 있을까요 :)
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP 4.3.2 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2006, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* MY_Logging Class
*
* This library assumes that you have a config item called
* $config['show_in_log'] = array();
* you can then create any error level you would like, using the following format
* $config['show_in_log']= array('DEBUG','ERROR','INFO','SPECIAL','MY_ERROR_GROUP','ETC_GROUP');
* Setting the array to empty will log all error messages.
* Deleting this config item entirely will default to the standard
* error loggin threshold config item.
*
* @package CodeIgniter
* @subpackage Libraries
* @category Logging
* @author ExpressionEngine Dev Team. Mod by Chris Newton
*/
class MY_Log extends CI_Log {
/**
* Constructor
*/
public function __construct()
{
$config =& get_config();
$this->_log_path = ($config['log_path'] != '') ? $config['log_path'] : APPPATH.'logs/';
if (! is_dir($this->_log_path) OR ! is_really_writable($this->_log_path))
{
$this->_enabled = FALSE;
}
if (is_numeric($config['log_threshold']))
{
$this->_threshold = $config['log_threshold'];
}
if ($config['log_date_format'] != '')
{
$this->_date_fmt = $config['log_date_format'];
}
}
private function isCommandLineInterface()
{
return (php_sapi_name() === 'cli');
}
// --------------------------------------------------------------------
/**
* Write Log File
*
* Generally this function will be called using the global log_message() function
*
* @access public
* @param string the error level
* @param string the error message
* @param bool whether the error is a native PHP error
* @return bool
*/
public function write_log($level = 'error', $msg, $php_error = FALSE)
{
if ($this->_enabled === FALSE)
{
return FALSE;
}
$level = strtoupper($level);
if (! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold))
{
return FALSE;
}
$filepath = $this->_log_path.'log-'.date('Y-m-d').'.php';
$message = '';
if (! file_exists($filepath))
{
$message .= "<"."?php if (! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n";
}
if (! $fp = @fopen($filepath, FOPEN_WRITE_CREATE))
{
return FALSE;
}
if ($this->isCommandLineInterface()) {
$message .= 'CMD ';
}
$message .= $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --> '.$msg."\n";
flock($fp, LOCK_EX);
fwrite($fp, $message);
flock($fp, LOCK_UN);
fclose($fp);
@chmod($filepath, FILE_WRITE_MODE);
return TRUE;
}
}
왜 나는 log 대신에 php 확장이 있는지 궁금합니다. '.log'가 아닌 '.php' –
아무 이유없이 CI 개발자가 아마 그렇게 결정했습니다. –
는 나에게 잠재적 인 뒷문처럼 보입니다. 나는 그것을 다시 기록으로 바 꾸었습니다. –
- 1. codeigniter의 테이블에서 사용자 이름을 얻는 방법
- 2. elfinder 파일 관리자를 사용자 정의하십시오.
- 3. 템플릿에서 $ singularHumanName을 사용자 정의하십시오.
- 4. JAX-WS에서 바인딩 이름을 정의하십시오.
- 5. MSBuild에서 프로젝트의 로그 파일을 정의하십시오.
- 6. jQuery 파일 업로드 maxNumberOfFiles를 사용자 정의하십시오.
- 7. Eclipse에서 검색 (파일) 기능을 사용자 정의하십시오.
- 8. Codeigniter의 두 가지 다른 로그 파일 유형에 로그인
- 9. 루프 내에서 배열 이름을 정의하십시오.
- 10. 파일 이름에서 파일 경로를 정의하십시오.
- 11. CodeIgniter의 파일 경로
- 12. cpp 파일 위치를 정의하십시오.
- 13. github에서 gem을 사용자 정의하십시오.
- 14. HtmlHelper.ValidationMessage 출력을 사용자 정의하십시오.
- 15. Google지도의 InfoWindow를 사용자 정의하십시오
- 16. 과거에 시간을 사용자 정의하십시오.
- 17. quicktime iphone을 사용자 정의하십시오.
- 18. xsd : choice 요소에서 JAXB 2.0 생성 메소드 이름을 사용자 정의하십시오.
- 19. 페이 스북을 단추처럼 사용자 정의하십시오.
- 20. Magento 검색 기능을 사용자 정의하십시오.
- 21. 장고 모델 전체에 대한 자세한 이름을 정의하십시오.
- 22. CodeIgniter의 Tank_Auth 테이블 필드 이름 사용자 정의
- 23. Codeigniter의 사용자 권한 제어
- 24. CodeIgniter의 사용자 인증
- 25. JsonResult를 사용할 때 JSON 필드 이름을 정의하십시오.
- 26. 레일 : 모델에 대한 열 이름을 정의하십시오.
- 27. JavaScript : 함수 매개 변수로 변수 이름을 정의하십시오.
- 28. 표보기에서 빈 셀을 사용자 정의하십시오.
- 29. bash에서 "cd"를 사용자 정의하십시오.
- 30. UITableView에서 그룹의 위치를 사용자 정의하십시오.
위대한. 고마워! –
가져 오기 : 치명적인 오류 : 'CI_Controller'클래스가 D : \ projektai \ roachrun \ system \ core \ CodeIgniter.php의 233에 없습니다. –
여전히 작동합니까? 나는 문자 그대로 복사하여 파일 경로 만 바꾸어 복사했지만, 로그는 여전히 기본 파일 이름을 사용하고 있습니다. 또한 php를 추가하는 것을 시도해 보았습니다. –