1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.logging.logback.internal

File LogbackUtils.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

8
7
5
1
83
32
9
1.29
1.4
5
1.8

Classes

Class Line # Actions
LogbackUtils 36 7 0% 9 1
0.9595%
 

Contributing tests

This file is covered by 171 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.logging.logback.internal;
21   
22    import org.slf4j.ILoggerFactory;
23    import org.slf4j.Logger;
24    import org.slf4j.LoggerFactory;
25    import org.xwiki.logging.LogLevel;
26   
27    import ch.qos.logback.classic.Level;
28    import ch.qos.logback.classic.LoggerContext;
29   
30    /**
31    * Provide several Logback related utility methods.
32    *
33    * @version $Id: eb5f5d9c936e05701455bd7de12515ae0944d7a7 $
34    * @since 3.2M3
35    */
 
36    public class LogbackUtils
37    {
38    /**
39    * @return the root {@link LoggerContext}.
40    */
 
41  19621 toggle public LoggerContext getLoggerContext()
42    {
43  19621 ILoggerFactory loggerFactory = getLoggerFactory();
44   
45  19621 return loggerFactory instanceof LoggerContext ? (LoggerContext) loggerFactory : null;
46    }
47   
48    /**
49    * @return the Logback root logger
50    */
 
51  785 toggle public ch.qos.logback.classic.Logger getRootLogger()
52    {
53  785 LoggerContext loggerContext = getLoggerContext();
54   
55  785 return loggerContext != null ? getLoggerContext().getLogger(Logger.ROOT_LOGGER_NAME) : null;
56    }
57   
58    /**
59    * @param level the Logback log level
60    * @return the XWiki log level
61    */
 
62  29790 toggle public LogLevel toLogLevel(Level level)
63    {
64  29790 return level != null ? LogLevel.valueOf(level.toString()) : null;
65    }
66   
67    /**
68    * @param logLevel the XWikilog level
69    * @return the Logback log level
70    */
 
71  2 toggle public Level toLevel(LogLevel logLevel)
72    {
73  2 return logLevel != null ? Level.toLevel(logLevel.toString(), null) : null;
74    }
75   
76    /**
77    * @return the SLF4J Logger Factory used for logging
78    */
 
79  19621 toggle protected ILoggerFactory getLoggerFactory()
80    {
81  19621 return LoggerFactory.getILoggerFactory();
82    }
83    }