1

I read some posts here about similar problems but none was able to help me. I'm using Wildfly 9.0.2 and want to configure it to log like this:

my.project.category = INFO
my.especial.project.category = DEBUG
the rest = WARN

What I'm trying, with no success:

<subsystem xmlns="urn:jboss:domain:logging:3.0">
    <console-handler name="MY_DEBUGGER_HANDLER">
        <level name="DEBUG"/>
        <formatter>
            <named-formatter name="COLOR-PATTERN"/>
        </formatter>
    </console-handler>
    <console-handler name="MY_INFO_HANDLER">
        <level name="INFO"/>
        <formatter>
            <named-formatter name="COLOR-PATTERN"/>
        </formatter>
    </console-handler>
    <console-handler name="CONSOLE">
        <level name="WARN"/>
        <formatter>
            <named-formatter name="COLOR-PATTERN"/>
        </formatter>
    </console-handler>
    <logger category="my.project.category" use-parent-handlers="false">
        <level name="INFO"/>
        <handlers>
            <handler name="MY_INFO_HANDLER"/>
        </handlers>
    </logger>
    <logger category="my.especial.project.category" use-parent-handlers="false">
        <level name="DEBUG"/>
        <handlers>
            <handler name="MY_DEBUGGER_HANDLER"/>
        </handlers>
    </logger>                        
    <root-logger>
        <level name="DEBUG"/>
        <handlers>                    
            <handler name="CONSOLE"/>
        </handlers>
    </root-logger>
    <formatter name="PATTERN">
        <pattern-formatter pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n"/>
    </formatter>
    <formatter name="COLOR-PATTERN">
        <pattern-formatter pattern="%K{level}%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n"/>
    </formatter>
</subsystem>

The problem is that Wildfly refuses to log my categories, unless I change the CONSOLE handler level or add my handles to root-logger, which starts to logs all categories with that level.

Can you please, cast a light here and help me out?
Thank you!

Yoshimit
  • 31
  • 1
  • 4

1 Answers1

1

The handler itself should be set to the lowest level you want logged. For example on the default CONSOLE handler if you want to see DEBUG messages you'd need to set the handler level to at least DEBUG.

In your above configuration you've got the root-logger to DEBUG which means any undefined category will log debug messages. Usually you wouldn't want the root logger level set this low as it will have a performance impact.

Given you're requirements and assuming the default configuration, not your configuration above, the following CLI commands should get you the configuration you're looking for. Note it's not necessary, and not really suggested, to create multiple console handlers. It's best to allow the logger to control the level.

my.project.category = INFO my.especial.project.category = DEBUG the rest = WARN

/subsystem=logging/console-handler=CONSOLE:write-attribute(name=level, value=DEBUG)
/subsystem=logging/logger=my.project.category:add(level=INFO)
/subsystem=logging/logger=my.especial.project.category:add(level=DEBUG)
/subsystem=logging/root-logger=ROOT:write-attribute(name=level, value=WARN)

What the above would do is allow the console handler to log any messages DEBUG or higher. Your my.project.category will log at INFO and your my.especial.project.category will log at DEBUG. All other undefined loggers will only log WARN or higher.

James R. Perkins
  • 16,800
  • 44
  • 60
  • Hi James. Thank you very much for your help, but I still can't see INFO messages from my categories. I understand that I misunderstood the config before, but maybe after trying so many things, I broke something here. The commands above are all accepted, but the INFO messages are not displayed on Eclipse console. I don't know what I'm missing. My actual standalone-full.xml snipped is this now: https://paste.ee/p/fKTuv – Yoshimit Jan 24 '18 at 15:01
  • After some tests, it's clear that after setting root-logger level to WARN, the INFO messages from my.project.category didn't come out anymore. I'm using deafult configureation file now. – Yoshimit Jan 24 '18 at 15:41
  • That XML configuration looks correct to me. You should see `INFO` messages from anything logged with a parent category of `my.project.category`. These should be showing up on the console and the `server.log` file. How do you create your loggers? With something like `Logger.getLogger("my.project.category")`? – James R. Perkins Jan 24 '18 at 16:38
  • Hi James, I use this: @Logger private Log log; and then: log.info("message") inside method. Logger is a Jboss Seam annotation. – Yoshimit Jan 24 '18 at 20:28
  • I think that uses the full class name as the category. This means that your package should start with `my.project.category` in order to work. – James R. Perkins Jan 25 '18 at 03:38
  • Unfortunately, didn't worked. I tried that before. All my logs are cap by root-logger level, using package as or FQCN as category. – Yoshimit Jan 25 '18 at 21:51
  • Do you have an example log message you expect but don't seem? As long as the name of the logger is the first part of your package it should work. – James R. Perkins Jan 26 '18 at 23:01
  • Hi James, here are my snippets: https://paste.ee/p/KqN7z. I had to mock the real names (the code is not personal). As I said, all my logs are capped by root-logger level. With my snippet code, I only see WARNING, no matter from what class. Thank you. – Yoshimit Jan 31 '18 at 16:40
  • Hi there, @james! Any new hint? Thank you. – Yoshimit Feb 07 '18 at 17:02
  • The configuration looks fine so it's tough to tell without knowing more about the code to know what is happening. – James R. Perkins Feb 08 '18 at 14:38