OpenShiftメモ


すでにインストールしている場合は下記の通り停止、削除

```
minishift stop
minishift delete
```

下記のフォルダ配下を削除する。
C:\Users\gtoru\.minishift



OS再起動

https://developers.redhat.com/products/cdk/hello-world/?tcWhenSigned=April%2B26%2C%2B2018&tcWhenEnds=April%2B26%2C%2B2019&tcEndsIn=156&tcDuration=364&tcDownloadFileName=cdk-3.6.0-1-minishift-windows-amd64.exe&tcRedirect=5000&tcSrcLink=https%3A%2F%2Fdevelopers.redhat.com%2Fdownload-manager%2Fcontent%2Forigin%2Ffiles%2Fsha256%2Fba%2Fba8d9314a933425408048c20d3519842575f88083c0a323c643398560895d554%2Fcdk-3.6.0-1-minishift-windows-amd64.exe&p=Red%2BHat%2BContainer%2BDevelopment%2BKit%2B(CDK)&pv=3.6.0&tcDownloadURL=https%3A%2F%2Faccess.cdn.redhat.com%2Fcontent%2Forigin%2Ffiles%2Fsha256%2Fba%2Fba8d9314a933425408048c20d3519842575f88083c0a323c643398560895d554%2Fcdk-3.6.0-1-minishift-windows-amd64.exe%3F_auth_%3D1542777837_903ab16c5f1037845f0f061b7616b25a#fndtn-windows
へアクセスしダウンロードしたファイルを
%USERPROFILE%/bin/minishift.exe
として配置する。

minishift config set vm-driver virtualbox

minishift setup-cdk

〇setEnv.cmdの中身

```
set PATH=%PATH%;C:\Users\gtoru\bin
set MINISHIFT_USERNAME=g.toru.hashimoto@gmail.com
set MINISHIFT_PASSWORD=xxxxxxxx
```


〇start.cmdの中身

```
minishift.exe config set vm-driver virtualbox
minishift.exe start
minishift console
```

〇ocコマンド実行するための準備

```
@FOR /f "tokens=*" %i IN ('minishift oc-env') DO @call %i
```


〇Eclipseのダウンロード
https://www.eclipse.org/downloads/download.php?file=/oomph/epp/2018-09/Ra/eclipse-inst-win64.exe

〇Tomcatのダウンロード
https://tomcat.apache.org/download-90.cgi
9.0.8でないとダメだった。

〇Linux側の設定


```
<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000" address="0.0.0.0"
               redirectPort="8443" />
```

address="0.0.0.0"を追加しないと外からアドレス指定でアクセスできない。

〇td-agentのインストール

```
curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent3.sh | sh
systemctl start td-agent.service
systemctl status td-agent.service
```

/lib/systemd/system/td-agent.service
を下記のように編集する。root権限で実行する。

```
[Service]
User=root
Group=root
```


tdの設定ファイル。シンプルな例

```
<source>
  @type tail
  path /opt/tomcat/apache-tomcat-9.0.13/logs/catalina.out
  pos_file /var/log/td-agent/catalina.pos
  tag catalina.out
  <parse>
     @type none
  </parse>
</source>
<match catalina.out>
  @type file
  path /var/log/td-agent/catalina.log
  time_slice_format %Y%m%d
  time_slice_wait 1m
</match>
```

Tomcatの生ログ

```
java.lang.Exception
        at sample.TestServlet.doGet(TestServlet.java:34)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:791)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:748)
Hello World..
```

td-agentの出力結果

```
2018-12-05T19:49:17+09:00       catalina.out    {"message":"java.lang.Exception"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat sample.TestServlet.doGet(TestServlet.java:34)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:634)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:741)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:791)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"\tat java.lang.Thread.run(Thread.java:748)"}
2018-12-05T19:49:17+09:00       catalina.out    {"message":"Hello World.."}
```


（メモ）
スタックトレースを自前ログライブラリで出力する方法。これの応用で改行を取り除く。

```
StackTraceElement[] ste = ex.getStackTrace();
for(int i = 0; i < ste.length; i++) {
  System.out.print("at " + ste[i].getClassName() + "." + ste[i].getMethodName() + "(" + ste[i].getClassName() + ":" + ste[i].getLineNumber() + ")");
}
//ex.printStackTrace()と同じレベルの情報を出力可能。
```

Tomcatのデフォルト標準出力ではメッセージに日付等のヘッダー情報が付与されないためmultilineの設定でスタックトレースをメッセージブロックとして取り扱えない。
ログ出力フォーマットをそろえるためログライブラリを利用する。通常の案件ではlog4jを利用している。
https://logging.apache.org/log4j/2.0/download.html
ライブラリの配置やソースコードと出力結果は下記の通り。

Linux上も同様

```
10-Dec-2018 20:14:25.816 情報 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.undeploy コンテキストパス [/TestWeb] のWebアプリケーションの配備を解除します
10-Dec-2018 20:14:26.188 情報 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.deployWAR Webアプリケーションアーカイブ [/opt/tomcat/apache-tomcat-9.0.13/webapps/TestWeb.war] を配備します
10-Dec-2018 20:14:26.454 情報 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/opt/tomcat/apache-tomcat-9.0.13/webapps/TestWeb.war] has finished in [265] ms
2018-12-10 20:14:52,901 | [http-nio-0.0.0.0-8080-exec-11] | ERROR | sample.TestServlet | error
java.lang.Exception: null
        at sample.TestServlet.doGet(TestServlet.java:38) [classes/:?]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) [servlet-api.jar:?]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) [servlet-api.jar:?]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [catalina.jar:9.0.13]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:9.0.13]
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) [tomcat-websocket.jar:9.0.13]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [catalina.jar:9.0.13]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:9.0.13]
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) [catalina.jar:9.0.13]
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [catalina.jar:9.0.13]
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) [catalina.jar:9.0.13]
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) [catalina.jar:9.0.13]
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [catalina.jar:9.0.13]
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668) [catalina.jar:9.0.13]
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [catalina.jar:9.0.13]
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [catalina.jar:9.0.13]
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) [tomcat-coyote.jar:9.0.13]
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-coyote.jar:9.0.13]
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:791) [tomcat-coyote.jar:9.0.13]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417) [tomcat-coyote.jar:9.0.13]
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-coyote.jar:9.0.13]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_181]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_181]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:9.0.13]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_181]
2018-12-10 20:14:52,923 | [http-nio-0.0.0.0-8080-exec-11] | INFO  | sample.TestServlet | Hello World..
```

```xml

log4j2.xmlの設定
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="OFF">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <!-- <PatternLayout pattern="%d{DEFAULT} [%t] %-5level %msg%n"/> -->
            <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5level %msg%n"/>
        </Console>
    </Appenders>
    <Loggers>
        <Root level="info">
            <AppenderRef ref="Console"/>
        </Root>
        <Logger name="test" level="error" additivity="false">
            <AppenderRef ref="Console"/>
        </Logger>
        <Logger name="test2" level="info">
            <AppenderRef ref="Console" />
        </Logger>
    </Loggers>
</configuration>
```



マルチラインプラグインの設定例

```
<source>
  @type tail
  path /opt/tomcat/apache-tomcat-9.0.13/logs/catalina.out
  pos_file /var/log/td-agent/catalina.pos
  tag catalina.out
  <parse>
#     @type none
    @type multiline
    format_firstline /\d{4}-\d{1,2}-\d{1,2}/
    format1 /^(?<time>\d{4}-\d{1,2}-\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}) \[(?<thread>.*)\] (?<level>[^\s]+)(?<message>.*)/
  </parse>
</source>

<match catalina.out>
  @type file
  path /var/log/td-agent/catalina.log
  time_slice_format %Y%m%d
  time_slice_wait 1m
</match>
```


実行結果は下記の通りでスタックトレースが一行メッセージとなって出力される。ここではtomcatのデフォルトログのフォーマットとlog4jのフォーマットが合わないので明示的にecho '' > catalina.outで製品ログを一旦クリアしている。

```
[root@localhost catalina.log]# pwd
/var/log/td-agent/catalina.log
[root@localhost catalina.log]# ls -l
合計 12
-rw-r--r--. 1 root root 5728 12月 10 21:43 buffer.b57caa4de5113db59aedda93eaf0c61e4.log
-rw-r--r--. 1 root root   68 12月 10 21:43 buffer.b57caa4de5113db59aedda93eaf0c61e4.log.meta
[root@localhost catalina.log]# tail -f buffer.b57caa4de5113db59aedda93eaf0c61e4.log
2018-12-10T21:42:56+09:00       catalina.out    {"thread":"http-nio-0.0.0.0-8080-exec-1","level":"ERROR","message":" error\njava.lang.Exception: null\n\tat sample.TestServlet.doGet(TestServlet.java:38) [classes/:?]\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:634) [servlet-api.jar:?]\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:741) [servlet-api.jar:?]\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [catalina.jar:9.0.13]\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:9.0.13]\n\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) [tomcat-websocket.jar:9.0.13]\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [catalina.jar:9.0.13]\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:9.0.13]\n\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) [catalina.jar:9.0.13]\n\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [catalina.jar:9.0.13]\n\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) [catalina.jar:9.0.13]\n\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) [catalina.jar:9.0.13]\n\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [catalina.jar:9.0.13]\n\tat org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668) [catalina.jar:9.0.13]\n\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [catalina.jar:9.0.13]\n\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [catalina.jar:9.0.13]\n\tat org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) [tomcat-coyote.jar:9.0.13]\n\tat org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-coyote.jar:9.0.13]\n\tat org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:791) [tomcat-coyote.jar:9.0.13]\n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417) [tomcat-coyote.jar:9.0.13]\n\tat org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-coyote.jar:9.0.13]\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_181]\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_181]\n\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:9.0.13]\n\tat java.lang.Thread.run(Thread.java:748) [?:1.8.0_181]"}
2018-12-10T21:42:56+09:00       catalina.out    {"thread":"http-nio-0.0.0.0-8080-exec-1","level":"INFO","message":"  Hello World.."}
2018-12-10T21:43:02+09:00       catalina.out    {"thread":"http-nio-0.0.0.0-8080-exec-5","level":"ERROR","message":" error\njava.lang.Exception: null\n\tat sample.TestServlet.doGet(TestServlet.java:38) [classes/:?]\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:634) [servlet-api.jar:?]\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:741) [servlet-api.jar:?]\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [catalina.jar:9.0.13]\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:9.0.13]\n\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) [tomcat-websocket.jar:9.0.13]\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [catalina.jar:9.0.13]\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:9.0.13]\n\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) [catalina.jar:9.0.13]\n\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [catalina.jar:9.0.13]\n\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) [catalina.jar:9.0.13]\n\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) [catalina.jar:9.0.13]\n\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [catalina.jar:9.0.13]\n\tat org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668) [catalina.jar:9.0.13]\n\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [catalina.jar:9.0.13]\n\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [catalina.jar:9.0.13]\n\tat org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) [tomcat-coyote.jar:9.0.13]\n\tat org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-coyote.jar:9.0.13]\n\tat org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:791) [tomcat-coyote.jar:9.0.13]\n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417) [tomcat-coyote.jar:9.0.13]\n\tat org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-coyote.jar:9.0.13]\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_181]\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_181]\n\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:9.0.13]\n\tat java.lang.Thread.run(Thread.java:748) [?:1.8.0_181]"}
```


Tomcatのcatalina.out（標準出力用ファイル）には下記のように出力されている。（スタックトレースは複数行またぎ）

```
2018-12-10 21:43:02 [http-nio-0.0.0.0-8080-exec-5] ERROR error
java.lang.Exception: null
        at sample.TestServlet.doGet(TestServlet.java:38) [classes/:?]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) [servlet-api.jar:?]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) [servlet-api.jar:?]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [catalina.jar:9.0.13]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:9.0.13]
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) [tomcat-websocket.jar:9.0.13]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [catalina.jar:9.0.13]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:9.0.13]
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) [catalina.jar:9.0.13]
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [catalina.jar:9.0.13]
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) [catalina.jar:9.0.13]
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) [catalina.jar:9.0.13]
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [catalina.jar:9.0.13]
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668) [catalina.jar:9.0.13]
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [catalina.jar:9.0.13]
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [catalina.jar:9.0.13]
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) [tomcat-coyote.jar:9.0.13]
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-coyote.jar:9.0.13]
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:791) [tomcat-coyote.jar:9.0.13]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417) [tomcat-coyote.jar:9.0.13]
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-coyote.jar:9.0.13]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_181]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_181]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:9.0.13]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_181]
2018-12-10 21:43:02 [http-nio-0.0.0.0-8080-exec-5] INFO  Hello World..
```


Javaのソースコード

```
package sample;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger;

/**
 * Servlet implementation class TestServlet
 */
@WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static Logger LOG = (Logger) LogManager.getLogger();
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TestServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		PrintWriter out = response.getWriter();
		try {
			throw new Exception();
		} catch(Exception ex) {
			/*
			StackTraceElement[] ste = ex.getStackTrace();
			for(int i = 0; i < ste.length; i++) {
				System.out.print("at " + ste[i].getClassName() + "." + ste[i].getMethodName() + "(" + ste[i].getClassName() + ":" + ste[i].getLineNumber() + ")");
			}
			System.out.println("");
			*/
			
			//ex.printStackTrace();
	        LOG.error("error", ex);
		}
		LOG.info("Hello World..");
		out.println("Hello World..");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}

```


Eclipseの起動オプション

```
-Dlog4j.configurationFile=file://C:\apache-tomcat-9.0.13\apache-tomcat-9.0.13\lib\log4j2.xml
```

を足す。