Allowing override of log4j2.xml

Currently moqui hard-codes its dependence on log4j2.xml which makes the only possible way of changing logging is by that editing that file directly.

Wouldn’t it make more sense to make this configurable? Granted it should be a compile-time rather than runtime configuration, but nonetheless I should be able to override the default log4j2.xml file without touching the framework. Ideas?

2 Likes

I think any change on this would be based on the use case (assuming it’s feasible to do technically).

What’s the use case for this? Are you trying to use a different logger or use a fancy tool like sentry?

Well, I think in my case it is simple. I would like to reduce the logging in production, so move things for example from info to warn or so.

Technically it might be workable. Let’s say you keep the log file in framework, but you generate it in /runtime for example by merging / overriding depending on a certain condition (gradle condition during build time) and thus you depend on that generated file. I know class loading is a bit tricky and we need to be careful but if the file is already in place before starting moqui then perhaps it’s a solvable problem without much work.

In one production instance that I have, the hard-drive got filled with 40GB of logs. Yes of course I need to clean them up and all, but perhaps having less of them might also help, which is the reason I started this discussion.

1 Like

I was looking on how to do this recently, and gave up on how. After looking again just now, and based on your comment I’m surprised there isn’t a MoquiConf or runtime parameter to set this.

IIRC in the most recent versions of Moqui, the logging in production is sent to elastic search and local disk.

Another thing to check is if you’re running in Dev mode you’ll log more with this config (which is the default):

    <server-stats stats-skip-condition="pathInfo?.startsWith('/rpc') || pathInfo?.startsWith('/rest') || pathInfo?.startsWith('/status')">
        <!-- For development, track everything! It'll run slow through... -->
        <artifact-stats type="AT_XML_SCREEN" persist-bin="true" persist-hit="true"/>
        <artifact-stats type="AT_XML_SCREEN_CONTENT" persist-bin="true" persist-hit="true"/>
        <artifact-stats type="AT_XML_SCREEN_TRANS" persist-bin="true" persist-hit="true"/>
        <!-- NOTE: entity-implicit and entity-auto services never persist hits -->
        <artifact-stats type="AT_SERVICE" persist-bin="true" persist-hit="true"/>
        <artifact-stats type="AT_ENTITY" persist-bin="true"/>
    </server-stats>
Side note about slf4j

I found this about slf4j (see this):

We might be able to submit a patch to change this:

        <Logger name="org.moqui" level="info"/>

To something like this:

        <Logger name="org.moqui" level="${env:moqui.logger.level.org_moqui}"/>

Where we set the moqui.logger.level.org_moqui environment variable. Assuming does what is expected, and we can set a default option to info.

We could then follow that pattern for any other logging changes that are needed.

Yes all great ideas. So yes I guess it’s a combo of variable settings for dev / prod and variable substitution in the file itself. If it could be done this easily then great, much easier than what I had in mind. What’s the next step here? Can I help?

1 Like

Ideally, someone would take on the responsibility to complete this, test and fix the problem where no default is set, but can be overrided with an environment variable. Then submit a PR.

@taher you have the primary use case here, so if you’d like to do it, I’ll support you and review the code for the PR.