web-dev-qa-db-ja.com

Spring BootはHTTP要求のログを有効にします

スプリングブートによって提供される組み込みTomcatサーバーでHTTPサーバーログを有効にする方法私はapplication.propertiesでこれを試しましたが、ファイルを作成せず、コンソールにログも記録しません

#application.properties
server.Tomcat.access-log-enabled=true
server.Tomcat.access-log-pattern=%a asdasd
logging.file=/home/mati/mylog.log
spring boot 1.0.1.RELEASE
34
Mati

試して

server.Tomcat.accessLogEnabled=true
server.Tomcat.accessLogPattern=%a asdasd

そして、/tmp/Tomcat.<random>.<port>/logsで出力ファイルを探します。 server.Tomcat.basedirプロパティを設定して、ディレクトリを変更します。

30
Dave Syer

ここでは、コンソールまたは選択したファイルにそれらを表示する方法を説明します。 Tomcatの RequestDumperFilter@Configurationクラスで宣言します:

@Bean
public FilterRegistrationBean requestDumperFilter() {
    FilterRegistrationBean registration = new FilterRegistrationBean();
    Filter requestDumperFilter = new RequestDumperFilter();
    registration.setFilter(requestDumperFilter);
    registration.addUrlPatterns("/*");
    return registration;
}

それが出力です:

http-nio-8765-exec-1 START TIME        =30-may-2016 12:45:41
http-nio-8765-exec-1         requestURI=/info
http-nio-8765-exec-1           authType=null
http-nio-8765-exec-1  characterEncoding=UTF-8
http-nio-8765-exec-1      contentLength=-1
http-nio-8765-exec-1        contentType=null
http-nio-8765-exec-1        contextPath=
http-nio-8765-exec-1             cookie=JSESSIONID=E7259F5F9ED6B04CBE5A294C5F8CA5C6
http-nio-8765-exec-1             header=Host=mies-057:8765
http-nio-8765-exec-1             header=connection=keep-alive
http-nio-8765-exec-1             header=accept=text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
http-nio-8765-exec-1             header=upgrade-insecure-requests=1
http-nio-8765-exec-1             header=user-agent=Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
http-nio-8765-exec-1             header=referer=http://mies-057:1111/
http-nio-8765-exec-1             header=accept-encoding=gzip, deflate, sdch
http-nio-8765-exec-1             header=accept-language=es-ES,es;q=0.8
http-nio-8765-exec-1             header=cookie=JSESSIONID=E7259F5F9ED6B04CBE5A294C5F8CA5C6
http-nio-8765-exec-1             locale=es_ES
http-nio-8765-exec-1             method=GET
http-nio-8765-exec-1           pathInfo=null
http-nio-8765-exec-1           protocol=HTTP/1.1
http-nio-8765-exec-1        queryString=null
http-nio-8765-exec-1         remoteAddr=192.168.56.1
http-nio-8765-exec-1         remoteHost=192.168.56.1
http-nio-8765-exec-1         remoteUser=null
http-nio-8765-exec-1 requestedSessionId=E7259F5F9ED6B04CBE5A294C5F8CA5C6
http-nio-8765-exec-1             scheme=http
http-nio-8765-exec-1         serverName=mies-057
http-nio-8765-exec-1         serverPort=8765
http-nio-8765-exec-1        servletPath=/info
http-nio-8765-exec-1           isSecure=false
http-nio-8765-exec-1 ------------------=--------------------------------------------
http-nio-8765-exec-1 ------------------=--------------------------------------------
http-nio-8765-exec-1           authType=null
http-nio-8765-exec-1        contentType=application/json;charset=UTF-8
http-nio-8765-exec-1             header=Strict-Transport-Security=max-age=31536000 ; includeSubDomains
http-nio-8765-exec-1             header=X-Application-Context=Edge:8765
http-nio-8765-exec-1             header=Content-Type=application/json;charset=UTF-8
http-nio-8765-exec-1             header=Transfer-Encoding=chunked
http-nio-8765-exec-1             header=Date=Mon, 30 May 2016 10:45:41 GMT
http-nio-8765-exec-1             status=200
http-nio-8765-exec-1 END TIME          =30-may-2016 12:45:41
http-nio-8765-exec-1 ===============================================================

次に、標準のSpring Bootログとして管理します。

37
Xtreme Biker

Spring Boot 1.5.1では、 Dave Syerが言及したプロパティ は機能しなくなり、代わりに次のように名前が変更されました。

server.Tomcat.basedir=target/Tomcat-logs
server.Tomcat.accesslog.enabled=true
server.Tomcat.accesslog.pattern=%t %a "%r" %s (%D ms)

上記の構成を使用して、ルートディレクトリ経由でプロジェクトを実行すると、ログはtarget/Tomcat-logs/log/access_log。*で利用可能になります。

17
gerrytan