How to use slf4j logger instead of builtin Liferay DXP 7.2 logger in mvc-portlet? - liferay

I can't figure out how to turn off the default logger and use slf4j instead of the default in Liferay DXP 7.2 mvc-portlet. A working example would be great.
I have already tried:
Implementing Logging
How to disable XML Log Files in Liferay 7.x
Using SLF4J and Liferay Logging Framework in custom plugins
Liferay Logging is Dead! Long Live Liferay Logging!
Github: dnebing/slf4j-liferay

There are few example available on Liferay documentation, blogs and github. See below links.
https://help.liferay.com/hc/en-us/articles/360017883592-Implementing-Logging-
https://liferay.dev/blogs/-/blogs/liferay-logging-is-dead-long-live-liferay-logging-
https://github.com/dnebing/slf4j-liferay

Related

Using Lombok #Sl4j annoation with log4j implementation

I'd like to use the Lombok annotation #Sl4j in my project, but the default log that slf4j uses is Logback.
I'd like to set it to use log4j implementation.
Is there any way to achieve it?
I saw tutorials online that explain how to achieve it but not while using Lombok annotation.
Thank you!
Lombok and Slf4j are separated apis. Your code should use #Slf4j annotation to do logging.
Where it will log is not concern of Lombok but Slf4j configuration. Slf4j manual describes your desired case. Essentialy your app should use slf4j-log4j12-xxx.jar as backend logger.
So you should setup your app for Log4j logging, log using slf4j annotations and add: slf4j-api.jar, slf4j-log412.jar and log4j.jar in app.
I am assuming that you are using older log4j v1.

Why log4J not working after adding apache CXF?

I have developed small web application using JSF, and i add log4j to handle logging. Everything works perfectly until i implement add web service in my web application. After implement webservice using apache CXF I'm not getting any logs in my log file, but can get logs in eclipse console. I don't know why, it behave like that? My log file simply show messages like
i'm using jdk1.5, log4j 1.2.15 and CXF 2.6.11. Also i was tried some solutions from apache to use log4j instead of cxf default logger. please refer http://cxf.apache.org/docs/debugging-and-logging.html#DebuggingandLogging-LoggingMessages
But recommended solutions are not worked for me. How can i solve this issue?
It is possible that CXF introduces another log mechanism which means adds a yet another logging mechanism, or the imported versions of slf4j/log4j are not compatible.
I would recommend you to check the CXF pom file, and exclude all the log4j/slf4j jar files.
As #Arash said, remove log4j from classpath (if present). Also add the file META-INF/cxf/org.apache.cxf.Logger to the classpath with the following content:
org.apache.cxf.common.logging.Slf4jLogger
Reference: Using SLF4J Instead of java.util.logging
Problem was solved by removing slf4j-jdk14.jar from CXF. Actually Problem is "Class path contains multiple SLF4J bindings". So i removed CXF log4j binding. Now it's working perfectly. Thanks for all.

Using log4j 1.2's HTMLLayout class over log4j 2

I am using log4j 2.0 for logging my application. But the new log4j 2.0 api don't let us edit the HTMLLayout.it is defined as final class.Another thing, it has the log4j 1.2 api in it.So can ı achieve the extending HTMLLayout using log4j 1.2 api on log4j 2.0 ?If I can, I will customize the html log file as I want.
The question points out that the log4j 2 HtmlLayout class is final, so how can the layout be customized?
The answer is that it cannot without changes to the log4j API. Such changes need to be requested in a Log4j forum.
You'll need to file a feature request in the log4j issue tracker. Requests with patches have the best chance of being addressed quickly.

How to configure Myfaces to log through logback

How do I configure Myfaces to write to the logs through logback implementation which rest of my application uses ? Currently I'm writing logs from all parts of my application except the messages by Myfaces in log files.
I can find the messages from Myfaces even in the netbeans console.
Using Myfaces 2.1.8 with Glassfish 3.1 (Netbeans)
Myfaces may be logging to JUL. So you may be required to use jul-to-slf4j to redirect all logging to SLF4J.
Checkout this for how to fix.

Where can I find the source code for log4j's ZeroConfSocketHubAppender?

I'm looking for a way to make log4net support zeroconf to publish logs to Apache Chainsaw (see here: Does log4net support zeroconf?). Apparently log4j can already do this using a ZeroConfSocketHubAppender.
Where might I be able to view the source for the java ZeroConfSocketHubAppender? I've looked both in the Apache Chainsaw and in the Log4j repositories but was unsuccessful.
ZeroConf is a log4j 'companion', but ZeroConfSocketHubAppender (and this companion) is no longer necessary due to the fact that most network-based appenders in log4j have ZeroConf support built-in as of log4j 1.2.16.
All you need to do to enable ZeroConf is add jmdns.jar to your classpath and set the 'advertiseViaMulticastDNS' param to 'true' in the appender configuration.
Here's the commit & log info describing the changes which improved ZeroConf support in the appenders (and receivers):
http://svn.apache.org/viewvc?view=revision&revision=924176
Here is a link to the ZeroConf page if you still want to use that
http://logging.apache.org/log4j/companions/zeroconf/source-repository.html
By the way, the svn HEAD revision of Chainsaw (which should be released soon) includes support for using the advertised ZeroConf appender information to automatically create receivers.

Resources