e12c1e94420db9539fc6a608e60059e3f5769103
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / ErrorHandlerSimpleImpl.java
1 /**
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowplugin.openflow.md.core;
10
11 import java.util.Arrays;
12
13 import org.opendaylight.openflowplugin.ConnectionException;
14 import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 /**
19  * dumping all exceptions to log
20  * @author mirehak
21  */
22 public class ErrorHandlerSimpleImpl implements ErrorHandler {
23
24     private static final Logger LOG = LoggerFactory
25             .getLogger(ErrorHandlerSimpleImpl.class);
26
27     @Override
28     public void handleException(Throwable e, SessionContext sessionContext) {
29         String sessionKeyId = null;
30         if (sessionContext != null) {
31             sessionKeyId = Arrays.toString(sessionContext.getSessionKey().getId());
32         }
33         
34         if (e instanceof ConnectionException) {
35             LOG.warn("exception -> {}, session -> {}", e.getMessage(), sessionKeyId, e);
36         } else {
37             LOG.error("exception -> {}, session -> {}", e.getMessage(), sessionKeyId, e);
38         }
39     }
40 }