logging from a custom module

334 views
Skip to first unread message

Guy Katz

unread,
Mar 30, 2022, 5:31:16 AM3/30/22
to WildFly
Hi all;
I have implented a MicroProfile custom config source. it works great...
however, I canot seem to be able to log from the module code to any destination.
I have the following configuration:
module.xml
<module xmlns="urn:jboss:module:1.9" name="com.allot.mp">
    <resources>
        <resource-root path="."/>
    </resources>
    <dependencies>
        <module name="org.eclipse.microprofile.config.api"/>
        <module name="javax.api"/>
        <module name="javax.xml.stream.api"/>
        <module name="org.slf4j"/>
    </dependencies>
</module>

the dependencies work (without the slf4j dependency wildfly fails to start.
my custom donfig source code inside the module:
import org.eclipse.microprofile.config.spi.ConfigSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class JConfigStaxConfigSource implements ConfigSource{
    ...
    public JConfigStaxConfigSource(){
        Logger logger = LoggerFactory.getLogger(JConfigStaxConfigSource.class);
        logger.info(" Hello World");// does not print anything

        
PrintWriter  console = System.console().writer();
        console.println("Creating XMLStaxConfigSource");//prints to console
        console.println(logger);// actually prints the logger instance so its there

.....
}
in the <subsystem xmlns="urn:jboss:domain:logging:8.0"> I have tried to add roper config but I cant seem to be able to log from my module.
here it is:
<subsystem xmlns="urn:jboss:domain:logging:8.0">
            <console-handler name="CONSOLE">
                <level name="INFO"/>
                <encoding value="UTF-8"/>
                <formatter>
                    <named-formatter name="CONSOLE_PATTERN"/>
                </formatter>
            </console-handler>

            <logger category="com.allot.nms.common.enterprise">
                <level name="TRACE"/>
                <handlers>
                    <handler name="CONSOLE"/>
                </handlers>
            </logger>
            <root-logger>
                <level name="WARN"/>
                <handlers>
                    <handler name="CONSOLE"/>
                </handlers>
            </root-logger>

            <formatter name="CONSOLE_PATTERN">
                <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c{1}] %m%n"/>
            </formatter>

        </subsystem>

I assume this is not a microprofile subsystem thing but more of a 'how to log from a wildfly module' which apperantly I cant find the way to achieve.
your help is appreciated.
thanks!

James Perkins

unread,
Mar 30, 2022, 5:17:15 PM3/30/22
to WildFly
What version of WildFly are you using? Also out of curiosity what does the "console.println(logger)" print?

Guy Katz

unread,
Mar 31, 2022, 2:24:58 AM3/31/22
to WildFly
thanks a lot for the reply
we are using wildfly 23.0.0 final
the output of:
Logger logger = LoggerFactory.getLogger(JConfigStaxConfigSource.class);
PrintWriter console = System.console().writer();
console.println(logger);
is: 
"org.slf4j.impl.Slf4jLogger(com.allot.nms.common.enterprise.JConfigStaxConfigSource)"

thanks in advance!

Guy Katz

unread,
Mar 31, 2022, 2:34:52 AM3/31/22
to WildFly
I can also add the printing out (using print writer) what the logger is enabled for yields:
debug=false
error=true
info=true
trace=false
warn=true

so an info log should be ok (which is what I do)...
thanks!

James Perkins

unread,
Mar 31, 2022, 2:25:34 PM3/31/22
to WildFly
I can't seem to reproduce this. All my log messages show up. Are you editing the standalone.xml or do you use CLI or the web console? I'd suggest one of the latter two options as editing the XML requires the server to be shutdown.

Guy Katz

unread,
Apr 1, 2022, 5:00:20 AM4/1/22
to WildFly
I added it via cli.
I will DL a clear jboss 23.0 final and see if it works or not.
maybe something we do affects this ability and in a clean install it will work
I will update
thanks!

Guy Katz

unread,
Apr 3, 2022, 3:29:31 AM4/3/22
to WildFly
indeed on a clean server is logs fine. I will have to dig in a bit further to undertand whats going on./
thanks for the help!

On Thursday, March 31, 2022 at 9:25:34 PM UTC+3 jper...@redhat.com wrote:
Reply all
Reply to author
Forward
0 new messages