Logging in Java Action integrated components

2
I have integrated Mendix application with some non Mendix components via Java Actions. SL4J facade with Log4j implementation with some configured file appenders is used in my components. There some problems when I run application: I can see created log files (so I guess Log4j logging configuration is loaded), but I cannot find any log records in it. Do I need make some additional configuration or such logging is impossible at all? If it is impossible, may be some Mendix infrastructure can be used for such logging?
asked
4 answers
3

The recommended option is to use the builtin logging system:

Core.getLogger("MyLogger").info("This is a test message");

You can find more info in the documentation.

answered
3

I have found cause of the problem:
I use sl4j facade in my libraries, MxLoggerAdapter is used as implementation when code is executed in Mendix environment. It explains why my appenders does not work (in junit tests Log4jLoggerAdapter is used with log4j.xml loaded).
When I use log4j loggers directly - everything works fine, unfortunately I cannot be tied to log4j implementation in my code.

My questions now are:
1. Is it possible to avoid MxLoggerAdapter to be used as implementation for classes in user library? Then I would be able to control my logging like in junit/tomcat environment. I guess it is non trivial and answer is - No. :)
2. How could I change Mendix logging then. I need another layout pattern to be used and rout logs to file.

Many thanks for any help

answered
1

You can find a howto about redirecting your logging to Mendix's logging system, which utilizes SLF4J, here: http://www.slf4j.org/legacy.html

If you are using a lib that logs to Apache Commons Logging, Log4j or default Java Logging, you can't see the logging of this lib in the Mendix log. Using the how-to in the link you can.

First you should download the newest SLF4J.

In the case of Log4j, you simply replace your log4j.jar by the log4j-over-slf4j.jar of the corresponding slf4j version. Replace the slf4j.jar in the runtime/lib dir by the one you downloaded. You might want to update your slf4j in the server/lib dir to the newest version also. These dirs refer to dirs in your local modeler directory. This could also be changed like this on an on premise runtime or similar setup.

In the case of Apache Commons Logging, you simply replace the commons-logging.jar by the jcl-over-slf4j.jar of the corresponding slf4j version in the runtime/lib dir. Then follow similar steps as above.

answered
0

There is no console enabled so it will not write any log to it either. See my question/answer by using log4j in external components to log to file instead of console.

Link

answered