반응형
액세스 로그은 오직 1개의 파일에만 저장되는 것은 아니다. 로그 형식을 여러개를 정의하여 별도의 액세스 로그로 여러 파일에 저장할 수도 있다.
기본적으로 "httpd.conf" 파일에 작성되어 있는 로그 포맷에 "User-Agent"만 따로 기록하는 형식을 추가한다.
LogFormat "%{User-Agent}i" agent
그리고, 로그 파일 지정에서 새로운 "CustomLog"를 지정한다.
CustomLog logs/agent.log agent
실제 적용이 된다면 아래와 같을 것이다.
<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
LogFormat "%{User-Agent}i" agent <--------------------------- 여기 추가하였다.
<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
CustomLog logs/agent.log agent <--------------------------- 여기 추가하였다.
</IfModule>
이것으로 "User-Agent"만 다른 액세스 로그 파일 "agent.log"에 기록되게 되었다.
그러면 "httpd.conf" 파일을 편집한 후에 Apache를 재시작한 후 Apache에 적당히 액세스 로그를 확인해 본다.
기존 액세스 로그를 기록했던 "access.log" 파일과는 별도로 새롭게 "agent.log"라는 파일이 새로 생성되고, 파일에 액세스한 브라우저에 대한 정보만 기재되어 있는 것을 확인할 수 있다.
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36
Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18363
위 로그는 "Internet Explorer", "Edge", "Chrome" 3개의 브라우저에서 각각 Apache에서 공개되는 HTML 파일을 열람한 경우이다.
반응형
'Apache' 카테고리의 다른 글
[Apache] 로그 파일 - 로그에 IP 주소를 호스트명으로 변환 (logresolve) (0) | 2019.12.21 |
---|---|
[Apache] 로그 파일 - 에러 로그에 기록되는 레벨 설정 (LogLevel) (0) | 2019.12.21 |
[Apache] 로그 파일 - 특정 로그를 다른 파일에 기록 (0) | 2019.12.21 |
[Apache] 로그 파일 - 액세스 로그 포멧 (LogFormat) (0) | 2019.12.21 |
[Apache] 로그 파일 - 로그 파일의 위치 (CustomLog, ErrorLog) (0) | 2019.12.21 |
[Apache] PHP 사용을 위한 설정 - PHP 동작 여부 확인 (0) | 2019.12.21 |