View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.hc.core5.testing.nio;
29  
30  import org.apache.hc.core5.http.ConnectionClosedException;
31  import org.apache.hc.core5.reactor.IOSession;
32  import org.apache.hc.core5.reactor.IOSessionListener;
33  import org.slf4j.Logger;
34  import org.slf4j.LoggerFactory;
35  
36  public class LoggingIOSessionListener implements IOSessionListener {
37  
38      public final static LoggingIOSessionListeneressionListener.html#LoggingIOSessionListener">LoggingIOSessionListener INSTANCE = new LoggingIOSessionListener();
39  
40      private final Logger connLog = LoggerFactory.getLogger("org.apache.hc.core5.http.connection");
41  
42      private LoggingIOSessionListener() {
43      }
44  
45      @Override
46      public void connected(final IOSession session) {
47          if (connLog.isDebugEnabled()) {
48              connLog.debug("{} connected", session);
49          }
50      }
51  
52      @Override
53      public void startTls(final IOSession session) {
54          if (connLog.isDebugEnabled()) {
55              connLog.debug("{} TLS started", session);
56          }
57      }
58  
59      @Override
60      public void inputReady(final IOSession session) {
61          if (connLog.isDebugEnabled()) {
62              connLog.debug("{} input ready", session);
63          }
64      }
65  
66      @Override
67      public void outputReady(final IOSession session) {
68          if (connLog.isDebugEnabled()) {
69              connLog.debug("{} output ready", session);
70          }
71      }
72  
73      @Override
74      public void timeout(final IOSession session) {
75          if (connLog.isDebugEnabled()) {
76              connLog.debug("{} timeout", session);
77          }
78      }
79  
80      @Override
81      public void exception(final IOSession session, final Exception ex) {
82          if (ex instanceof ConnectionClosedException) {
83              return;
84          }
85          connLog.error("{} {}", session, ex.getMessage(), ex);
86      }
87  
88      @Override
89      public void disconnected(final IOSession session) {
90          if (connLog.isDebugEnabled()) {
91              connLog.debug("{} disconnected", session);
92          }
93      }
94  
95  }