My overall objective here is simply to be able to use a Java logging library, specifically log4j2 here, so that I can log user accesses to the application to a folder of my choice. And also make use of log rolling facility to copy log files to an archive directory at the end ofe very day.
I have been using log4j2 with ColdFusion 2016. I just placed the two jar files, log4j-api-2.6.2,jar and log4j-core-2.6.2.jar into the folder WEB-INF\lib and my config file, log4j2.xml into WEB-INF\classes. That worked fine because ColdFusion 2016 was using log4j version 1 and there was no conflict of package names. In ColdFusion 2021 it is using log4j version 2 and has the files log4j-api-2.13.3,jar and log4j-core-2.13.3.jar installed in cfusion/lib and now I get an error on the first call to log4j2 when it should be reading the configuration file.
This is simular to what is reported here, https://www.arctype.co/blog/resolve-log4j2-conflicts-in-uberjars, although this is not in a ColdFusion context.
Does anyone else face the issue? Does anyone have an idea how to appracoh this problem? Do I need to consider osgi?
This may be a very dumb question on my part, but since log4j2 is part of CF now, can you just do the logging directly from within CF using CFML? Is there a specific reason why you want to do it in Java? I just think you're going to have a problem using Java libraries from within CF when CF already includes some version of those libraries.
Dave Watts, Eidolon LLC
Hi Dave, thanks for reply. Yes that would be great if I could do it in CFML, but the only way I know how to do it in CFML is to use CFLOG and it is rather limited. Specifically I cannot:
- log to a file in folder of my choice.
- have the log automatically rollover at the end of the day so that it copies the log file to an archived folder and then starts again with a clean empty log file.
Well, maybe you don't need to use CFLOG at all. You could just use CFFILE, CFDIRECTORY and CFLOCK to create the file where you want it, and CFSCHEDULE to do the log rolling. You could create custom "log" functionality and put it in a custom tag or function. There's nothing really that special about what CFLOG does.
Dave Watts, Eidolon LLC
I just placed the two jar files, log4j-api-2.6.2,jar and log4j-core-2.6.2.jar into the folder WEB-INF\lib and my config file, log4j2.xml into WEB-INF\classes. That worked fine because ColdFusion 2016 was using log4j version 1 and there was no conflict of package names.
Even though that setup worked, I still have my reservations. In particular, about the wisdom of locating the XML configuration file in WEB-INF\classes.
In any case, what if we take ColdFusion's promise of backward-compatibility for granted. That suggests the following test.
You had in CF2016:
You have in CF2021:
Then we could play dumb, place your XML in
and see if ColdFusion takes the bait.
[Postscript: an alternative to \cfusion\lib\log4j2.xml is: