I would like to use logback or at least log4j 2.
Yes, technically it is possible. Alfresco already includes SLF4J and a bridge for Commons Logging to redirect via SLF4J to Log4j. If you wanted to use logback, you'd only need to replace the Log4j library shipped with Alfresco with a log4j-slf4j bridge, and of course add the logback configuration. Similar with Log4j2.
In order to avoid any startup error, you should override / remove the Log4J hierarchy initialisation. By doing that, you are losing the ability to have extensions (in Repository) provide their own logging configuration as their log4j.properties will not be read anymore. Additionally, tools like the "Log4j Settings" in Alfresco Support Tools / OOTBee Support Tools addons will stop to work.
I use logback in most of my Alfresco unit tests, and prefer it over the old Log4j shipped with Alfresco. I haven't looked at Log4j2 too much to know if I should / might want to prefer that instead.
TL;DR - Switching logging library in Alfresco is possible, but comes with some caveats. it is definitely not something that Alfresco (the company) supports.
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.