Apache | ログファイル | ログファイルの場所(CustomLog, ErrorLog)

アクセスログとエラーログの場所はhttpd.confに定義されている。まずアクセスログから見ていく。

アクセスログ: CustomLog

アクセスログファイルの場所はCustomLogで指定する。httpd.confCustomLogを検索すると、次のような内容が見つかる。

<IfModule log_config_module>
    #
    # The following directives define some format nicknames for use with
    # a CustomLog directive (see below).
    #
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    #
    # The location and format of the access logfile (Common Logfile Format).
    # If you do not define any access logfiles within a <VirtualHost>
    # container, they will be logged here.  Contrariwise, if you *do*
    # define per-<VirtualHost> access logfiles, transactions will be
    # logged therein and *not* in this file.
    #
    CustomLog "logs/access.log" common

    #
    # If you prefer a logfile with access, agent, and referer information
    # (Combined Logfile Format) you can use the following directive.
    #
    #CustomLog "logs/access.log" combined
</IfModule>

アクセスログファイルを指定するCustomLogの形式は次のとおりである。

CustomLog ログファイルの場所 ログ形式名

ログファイルの場所はServerRootの場所からの相対位置で指定する。ServerRootについては「サーバー配置ディレクトリ(ServerRoot)」を参照する。

ログ形式名は、LogFormatで定義されたどのログを記録するかを指定するものである。LogFormatの末尾に書かれている文字列がフォーマット名になる。フォーマット内容の詳細は別ページで説明する。

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common

したがって、1行目のLogFormat名はcombinedであり、2行目のLogFormat名はcommonである。

デフォルトで有効になっているアクセスログは次のように定義されている。

 CustomLog "logs/access.log" common

この設定では、ログファイル名はaccess.logで、ログフォーマットはcommonになっている。

エラーログ: ErrorLog

エラーログファイルの場所はErrorLogで指定する。httpd.confErrorLogを検索すると、次のような内容が見つかる。

#
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog "logs/error.log"

エラーログファイルの場所もServerRootの場所からの相対位置で指定される。

ログファイルの確認

アクセスログとエラーログはテキストファイルなので、テキストエディタで開くことができる。

C:\apache\Apache24\logs>dir
 C 드라이브의 볼륨에는 이름이 없습니다.
 볼륨 일련 번호: XXXX-XXXX

 C:\apache\Apache24\logs 디렉터리

2019-12-05  오후 11:29    <DIR>          .
2019-12-05  오후 11:29    <DIR>          ..
2019-12-05  오후 11:25            17,108 access.log
2019-12-05  오후 11:29            60,733 error.log
2019-12-05  오후 11:29                 7 httpd.pid
2019-08-09  오후 11:50             3,146 install.log
               4개 파일              80,994 바이트
               2개 디렉터리  450,580,013,056 바이트 남음

C:\apache\Apache24\logs>

access.log

127.0.0.1 - - [03/Dec/2019:01:21:23 +0900] "GET /referer.html HTTP/1.1" 304 -
127.0.0.1 - - [03/Dec/2019:01:21:23 +0900] "GET /img/devkuma.jpg HTTP/1.1" 403 199
::1 - - [03/Dec/2019:01:21:32 +0900] "GET /referer.html HTTP/1.1" 304 -
::1 - - [03/Dec/2019:01:21:32 +0900] "GET /img/devkuma.jpg HTTP/1.1" 304 -
127.0.0.1 - - [03/Dec/2019:01:21:51 +0900] "GET /img/devkuma.jpg HTTP/1.1" 200 5168
::1 - - [03/Dec/2019:01:22:43 +0900] "-" 408 -
::1 - - [03/Dec/2019:01:22:43 +0900] "-" 408 -
127.0.0.1 - - [03/Dec/2019:01:22:51 +0900] "-" 408 -
127.0.0.1 - - [03/Dec/2019:01:53:07 +0900] "GET /admin/admin.page HTTP/1.1" 401 381
127.0.0.1 - - [03/Dec/2019:01:53:34 +0900] "GET /admin/admin.html HTTP/1.1" 401 381
127.0.0.1 - - [03/Dec/2019:01:54:12 +0900] "GET / HTTP/1.1" 200 99

error.log

[Thu Dec 05 23:27:14.834393 2019] [mpm_winnt:notice] [pid 5788:tid 580] AH00364: Child: All worker threads have exited.
[Thu Dec 05 23:27:14.852887 2019] [mpm_winnt:notice] [pid 11848:tid 576] AH00430: Parent: Child process 5788 exited successfully.
[Thu Dec 05 23:29:01.662578 2019] [mpm_winnt:notice] [pid 10168:tid 668] AH00455: Apache/2.4.41 (Win64) PHP/7.4.0 configured -- resuming normal operations
[Thu Dec 05 23:29:01.662578 2019] [mpm_winnt:notice] [pid 10168:tid 668] AH00456: Apache Lounge VS16 Server built: Aug  9 2019 16:46:32
[Thu Dec 05 23:29:01.662578 2019] [core:notice] [pid 10168:tid 668] AH00094: Command line: 'httpd.exe -d C:/apache/Apache24'
[Thu Dec 05 23:29:01.665949 2019] [mpm_winnt:notice] [pid 10168:tid 668] AH00418: Parent: Created child process 7372
[Thu Dec 05 23:29:02.063030 2019] [mpm_winnt:notice] [pid 7372:tid 664] AH00354: Child: Starting 64 worker threads.

記録されるフォーマットの詳細や、エラーログに記録されるエラーレベルの設定などについては、次のページで説明する。