Pages

Jumat, 11 November 2011

Apche日志之错误日志 Apche log of the error log

错误日志和访问日志一样也是Apache的标准日志。 Error log and access log is the same as the standard Apache log. 本文分析错误日志的内容,介绍如何设置和错误日志相关的选项,文档错误和CGI错误的分类,以及如何方便地查看日志内容,等等。 This paper analyzes the contents of the error log, how to setup and error log related options, document classification error and CGI error, and how to easily view the log contents, and so on.

一、位置和内容(4月2日) First, the location and content (April 2)

前文讨论了Apache的访问日志,包括它的内容、格式和如何设置访问日志有关的选项。 Discussed before, the Apache access log, including its content, format and how to set options related to access log. 本文我们要讨论的是另外一种Apache标准日志——错误日志。 This we have to discuss is another standard Apache log - error log.

错误日志无论在格式上还是在内容上都和访问日志不同。 Error log format or in terms of both content and access logs are different. 然而,错误日志和访问日志一样也提供丰富的信息,我们可以利用这些信息分析服务器的运行情况、哪里出现了问题。 However, the same error log and access log also provides a wealth of information, we can use this information to analyze operation of the server, where there is a problem.

错误日志的文件名字是error_log,但如果是Windows平台,则错误日志的文件名字是error.log。 Error log file name error_log, but if the Windows platform, the error log file name is error.log. 错误日志的位置可以通过ErrorLog指令设置: The location of the error log can be set by the ErrorLog directive:

ErrorLog logs/error.log ErrorLog logs / error.log

除非文件位置用“/”开头,否则这个文件位置是相对于ServerRoot目录的相对路径。 Unless file location as "/" at the beginning, otherwise the file location is relative to the ServerRoot directory relative path. 如果Apache采用默认安装方式安装,那么错误日志的位置应该在/usr/local/apache/logs下。 If Apache is installed using the default installation, then the error log should be located in / usr / local / apache / logs next. 但是,如果Apache用某种包管理器安装,错误日志很可能在其他位置。 However, if Apache with some kind of package manager to install, error log is likely in other locations.

正如其名字所示,错误日志记录了服务器运行期间遇到的各种错误,以及一些普通的诊断信息,比如服务器何时启动、何时关闭等。 As its name implies, the server error log records errors encountered during the operation, as well as some general diagnostic information, such as when the server starts, when the closure.

我们可以设置日志文件记录信息级别的高低,控制日志文件记录信息的数量和类型。 We can set the log file to record information level of the level of control log file records the number and type of information. 这是通过LogLevel指令设置的,该指令默认设置的级别是error,即记录称得上错误的事件。 This is done by setting the LogLevel directive, the directive is the default setting of the level of error, that is called the error event log. 有关该指令中允许设置的各种选项的完整清单,请参见http://www.apache.org/docs/mod/core.html#loglevel的Apache文档。 About the instruction set allows a complete list of the various options, see the Apache documentation http://www.apache.org/docs/mod/core.html # loglevel.

大多数情况下,我们在日志文件中见到的内容分属两类:文档错误和CGI错误。 In most cases, we see in the log file is divided into two categories: Documentation error and CGI error. 但是,错误日志中偶尔也会出现配置错误,另外还有前面提到的服务器启动和关闭信息。 However, the error log configuration errors occasionally occur, in addition to the previously mentioned server startup and shutdown information.

错误日志和访问日志一样也是Apache的标准日志。 Error log and access log is the same as the standard Apache log. 本文分析错误日志的内容,介绍如何设置和错误日志相关的选项,文档错误和CGI错误的分类,以及如何方便地查看日志内容,等等。 This paper analyzes the contents of the error log, how to setup and error log related options, document classification error and CGI error, and how to easily view the log contents, and so on.

二、文档错误(4月2日) Second, the documentation errors (April 2)

文档错误和服务器应答中的400系列代码相对应,最常见的就是404错误——Document Not Found(文档没有找到)。 Documentation errors, and server response code corresponding to the 400 series, the most common is the 404 - Document Not Found (document not found). 除了404错误以外,用户身份验证错误也是一种常见的错误。 In addition to 404 other than the user authentication error is a common mistake.

404错误在用户请求的资源(即URL)不存在时出现,它可能是由于用户输入的URL错误,或者由于服务器上原来存在的文档因故被删除或移动。 404 error in the user requested resource (URL) does not exist there, it may be due to the URL entered by the user error, or because of the existence of the original document on the server for some reason been deleted or moved.

顺便说一下,按照Jakob Nielson的意见,在不提供重定向或者其他补救措施的情况下,我们永远不应该移动或者删除Web网站的任何资源。 By the way, according to Jakob Nielson's advice, not to provide redirection or other remedies, we should never move or delete the Web site of any resources. Nielson的更多文章,请参见http://www.zdnet.com/devhead/alertbox/。 Nielson more articles, see http://www.zdnet.com/devhead/alertbox/.

当用户不能打开服务器上的文档时,错误日志中出现的记录如下所示: When users can not open the document on the server, the error appears in the log records as follows:

[Fri Aug 18 22:36:26 2000] [error] [Fri Aug 18 22:36:26 2000] [error]

[client 192.168.1.6] File does not exist: [Client 192.168.1.6] File does not exist:

/usr/local/apache/bugletdocs/ / Usr / local / apache / bugletdocs /


可以看到,正如访问日志access_log文件一样,错误日志记录也分成多个项。 You can see, the same as the access_log file access log, error log records into multiple items.

错误记录的开头是日期/时间标记,注意它们的格式和access_log中日期/时间的格式不同。 Error log is the beginning of the date / time stamp, note in their format and access_log date / time format is different. access_log中的格式被称为“标准英文格式”,这或许是历史跟我们开的一个玩笑,但现在要改变它已经太迟了。 access_log in the format known as "standard English format", which are probably a joke with us, but now too late to change it.

错误记录的第二项是当前记录的级别,它表明了问题的严重程度。 The second error log is the current record level, it shows the extent of the problem. 这个级别信息可能是LogLevel指令的文档中所列出的任一级别(参见前面LogLevel的链接),error级别处于warn级别和crit级别之间。 The LogLevel directive level information may be listed in the document at any level (see LogLevel previous link), error level at the warn level and between levels of crit. 404属于error错误级别,这个级别表示确实遇到了问题,但服务器还可以运行。 ERROR error level is 404, this level that do experience a problem, but the server can also run.

错误记录的第三项表示用户发出请求时所用的IP地址。 The third error log that is used when a user makes a request to the IP address.

记录的最后一项才是真正的错误信息。 The last record is the real error message. 对于404错误,它还给出了完整路径指示服务器试图访问的文件。 For the 404 error, it also gives the full path indicates that the server tries to access the file. 当我们料想某个文件应该在目标位置却出现了404错误时,这个信息是非常有用的。 When should we expect a file in the target position, it was an 404 error, this information is very useful. 此时产生这种错误的原因往往是由于服务器配置错误、文件实际所处的虚拟主机和我们料想的不同,或者其他一些意料不到的情况。 This produces the causes of this error is often due to server configuration error, the actual file in which the virtual hosts and we expect a different, or some other unexpected situations.

由于用户身份验证问题而出现的错误记录如下所示: Since the problem of user authentication error log is as follows:

[Tue Apr 11 22:13:21 2000] [Tue Apr 11 22:13:21 2000]

[error] [client 192.168.1.3] user rbowen@rcbowen. [Error] [client 192.168.1.3] user rbowen @ rcbowen.

com: authentication failure for \"/cgi-bin/hirecareers/company.cgi\": com: authentication failure for \ "/ cgi-bin/hirecareers/company.cgi \":

password mismatch password mismatch
注意,由于文档错误是用户请求的直接结果,因此它们在访问日志中也会有相应的记录。 Note that, due to documentation error is a direct result of user requests, so they will have the appropriate access log records.

错误日志和访问日志一样也是Apache的标准日志。 Error log and access log is the same as the standard Apache log. 本文分析错误日志的内容,介绍如何设置和错误日志相关的选项,文档错误和CGI错误的分类,以及如何方便地查看日志内容,等等。 This paper analyzes the contents of the error log, how to setup and error log related options, document classification error and CGI error, and how to easily view the log contents, and so on.

三、CGI错误(4月2日) Three, CGI error (April 2)

错误日志最主要的用途或许是诊断行为异常的CGI程序。 Perhaps the most important use of the error log to diagnose abnormal behavior of the CGI program. 为了进一步分析和处理方便,CGI程序输出到STDERR(Standard Error,标准错误设备)的所有内容都将直接进入错误日志。 In order to facilitate further analysis and processing, CGI program output to STDERR (Standard Error, standard error) of all content will go directly to the error log. 这意味着,任何编写良好的CGI程序,如果出现了问题,错误日志就会告诉我们有关问题的详细信息。 This means that any well-written CGI program, if there is a problem, the error log will tell us more information about the problem.

然而,把CGI程序错误输出到错误日志也有它的缺点,错误日志中将出现许多没有标准格式的内容,这使得用错误日志自动分析程序从中分析出有用的信息变得相当困难。 However, the CGI program error output to the error log also has its shortcomings, there is no error log will appear in many standard formats, which makes use of automatic error log analysis program to analyze the useful information has become very difficult.

下面是一个例子,它是调试Perl CGI代码时,错误日志中出现的一个错误记录: Here is an example, it is debugging Perl CGI code, the error appears in an error log record:

[Wed Jun 14 16:16:37 2000] [error] [client 192.168.1.3] Premature [Wed Jun 14 16:16:37 2000] [error] [client 192.168.1.3] Premature

end of script headers: /usr/local/apache/cgi-bin/HyperCalPro/announcement.cgi end of script headers: / usr / local / apache / cgi-bin / HyperCalPro / announcement.cgi

Global symbol \"$rv\" requires explicit package name at Global symbol \ "$ rv \" requires explicit package name at

/usr/local/apache/cgi-bin/HyperCalPro/announcement.cgi line 81. / Usr / local / apache / cgi-bin / HyperCalPro / announcement.cgi line 81.

Global symbol \"%details\" requires explicit package name at Global symbol \ "% details \" requires explicit package name at

/usr/local/apache/cgi-bin/HyperCalPro/announcement.cgi line 84. / Usr / local / apache / cgi-bin / HyperCalPro / announcement.cgi line 84.

Global symbol \"$Config\" requires explicit package name at Global symbol \ "$ Config \" requires explicit package name at

/usr/local/apache/cgi-bin/HyperCalPro/announcement.cgi line 133. / Usr / local / apache / cgi-bin / HyperCalPro / announcement.cgi line 133.

Execution of /usr/local/apache/cgi-bin/HyperCalPro/announcement.cgi Execution of / usr / local / apache / cgi-bin / HyperCalPro / announcement.cgi

aborted due to compilation errors. aborted due to compilation errors.

可以看到,CGI错误和前面的404错误格式相同,包含日期/时间、错误级别以及客户地址、错误信息。 You can see, CGI errors and 404 errors in front of the same format with date / time, the error level as well as customer address, an error message. 但这个CGI错误的错误信息有好几行,这往往会干扰一些错误日志分析软件的工作。 But the CGI causes the error message has several lines, which tend to interfere with some of the error log analysis software work.

有了这个错误信息,即使是对Perl不太熟悉的人也能够找出许多有关错误的信息,例如至少可以方便地得知是哪几行代码出现了问题。 With this error message, even for people who are not familiar with Perl can find many information about the error, for example, can easily learn at least a few lines of code in which there is a problem. Perl在报告程序错误方面的机制是相当完善的。 Perl error in the reporting process in the mechanism is quite perfect. 当然,不同的编程语言输出到错误日志的信息会有所不同。 Of course, different programming languages ​​output to error log information will be different.

由于CGI程序运行环境的特殊性,如果没有错误日志的帮助,大多数CGI程序的错误都将很难解决。 CGI programs run as the special nature of the environment, if no error log to help, most of the CGI program errors are difficult to solve.

有不少人在邮件列表或者新闻组中抱怨说自己有一个CGI程序,当打开网页时服务器却返回错误,比如“Internal Server Error”。 There are many people on the mailing list or news group complained that they have a CGI program, but when you open a Web page server returned an error, such as "Internal Server Error". 我们可以肯定,这些人还没有看过服务器的错误日志,或者根本不知道错误日志的存在。 We can be sure that these people have not seen the server's error log, or do not know the existence of the error log. 决多大多数情况下,错误日志能够精确地指出CGI错误的所在以及如何修正这个错误。 Never more than most cases, the error log to pinpoint where the error CGI and how to fix this error.
错误日志和访问日志一样也是Apache的标准日志。 Error log and access log is the same as the standard Apache log. 本文分析错误日志的内容,介绍如何设置和错误日志相关的选项,文档错误和CGI错误的分类,以及如何方便地查看日志内容,等等。 This paper analyzes the contents of the error log, how to setup and error log related options, document classification error and CGI error, and how to easily view the log contents, and so on.

四、查看日志文件(4月2日) Fourth, check the log file (April 2)

我常常告诉别人说,在进行开发的同时我会不断地检查服务器的日志,以便能够立即知道哪儿出了问题。 I often tell people that, during the development and I will continue to check the server logs in order to be able to immediately know where a problem. 但我得到的回答却往往是沉默。 But I get the answer is often silent. 起先我以为这种沉默意味着“你当然得这样做”,后来我才发现这种沉默的真正含义是“我不知道别人的做法,但我自己是不干的。” At first I thought that this silence means "Of course you have to do", but then I discovered the true meaning of this silence, "I do not know the others are doing, but I myself quit."

虽然如此,下面我们还是要看看如何方便地查看服务器日志文件。 Nevertheless, here we have to see how easily view server log files. 用telnet连接到服务器,然后输入下面的命令: Use telnet to connect to the server, then enter the following command:

tail -f /usr/local/apache/logs/error_log tail-f / usr / local / apache / logs / error_log

该命令将显示出日志文件的最后几行内容,如果有新的内容加入到日志文件,它还会立即显示出新加入的内容。 This command will display the last few lines of the log file contents, if there is new content added to the log file, it will immediately display new content.

Windows用户也同样可以使用这种方法,比如可以使用各种为Windows提供的Unix工具软件包。 Windows users can also use this method, such as can be provided using a variety of Unix tools for Windows package. 我个人爱好一个称为AINTX的工具,它可以在http://maxx.mc.net/~jlh/nttools/index.htm找到。 I personally like a tool called AINTX, it can http://maxx.mc.net/ ~ jlh / nttools / index.htm to find.

还有一种替代方法是使用下面的Perl代码,它利用了一个称为File::Tail的模块: Another alternative is to use the following Perl code, which uses a program called File:: Tail module:

use File::Tail; use File:: Tail;

$file=File::Tail->new(\"/some/log/file\"); $ File = File:: Tail-> new (\ "/ some / log / file \");

while (defined($line=$file->read)) { while (defined ($ line = $ file-> read)) {

print \"$line\"; print \ "$ line \";

} }

无论具体采用的是哪一种方法,同时打开多个终端窗口都是一种好习惯:比如在一个窗口中显示错误日志,在另一个窗口中显示访问日志。 No matter which specific method is used, open multiple terminal windows are a good habit: for example, a window displays the error log, in another window display access log. 这样,我们就能够随时获知网站上发生的事情并立即予以解决。 In this way, we can always learn what happened on the website and immediately be resolved.

在这个《Apache日志》系列的下一篇文章中,我们将讨论定制服务器日志,即如何在日志文件中记录所有我们想要的信息,排除所有我们不想要的信息。 In the "Apache Log" series, the next article, we will discuss the custom server logs, that is, how in the log file records all the information we want, we do not want to exclude all the information.

在此之后,我们还将讨论日志文件的处理,即如何从日志文件生成统计报表。 After this, we will also discuss the handling of log files, that is, how to generate statistical reports from log files. 在最后几篇文章中,我们还将讨论如何把日志记录重定向到指定的程序而不是保存到日志文件,以便由程序实时地处理新生成的日志数据,比如将日志数据保存到数据库,或者当发生某些关键性错误时通过email把日志信息发送给系统管理员,等等。 In the last few articles, we will also discuss how to redirect the log to the specified procedure rather than saved to a log file for the program to handle the new generation of real-time log data, such as the log data to the database, or when some critical errors occur when the log information sent by email to the system administrator, and so on.

(仙人掌工作室编译) (Cactus Studio compiler)

Tidak ada komentar:

Posting Komentar