<s>
A	O
Java	B-Language
logging	I-Language
framework	I-Language
is	O
a	O
computer	B-Application
data	I-Application
logging	I-Application
package	O
for	O
the	O
Java	B-Device
platform	I-Device
.	O
</s>
<s>
This	O
article	O
covers	O
general	O
purpose	O
logging	B-Application
frameworks	O
.	O
</s>
<s>
Logging	B-Application
refers	O
to	O
the	O
recording	O
of	O
activity	O
by	O
an	O
application	O
and	O
is	O
a	O
common	O
issue	O
for	O
development	O
teams	O
.	O
</s>
<s>
Logging	B-Application
frameworks	O
ease	O
and	O
standardize	O
the	O
process	O
of	O
logging	B-Application
for	O
the	O
Java	B-Device
platform	I-Device
.	O
</s>
<s>
Unfortunately	O
the	O
JDK	B-Language
did	O
not	O
include	O
logging	B-Application
in	O
its	O
original	O
release	O
so	O
by	O
the	O
time	O
the	O
Java	B-Device
Logging	B-Application
API	B-General_Concept
was	O
added	O
several	O
other	O
logging	B-Application
frameworks	O
had	O
become	O
widely	O
used	O
–	O
in	O
particular	O
(	O
also	O
known	O
as	O
Java	B-Device
Commons	O
Logging	B-Application
or	O
JCL	O
)	O
and	O
Log4j	B-Application
.	O
</s>
<s>
This	O
led	O
to	O
problems	O
when	O
integrating	O
different	O
third-party	O
libraries	O
(	O
JARs	O
)	O
each	O
using	O
different	O
logging	B-Application
frameworks	O
.	O
</s>
<s>
Pluggable	O
logging	B-Application
frameworks	O
(	O
wrappers	O
)	O
were	O
developed	O
to	O
solve	O
this	O
problem	O
.	O
</s>
<s>
Logging	B-Application
is	O
typically	O
broken	O
into	O
three	O
major	O
pieces	O
:	O
the	O
Logger	O
,	O
the	O
Formatter	O
and	O
the	O
Appender	O
(	O
or	O
Handler	O
)	O
.	O
</s>
<s>
The	O
Logger	O
is	O
responsible	O
for	O
capturing	O
the	O
message	O
to	O
be	O
logged	O
along	O
with	O
certain	O
metadata	O
and	O
passing	O
it	O
to	O
the	O
logging	B-Application
framework	O
.	O
</s>
<s>
Simpler	O
logging	B-Application
frameworks	O
,	O
like	O
,	O
combine	O
the	O
logger	O
and	O
the	O
appender	O
.	O
</s>
<s>
The	O
application	O
logs	O
a	O
message	O
by	O
passing	O
an	O
object	O
or	O
an	O
object	O
and	O
an	O
exception	B-General_Concept
with	O
an	O
optional	O
severity	O
level	O
to	O
the	O
logger	O
object	O
under	O
a	O
given	O
name/identifier	O
.	O
</s>
<s>
A	O
common	O
scheme	O
is	O
to	O
use	O
the	O
name	O
of	O
the	O
class	O
or	O
package	O
that	O
is	O
doing	O
the	O
logging	B-Application
.	O
</s>
<s>
Both	O
Log4j	B-Application
and	O
the	O
Java	B-Device
logging	B-Application
API	B-General_Concept
support	O
defining	O
handlers	O
higher	O
up	O
the	O
hierarchy	O
.	O
</s>
<s>
As	O
long	O
as	O
there	O
is	O
a	O
handler	O
defined	O
somewhere	O
in	O
this	O
stack	O
,	O
logging	B-Application
may	O
occur	O
.	O
</s>
<s>
Common	O
level	O
names	O
are	O
copied	O
from	O
(	O
although	O
the	O
Java	B-Device
Logging	B-Application
API	B-General_Concept
defines	O
different	O
level	O
names	O
)	O
:	O
</s>
<s>
Expect	O
these	O
to	O
be	O
immediately	O
visible	O
on	O
a	O
status	O
console.WARNINGUse	O
of	O
deprecated	O
APIs	B-General_Concept
,	O
poor	O
use	O
of	O
API	B-General_Concept
,	O
'	O
almost	O
 '	O
errors	O
,	O
other	O
runtime	O
situations	O
that	O
are	O
undesirable	O
or	O
unexpected	O
,	O
but	O
not	O
necessarily	O
"	O
wrong	O
"	O
.	O
</s>
<s>
The	O
logging	B-Application
framework	O
maintains	O
the	O
current	O
logging	B-Application
level	O
for	O
each	O
logger	O
.	O
</s>
<s>
The	O
logging	B-Application
level	O
can	O
be	O
set	O
more	O
or	O
less	O
restrictive	O
.	O
</s>
<s>
For	O
example	O
,	O
if	O
the	O
logging	B-Application
level	O
is	O
set	O
to	O
"	O
WARNING	O
"	O
,	O
then	O
all	O
messages	O
of	O
that	O
level	O
or	O
higher	O
are	O
logged	O
:	O
ERROR	O
and	O
FATAL	O
.	O
</s>
<s>
The	O
most	O
commonly	O
used	O
filter	O
is	O
the	O
logging	B-Application
level	O
documented	O
in	O
the	O
previous	O
section	O
.	O
</s>
<s>
Logging	B-Application
frameworks	O
such	O
as	O
Log4j	B-Application
2	O
and	O
SLF4J	B-Language
also	O
provide	O
Markers	O
,	O
which	O
when	O
attached	O
to	O
a	O
log	O
event	O
can	O
also	O
be	O
used	O
for	O
filtering	O
.	O
</s>
<s>
Filters	O
can	O
also	O
be	O
used	O
to	O
accept	O
or	O
deny	O
log	O
events	O
based	O
on	O
exceptions	O
being	O
thrown	O
,	O
data	O
within	O
the	O
log	O
message	O
,	O
data	O
in	O
a	O
ThreadLocal	O
that	O
is	O
exposed	O
through	O
the	O
logging	B-Application
API	B-General_Concept
,	O
or	O
a	O
variety	O
of	O
other	O
methods	O
.	O
</s>
<s>
+	O
Table	O
1	O
-	O
Features	O
Framework	O
Type	O
Supported	O
Log	O
Levels	O
Standard	O
Appenders	O
Comments	O
Cost	O
/	O
Licence	O
Log4j	B-Application
Logging	B-Application
Framework	O
FATAL	O
ERROR	O
WARN	O
INFO	O
DEBUG	O
TRACE	O
Too	O
many	O
to	O
list	O
:	O
See	O
Appender	O
Documentation	O
Widely	O
used	O
in	O
many	O
projects	O
and	O
platforms	O
.	O
</s>
<s>
Log4j	B-Application
1	O
was	O
declared	O
"	O
End	O
of	O
Life	O
"	O
in	O
2015	O
and	O
has	O
been	O
replaced	O
with	O
Log4j	B-Application
2	O
which	O
provides	O
an	O
API	B-General_Concept
that	O
can	O
be	O
used	O
with	O
other	O
logging	B-Application
implementations	O
as	O
well	O
as	O
an	O
implementation	O
of	O
that	O
API	B-General_Concept
.	O
</s>
<s>
Apache	O
License	O
,	O
Version	O
2.0	O
Java	B-Device
Logging	B-Application
API	B-General_Concept
Logging	B-Application
Framework	O
SEVERE	O
WARNING	O
INFO	O
CONFIG	O
FINE	O
FINER	O
FINEST	O
Sun	O
's	O
default	O
Java	B-Device
Virtual	O
Machine	O
(	O
JVM	O
)	O
has	O
the	O
following	O
:	O
ConsoleHandler	O
,	O
FileHandler	O
,	O
SocketHandler	O
,	O
MemoryHandler	O
Comes	O
with	O
the	O
JRE	O
tinylog	O
Logging	B-Application
Framework	O
ERROR	O
WARNING	O
INFO	O
DEBUG	O
TRACE	O
ConsoleWriter	O
,	O
FileWriter	O
,	O
LogcatWriter	O
,	O
JdbcWriter	O
,	O
RollingFileWriter	O
,	O
SharedFileWriter	O
and	O
null	O
(	O
discards	O
all	O
log	O
entries	O
)	O
Apache	O
License	O
,	O
Version	O
2.0	O
Logback	O
Logging	B-Application
Framework	O
ERROR	O
WARN	O
INFO	O
DEBUG	O
TRACE	O
Too	O
many	O
to	O
list	O
:	O
see	O
Appender	O
JavaDoc	O
Developed	O
as	O
a	O
replacement	O
for	O
Log4j	B-Application
,	O
with	O
many	O
improvements	O
.	O
</s>
<s>
Used	O
by	O
numerous	O
projects	O
,	O
typically	O
behind	O
slf4j	B-Language
,	O
for	O
example	O
Akka	B-Language
,	O
Apache	B-Language
Camel	I-Language
,	O
Apache	B-Language
Cocoon	I-Language
,	O
Artifactory	O
,	O
Gradle	B-Language
,	O
Lift	B-Language
Framework	I-Language
,	O
Play	B-Language
Framework	I-Language
,	O
Scalatra	B-Language
,	O
SonarQube	B-Application
,	O
Spring	O
Boot	O
,	O
...	O
LGPL	B-Application
,	O
Version	O
2.1	O
Apache	B-Language
Commons	I-Language
Logging	I-Language
(	O
JCL	O
)	O
Logging	B-Application
Wrapper	O
FATAL	O
ERROR	O
WARN	O
INFO	O
DEBUG	O
TRACE	O
Depends	O
on	O
the	O
underlying	O
framework	O
Widely	O
used	O
,	O
often	O
in	O
conjunction	O
with	O
Log4j	B-Application
Apache	O
License	O
,	O
Version	O
2.0	O
SLF4J	B-Language
Logging	B-Application
Wrapper	O
ERROR	O
WARN	O
INFO	O
DEBUG	O
TRACE	O
Depends	O
on	O
the	O
underlying	O
framework	O
,	O
which	O
is	O
pluggable	O
.	O
</s>
<s>
Provides	O
API	B-General_Concept
compatible	O
shims	O
for	O
JCL	O
,	O
JDK	B-Language
and	O
Log4j	B-Application
logging	B-Application
packages	O
.	O
</s>
<s>
JCL	O
and	O
Log4j	B-Application
are	O
very	O
common	O
simply	O
because	O
they	O
have	O
been	O
around	O
for	O
so	O
long	O
and	O
were	O
the	O
only	O
choices	O
for	O
a	O
long	O
time	O
.	O
</s>
<s>
The	O
flexibility	O
of	O
slf4j	B-Language
(	O
using	O
Logback	O
underneath	O
)	O
has	O
made	O
it	O
a	O
popular	O
choice	O
.	O
</s>
<s>
SLF4J	B-Language
is	O
a	O
set	O
of	O
logging	B-Application
wrappers	O
(	O
or	O
shims	O
)	O
that	O
allow	O
it	O
to	O
imitate	O
any	O
of	O
the	O
other	O
frameworks	O
.	O
</s>
<s>
Thus	O
multiple	O
third-party	O
libraries	O
can	O
be	O
incorporated	O
into	O
an	O
application	O
,	O
regardless	O
of	O
the	O
logging	B-Application
framework	O
each	O
has	O
chosen	O
to	O
use	O
.	O
</s>
<s>
However	O
all	O
logging	B-Application
output	O
is	O
generated	O
in	O
a	O
standard	O
way	O
,	O
typically	O
via	O
Logback	O
.	O
</s>
<s>
Log4j	B-Application
2	O
provides	O
both	O
an	O
API	B-General_Concept
and	O
an	O
implementation	O
.	O
</s>
<s>
The	O
API	B-General_Concept
can	O
be	O
routed	O
to	O
other	O
logging	B-Application
implementations	O
equivalent	O
to	O
how	O
SLF4J	B-Language
works	O
.	O
</s>
<s>
Unlike	O
SLF4J	B-Language
,	O
the	O
Log4j	B-Application
2	O
API	B-General_Concept
logs	O
Message	O
objects	O
instead	O
of	O
Strings	O
for	O
extra	O
flexibility	O
and	O
also	O
supports	O
Java	B-Device
Lambda	O
expressions	O
.	O
</s>
<s>
JCL	O
is	O
n't	O
really	O
a	O
logging	B-Application
framework	O
,	O
but	O
a	O
wrapper	O
for	O
one	O
.	O
</s>
<s>
As	O
such	O
,	O
it	O
requires	O
a	O
logging	B-Application
framework	O
underneath	O
it	O
,	O
although	O
it	O
can	O
default	O
to	O
using	O
its	O
own	O
SimpleLog	O
logger	O
.	O
</s>
<s>
JCL	O
,	O
SLF4J	B-Language
and	O
the	O
Log4j	B-Application
2	O
API	B-General_Concept
are	O
useful	O
when	O
developing	O
reusable	O
libraries	O
which	O
need	O
to	O
write	O
to	O
whichever	O
underlying	O
logging	B-Application
system	O
is	O
being	O
used	O
by	O
the	O
application	O
.	O
</s>
<s>
This	O
also	O
provides	O
flexibility	O
in	O
heterogeneous	O
environments	O
where	O
the	O
logging	B-Application
framework	O
is	O
likely	O
to	O
change	O
,	O
although	O
in	O
most	O
cases	O
,	O
once	O
a	O
logging	B-Application
framework	O
has	O
been	O
chosen	O
,	O
there	O
is	O
little	O
need	O
to	O
change	O
it	O
over	O
the	O
life	O
of	O
the	O
project	O
.	O
</s>
<s>
SLF4J	B-Language
and	O
Log4j	B-Application
2	O
benefit	O
from	O
being	O
newer	O
and	O
build	O
on	O
the	O
lessons	O
learned	O
from	O
older	O
frameworks	O
.	O
</s>
<s>
Moreover	O
JCL	O
has	O
known	O
problems	O
with	O
class-loaders	O
when	O
determining	O
what	O
logging	B-Application
library	O
it	O
should	O
wrap	O
which	O
has	O
now	O
replaced	O
JCL	O
.	O
</s>
<s>
The	O
Java	B-Device
Logging	B-Application
API	B-General_Concept
is	O
provided	O
with	O
Java	B-Device
.	O
</s>
<s>
Although	O
the	O
API	B-General_Concept
is	O
technically	O
separate	O
from	O
the	O
default	O
implementation	O
provided	O
with	O
Java	B-Device
,	O
replacing	O
it	O
with	O
an	O
alternate	O
implementation	O
can	O
be	O
challenging	O
so	O
many	O
developers	O
confuse	O
this	O
implementation	O
with	O
the	O
Java	B-Device
Logging	B-Application
API	B-General_Concept
.	O
</s>
