php Log_message codeigniter

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33389366/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:28:23  来源:igfitidea点击:

Log_message codeigniter

phpcodeignitererror-loggingerror-log

提问by Nassim Rebhi

I want to use log_message in Codeigniter but log_message does not write anything in the log file.

我想在 Codeigniter 中使用 log_message 但 log_message 没有在日志文件中写入任何内容。

$config['log_threshold'] = 4;

$config['log_path'] = 'http://spsvn01/var/www/html/RAIDLOG/application/logs/';

And in my controller I write :

在我的控制器中,我写道:

log_message('error','USER_INFO '.$user_info['email']);

Thanks a lot !

非常感谢 !

回答by Mr. ED

I would use FCPATH $config['log_path'] = FCPATH . '/application/logs/';once you have set path refresh page. $config['log_threshold'] = 4;

$config['log_path'] = FCPATH . '/application/logs/';一旦您设置了路径刷新页面,我将使用 FCPATH 。$config['log_threshold'] = 4;

$config['log_path'] = FCPATH . '/application/logs/';

Works fine on my end.

对我来说效果很好。

http://www.codeigniter.com/user_guide/general/errors.html

http://www.codeigniter.com/user_guide/general/errors.html

Informational Messages

信息性消息

log_message('info','USER_INFO '.$user_info['email']);

Error Messages

错误信息

log_message('error','USER_INFO '.$user_info['email']);

Folder Must Be Writable CHMOD 700

文件夹必须是可写的 CHMOD 700

回答by Nere

Just as simple like this:

就像这样简单:

$config['log_threshold'] = 4;

$config['log_path'] = '/logs/';

回答by Zia

open the your_project_dir/application/config/config.php

打开 your_project_dir/application/config/config.php

In config file you'll find 3 default variables

在配置文件中,您将找到 3 个默认变量

$config['log_threshold']=0; 
$config['log_path'] = ''; 
$config['log_file_extension'] = '';
  1. $config['log_threshold'] accepts array (1, 2, 3) or single integer $config['log_path'] accepts path of log file (if you keep it blank the default path will be set and default path will be your_project_dir/application/logs/).
  2. $config['log_file_extension'] accepts log file extension i.e html, txt etc. (if you keep it empty then default extension will be php)
  3. Make sure your log path is write able.
  1. $config['log_threshold'] 接受数组 (1, 2, 3) 或单个整数 $config['log_path'] 接受日志文件的路径(如果将其保留为空白,则将设置默认路径,默认路径将是 your_project_dir/应用程序/日志/)。
  2. $config['log_file_extension'] 接受日志文件扩展名,即 html、txt 等(如果将其保留为空,则默认扩展名将为 php)
  3. 确保您的日志路径可以写入。

Error Status are already definedIn

错误状态已定义

your_project_dir/system/core/Log.php

your_project_dir/system/core/Log.php

protected $_levels = array('ERROR' => 1, 'DEBUG' => 2, 'INFO' => 3, 'ALL' => 4)

You've to assign array i.e for errors and info array(1, 2) Method log_message('', '') accepts 2 parameters. First parameter is level (i.e. ERROR or DEBUG or INFO or ALL) & second parameter is message.

您必须为错误和信息分配数组,即 array(1, 2) 方法 log_message('', '') 接受 2 个参数。第一个参数是级别(即 ERROR 或 DEBUG 或 INFO 或 ALL),第二个参数是消息。

Example:

例子:

log_message('ERROR', 'Custom error here.');

RememberAll default php errors will be part of the log if you assign

请记住,如果您分配,所有默认的 php 错误都将成为日志的一部分

$config['log_threshold']=array(1)

For custom Logs:You've to add a new array element in your_project_dir/system/core/Log.php i.e.

对于自定义日志:您必须在 your_project_dir/system/core/Log.php 中添加一个新的数组元素,即

protected $_levels = array('ERROR' => 1, 'DEBUG' => 2, 'INFO' => 3, 'ALL' => 4, 'CUSTOM' => 5);

Now you can call method as

现在你可以调用方法作为

log_message('CUSTOM', 'Custom message here.'); // This will put just your custom messages in log file