search
Homephp教程php手册PHP中把错误日志保存在系统日志中(Windows系统),php日志

PHP中把错误日志保存在系统日志中(Windows系统),php日志

【将错误记录到系统日志中】

在 php.ini 中将 error_log 设置为:

复制代码 代码如下:
error_log = syslog

或者在运行时使用 ini_set() 函数设置。

【例1】

<&#63;php
//关闭错误显示
ini_set('display_errors', 0);
//开启错误日志功能
ini_set('log_errors', 'on');
//设置错误日志的路径
ini_set('error_log', 'syslog');
//显示所有错误
error_reporting(-1);

//记录错误
//通知级别的错误
echo $test; 
//警告
settype($var, 'dee');
//致命错误
test();

查看错误日志(Windows 系统):

"我的电脑" ---- 右键 ----- 管理 ----- 事件查看器 ----- 信息

 

 

 【例2】通过 openlog() 发送系统日志

<&#63;php
//关闭错误显示
ini_set('display_errors', 0);
//开启错误日志功能
ini_set('log_errors', 'on');
//设置错误日志的路径
ini_set('error_log', 'syslog');
//显示所有错误
error_reporting(-1);

//打开系统日志的连接
openlog('PHP5.3.10', LOG_PID, LOG_SYSLOG); //openlog:Open connection to system logger
//发送日志
syslog(LOG_ERR, 'this is a test of a syslog'.date("Y-m-d H:i:s"));
//关闭系统日志的连接
closelog();

在事件查看器的警告信息中也能看到日志:

 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools