[[Logging_How_To]]
= How To

ifdef::env-github[]
:tip-caption: :bulb:
:note-caption: :information_source:
:important-caption: :heavy_exclamation_mark:
:caution-caption: :fire:
:warning-caption: :warning:
endif::[]

[[how-do-i-add-a-log-category]]
== How do I add a log category?

[source,options="nowrap"]
----
/subsystem=logging/logger=com.your.category:add
----

[[how-do-i-change-a-log-level]]
== How do I change a log level?

To change a handlers log level:

[source,options="nowrap"]
----
/subsystem=logging/console-handler=CONSOLE:write-attribute(name=level,value=DEBUG)
----

Changing the level on a log category is the same:

[source,options="nowrap"]
----
/subsystem=logging/logger=com.your.category:write-attribute(name=level,value=ALL)
----

[[how-do-i-log-my-applications-messages-to-their-own-file]]
== How do I log my applications messages to their own file?

1.  Create a file handler. There are 3 different types of file handlers
to choose from; `file-handler`, `periodic-rotating-file-handler` and
`size-rotating-file-handler`. In this example we'll just use a simple
`file-handler`.
+
[source,options="nowrap"]
----
/subsystem=logging/file-handler=fh:add(level=INFO, file={"relative-to"=>"jboss.server.log.dir", "path"=>"fh.log"}, append=false, autoflush=true)
----
2.  Now create the log category.
+
[source,options="nowrap"]
----
/subsystem=logging/logger=org.your.company:add(use-parent-handlers=false,handlers=["fh"])
----

[[how-do-i-log4j2]]
== How do I use my own log4j2 implementation?

If you want to use your own log4j2 implementation, such as log4j-core, then you need to do the following two steps.

1. Disable the adding of the logging dependencies to all your deployments with the
<<add-logging-api-dependencies, add-logging-api-dependencies>> attribute *OR* exclude the `org.apache.logging.log4j.api`
in a link:Developer_Guide.html#jboss-deployment-structure-file[jboss-deployment-structure.xml].
2. Then you would need to include the log4j-api and a log4j2 implementation library in your deployment.

IMPORTANT: This only works for logging in your deployment. Server logs will continue to use the logging subsystem
           configuration.
