Search code examples
log4j2gemfiregeode

Can I modify Geode's default logging behavior?


Geode's out-of-the-box logging behavior does not include the "name" of the logger on each line (usually the name of the class invoking the Log4j Logger). I want to add this field to the default logger configuration, the one that logs to <member-name>/<member-name>.log.

Using the instructions from the documentation, I was able to successfully configure an additional logger using the configuration below -- it writes to a separate file from the default (logs/app.log in this case), but the default configuration also still logs as normal to the default file.

My expectation would be that providing my own log4j2.xml would override the default configuration, not supplement it. Is there anything I can do to override the behavior of that default logger?

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="FATAL" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j">
    <Properties>
        <Property name="geode-pattern">[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} &lt;%thread&gt; tid=%tid] - %c - %message%n%throwable%n</Property>
        <Property name="geode-default">true</Property>
    </Properties>
    <Appenders>
        <File name="MyFile" fileName="logs/app.log">
            <PatternLayout pattern="${geode-pattern}"/>
        </File>
    </Appenders>
    <Loggers>
        <Root level="info">
            <AppenderRef ref="MyFile"/>
        </Root>
    </Loggers>
</Configuration>

Solution

  • I don't see anything wrong with your configuration, actually I just tried it locally and the members only log to the configured file instead of the default:

    $> gfsh start locator --name=locator1 --J=-Dlog4j.configurationFile=$CURRENT_DIRECTORY/log4j-custom.xml
    $> gfsh -e "connect" -e "start server --name=server1 --J=-Dlog4j.configurationFile=$CURRENT_DIRECTORY/log4j-custom.xml"
    
    $> gfsh -e "connect" -e "shutdown --include-locators=true"
    
    $> tree -L 3
    .
    ├── gfsh-0_0.log
    ├── locator1
    │   ├── ConfigDiskDir_locator1
    │   │   ├── BACKUPcluster_config.if
    │   │   ├── BACKUPcluster_config_1.crf
    │   │   ├── BACKUPcluster_config_1.drf
    │   │   └── DRLK_IFcluster_config.lk
    │   ├── GemFire_user
    │   │   └── services
    │   ├── locator10334view.dat
    │   ├── locator10334views.log
    │   ├── logs
    │   │   └── app.log
    │   └── vf.gf.locator.pid
    ├── log4j-custom.xml
    └── server1
        ├── logs
        │   └── app.log
        └── vf.gf.server.pid
    

    I've tried with the latest release, GemFire 9.9.1, maybe you're using an older version?, can you try with the latest one?.