Coverage Report - net.admin4j.exception.LogbackExceptionAppenderV1_6
 
Classes in this File Line Coverage Branch Coverage Complexity
LogbackExceptionAppenderV1_6
15%
2/13
0%
0/6
3
 
 1  
 /*
 2  
  * This software is licensed under the Apache License, Version 2.0
 3  
  * (the "License") agreement; you may not use this file except in compliance with
 4  
  * the License.  You may obtain a copy of the License at
 5  
  *
 6  
  *      http://www.apache.org/licenses/LICENSE-2.0
 7  
  *
 8  
  * Unless required by applicable law or agreed to in writing, software
 9  
  * distributed under the License is distributed on an "AS IS" BASIS,
 10  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 11  
  * See the License for the specific language governing permissions and
 12  
  * limitations under the License.
 13  
  */
 14  
 package net.admin4j.exception;
 15  
 
 16  
 import org.slf4j.Logger;
 17  
 import org.slf4j.LoggerFactory;
 18  
 
 19  
 import ch.qos.logback.classic.spi.ILoggingEvent;
 20  
 import ch.qos.logback.core.AppenderBase;
 21  
 
 22  9
 public class LogbackExceptionAppenderV1_6 extends AppenderBase<ILoggingEvent> {
 23  
 
 24  9
         private static Logger logger = LoggerFactory.getLogger(ExceptionTracker.class);
 25  
 
 26  
         @Override
 27  
         protected void append(ILoggingEvent event) {
 28  
 
 29  
                 /*
 30  
                  * It's important that this logger not even throw a RuntimeException.
 31  
                  * Throwing any exception will mask the underlying error and do users a
 32  
                  * great disservice by masking the root issue. D. Ashmore -- Nov, 2015.
 33  
                  */
 34  
                 try {
 35  0
                         for (Object logArgument : event.getArgumentArray()) {
 36  0
                                 if (logArgument instanceof Throwable) {
 37  0
                                         ExceptionTracker.track((Throwable) logArgument);
 38  
                                 }
 39  
                         }
 40  0
                 } catch (Throwable t) {
 41  0
                         processError(t);
 42  0
                 }
 43  
 
 44  0
         }
 45  
 
 46  
         protected void processError(Throwable t) {
 47  0
                 if (logger != null) {
 48  0
                         logger.error("Error tracking logged exception", t);
 49  
                 }
 50  
                 else {
 51  0
                         t.printStackTrace();
 52  
                 }
 53  0
         }
 54  
 
 55  
 }