Setting "cas.log.level" in property files

236 views
Skip to first unread message

Mark van Rossum

unread,
Apr 16, 2021, 5:21:53 AM4/16/21
to CAS Community
Hi,
I'm using the default cas-overlay template which includes a log4j2.xml config file.  This has a value: " <Property name="cas.log.level">info</Property>" which can be altered to set the main logging level.  

I have all other settings in cas.properties, and then multiple environments (dev,preprod,prod) etc using their own property files which overlay the cas.properties with environment specific values

I'd like to keep the log4j XML file common across all my environments, but set the log level differently per environment, using the property files.

I tried setting "cas.log.level" in the property file but this just errored:
"Failed to bind properties under 'cas' to org.apereo.cas.configuration.CasConfigurationProperties
        cas.log.level = TRACE"

Weirdly it seems you can set this property on the command line with "-Dcas.log.level"  though, but I'd prefer to keep all environment specific settings in it's property file as it makes configuration much simpler.

It seems like a common thing to do, is there anyway to set this value using the property files?  The documentation [1] notes you can set "
logging.level=" in the property files, but you would then need to duplicate all the loggers from the log4j XML file which.

Thanks!
Mark

Mark H. Wood

unread,
Apr 16, 2021, 9:24:46 AM4/16/21
to cas-...@apereo.org
On Fri, Apr 16, 2021 at 02:21:53AM -0700, Mark van Rossum wrote:
> Hi,
> I'm using the default cas-overlay template which includes a log4j2.xml
> config file. This has a value: "
> <Property name="cas.log.level">info</Property>" which can be altered to set
> the main logging level.
>
> I have all other settings in cas.properties, and then multiple environments
> (dev,preprod,prod) etc using their own property files which overlay the
> cas.properties with environment specific values
>
> I'd like to keep the log4j XML file common across all my environments, but
> set the log level differently per environment, using the property files.
>
> I tried setting "cas.log.level" in the property file but this just errored:
> "Failed to bind properties under 'cas' to
> org.apereo.cas.configuration.CasConfigurationProperties
> cas.log.level = TRACE"

Apparently 'CasConfigurationProperties' is not an extension of
Properties, but rather something which knows only a specific set of
properties.

> Weirdly it seems you can set this property on the command line with
> "-Dcas.log.level" though, but I'd prefer to keep all environment specific
> settings in it's property file as it makes configuration much simpler.

That makes me wonder if CAS is copying the values of System.properties
to Log4J somehow. It does seem to be handling Log4J setup itself
rather than letting Log4J use its own configuration discovery
mechanisms.

> It seems like a common thing to do, is there anyway to set this value using
> the property files? The documentation [1] notes you can set "logging.level="
> in the property files, but you would then need to duplicate all the loggers
> from the log4j XML file which.

The behavior you've reported suggests that there is no way to do that.

You could try XInclude:

https://logging.apache.org/log4j/2.x/manual/configuration.html#XInclude

You'd need an additional per-instance XML document, to use XInclude.
That would at least keep it alongside the other configuration data.

OTOH you might consider logging configuration to be an attribute of
the deployment rather than of the instance, and set that value using
JNDI. Environment objects are easily set up in Tomcat; I don't know
other containers well enough to comment on them.

I would recommend a thorough reading of that whole page.

--
Mark H. Wood
Lead Technology Analyst

University Library
Indiana University - Purdue University Indianapolis
755 W. Michigan Street
Indianapolis, IN 46202
317-274-0749
www.ulib.iupui.edu
signature.asc

Ray Bon

unread,
Apr 16, 2021, 12:16:44 PM4/16/21
to cas-...@apereo.org
Mark,

Logging config is loaded as part of the application initialization (container handles this part). Cas properties file is loaded after that during application runtime (spring classes do this work).

Command line parameters can be placed in a start up script. For tomcat that is bin/setenv.sh.

Ray

On Fri, 2021-04-16 at 02:21 -0700, Mark van Rossum wrote:
Notice: This message was sent from outside the University of Victoria email system. Please be cautious with links and sensitive information.
-- 
Ray Bon
Programmer Analyst
Development Services, University Systems

I respectfully acknowledge that my place of work is located within the ancestral, traditional and unceded territory of the Songhees, Esquimalt and WSÁNEĆ Nations.
Reply all
Reply to author
Forward
0 new messages