ColdFusion 2021 and log4j2

New Here ,
May 27, 2021 May 27, 2021

Copy link to clipboard

Copied

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.

It reports:

  • ERROR StatusLogger Unrecognized format specifier
  • ERROR StatusLogger Unrecognized conversion

 

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?

 

Thanks,

 

William

 

Views

83

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 27, 2021 May 27, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 27, 2021 May 27, 2021

Copy link to clipboard

Copied

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.

 

William

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 27, 2021 May 27, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 30, 2021 May 30, 2021

Copy link to clipboard

Copied

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. 

 

By @wfisk

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:

 

\WEB-INF\lib\log4j-api-2.6.2,jar 

\WEB-INF\lib\log4j-core-2.6.2.jar

\WEB-INF\classes\log4j2.xml

 

You have in CF2021:

 

\cfusion\lib\log4j-api-2.13.3,jar 

\cfusion\lib\log4j-core-2.13.3.jar

 

Then we could play dumb, place your XML in 

 

\cfusion\lib\log4j2.xml

 

and see if ColdFusion takes the bait.

 

[Postscript: an alternative to \cfusion\lib\log4j2.xml is:

  1. \WEB-INF\classes\log4j2.xml
  2. then add {application.home}/wwwroot/WEB-INF/classes/ to the -Dcoldfusion.classPath property in jvm.config
  3. The tests require a ColdFusion restart. ]

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 06, 2021 Jun 06, 2021

Copy link to clipboard

Copied

LATEST

Hi @wfisk , problem solved?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines