1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Logback FAQ</title>
<link rel="stylesheet" type="text/css" href="css/common.css" />
<link rel="stylesheet" type="text/css" href="css/screen.css" media="screen" />
<link rel="stylesheet" type="text/css" href="css/_print.css" media="print" />
</head>
<body>
<script type="text/javascript">prefix='';</script>
<script src="templates/header.js" type="text/javascript"></script>
<div id="left">
<script src="templates/left.js" type="text/javascript"></script>
</div>
<div id="right">
<script src="templates/right.js" type="text/javascript"></script>
</div>
<div id="content">
<h2>
<a name="top">Frequently Asked Questions</a>
</h2>
<h3>Logback project</h3>
<ol>
<li><a href="#why_lgpl">Why is logback distributed under LGPL
and not the Apache Software License?</a> </li>
<li><a href="#dependecy">What are logback's dependencies, i.e.
JDK version and third-party libraries?</a>
</li>
</ol>
<h3>Logback Classic</h3>
<ol type="1">
<li>
<a href="#logger_serialization">Are logback loggers
serializable?</a>
</li>
<li>
<a href="#auto_config">How does the automatic configuration
work?</a>
</li>
<li>
<a href="#configFileLocation">Where should the configuration
files such as <em>logback.groovy</em>,
<em>logback-test.xml</em> or <em>logback.xml</em> be located
on the classpath?</a> </li>
<li>
<a href="#sharedConfiguration">Is it possible for multiple JEE
applications to share the same configuration file but without
stepping on each other's toes?
</a>
</li>
<li>
<a href="#overrideFromCL">
How can I disable logging from the command line?
</a>
</li>
<li>
<a href="#setup_jetty">How can Jetty be instructed to use
logback-classic as its logging implementation?
</a>
</li>
</ol>
<!-- =============================================================== -->
<!-- =============================================================== -->
<!-- =============================================================== -->
<!-- =============================================================== -->
<div class="section">
<h2>Logback project</h2>
<dl>
<dt>
<a name="why_lgpl" href="#why_lgpl">Why is logback
distributed under LGPL and not the Apache Software License
(ASL)?</a> </dt>
<dd>
<p>The logback project is dual licensed under the LGPL and
the EPL for two main reasons. For one, the different
license emphasizes that the fact that logback is a related
but <em>different</em> project than log4j.
</p>
<p>Both the LGPL and EPL are reasonable and widely-accepted
licenses. In contrast to the ASL, both the LGPL and he EPL
require that derivate work be licensed under the same
license. While there might be debate about the exact
definition of derivative work, we find such reciprocity both
justified and morally appealing -- that is the second
reason for our choice of the LGPL & EPL
dual-license. The subtly more liberal approach embodied in
the ASL is not necessarily wrong. It is the expression of a
different balance.
</p>
</dd>
</dl>
<hr/>
<dl>
<dt><a name="dependecy" href="#dependecy">What are logback's
dependencies, i.e. JDK version and third-party libraries?</a>
</dt>
<dd><p>This question is answered on a <a
href="dependencies.html">separate page</a> dedicated to the
question of dependencies.</p>
</dd>
</dl>
</div>
<div class="section">
<h2>Logback-classic</h2>
<dl>
<!-- ========================================================= -->
<dt>
<a name="auto_config" href="#auto_config">
How does the automatic configuration work?
</a>
</dt>
<dd>
<p>This question is answered in the <a
href="manual/configuration.html#auto_configuration">relevant
section</a> of the logback manual.
</p>
<hr/>
</dd>
<!-- ========================================================= -->
<dt>
<a name="configFileLocation"
href="#configFileLocation">Where should the configuration
files such as <em>logback.groovy</em>,
<em>logback-test.xml</em> or <em>logback.xml</em> be located
on the classpath?</a>
</dt>
<dd>
<p>Configuration files such as <em>logback.groovy</em>,
<em>logback-test.xml</em> or <em>logback.xml</em> can be
located <b>directly</b> under any folder declared in the
class path. For example, if the class path reads
"c:/java/jdk15/lib/rt.jar;c:/mylibs/" then the
<em>logback.xml</em> file should be located directly under
"c:/mylibs/", that is as "c:/mylibs/logback.xml". Placing it
under a sub-folder of c:/mylibs/, say, c:/mylibs/other/,
will not work.</p>
<p>For web-applications, configuration files can be placed
<b>directly</b> under <em>WEB-INF/classes/</em>.</p>
<hr/>
</dd>
<!-- ========================================================= -->
<dt>
<a name="logger_serialization" href="#logger_serialization">
Are logback loggers serializable?</a>
</dt>
<dd>
<p>Yes. A logback logger <em>is</em> an SLF4J logger and SLF4J
loggers are serializable. This means that an object
referencing a logger will be able to log after its
deserialization.
</p>
<p>The deserialized logger instance will be generated by
<code>org.slf4j.LoggerFactory</code>. Thus, it is possible
for a logback logger to be deserialized as a log4j or j.u.l.
logger, depending on the deserialization environment.</p>
<hr/>
</dd>
<!-- ========================================================= -->
<dt>
<a name="sharedConfiguration" href="#sharedConfiguration">
Is it possible for multiple JEE applications to share the
same configuration file but without stepping on each other's
toes?</a>
</dt>
<dd>
<p>Yes, it is. Using <a
href="manual/configuration.html#variableSubstitution">variable
substitution</a>, it is possible to have a single
configuration file to output logs to different destinations
for each JEE application. Here is a sample
configuration file designed for this purpose.</p>
<p class="source"><configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<!-- "application-name" is a variable -->
<File><b>c:/logs/${application-name}.log</b></File>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d %p %t %c - %m%n</Pattern>
</layout>
</appender>
<root level="debug">
<appender-ref ref="FILE"/>
</root>
</configuration> </p>
<p>Assuming each JEE application loads a different copy of
logback classes into memory, if we can somehow inject a
different value for <code><em>application-name</em></code>
each time an application starts, logs will be output to
different files. We just need to initialize logback with the
above configuration file while injecting a different value
for <code><em>application-name</em></code> variable. Here is
sample code that programmatically configures logback. It
should be invoked during the initialization of your JEE
applications.
</p>
<p class="source"> LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator jc = new JoranConfigurator();
jc.setContext(context);
context.reset(); // override default configuration
// inject the name of the current application as "application-name"
// property of the LoggerContext
<b>context.putProperty("application-name", NAME_OF_CURRENT_APPLICATION);</b>
jc.doConfigure("/path/to/the/above/configuration/file.xml"); </p>
<hr/>
</dd>
<!-- ========================================================= -->
<dt>
<a name="overrideFromCL" href="#overrideFromCL">
How can I disable logging from the command line?
</a>
</dt>
<dd>
<p>Logback does not allow logging to be disabled from the command
line. However, if the configuration file allows it, you can
set the level of loggers on the command line via a Java
system property. Here is such a configuration file.</p>
<p class="source"><configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d [%thread] %level %logger - %m%n</Pattern>
</layout>
</appender>
<root level="<b>${root-level:-INFO}</b>">
<appender-ref ref="CONSOLE"/>
</root>
</configuration></p>
<p>Making use of <a
href="manual/configuration.html#variableSubstitution">variable
substitution</a> as well as <a
href="manual/configuration.html#defaultValuesForVariables">default
values for variables</a>, if the <span
class="variable">root-level</span> system property is set to
<code>OFF</code>, then all logging will be turned
off. However, if it is not set, it will assume the default
value of <code>INFO</code>. Note that you can set the <span
class="variable">root-level</span> system property to any
level value of your choice. The value <code>OFF</code> is
just an example.
</p>
<hr/>
</dd>
<!-- ========================================================= -->
<dt>
<a name="setup_jetty" href="#">
How can Jetty be instructed to use logback-classic as its
logging implementation?
</a>
</dt>
<dd>
<p>The Jetty application server uses SLF4J for its internal
logging.
</p>
<p>Logback jar files must be present on Jetty's class
path. These files are
<em>logback-core-1.2.3.jar</em> and
<em>logback-classic-1.2.3.jar</em>. These files
should be placed under the <em>$JETTY_HOME/lib</em>
directory.
</p>
<p>Since Jetty uses an older version of SLF4J internally,
we recommend that the old version be replaced by
<em>slf4j-api-1.7.25.jar</em>. This file can be
downloaded from the <a
href="http://www.slf4j.org/download.html">SLF4J</a> project.
</p>
<p>For automatically configuring logback-classic, you can
place the file <em>logback.xml</em> under the
<em>$JETTY_HOME/resources</em> directory. You can find
sample configuration files in the
<em>logback-examples/src/main/java/chapters/appenders/conf/</em>
folder shipping within the logback distribution.
</p>
<hr/>
</dd>
<!-- end of definitions -->
</dl>
</div>
<script src="templates/footer.js" type="text/javascript"></script>
</div>
</body>
</html>
|