AKB
AKB

Reputation: 5938

Mule Log4j2 configuration

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Properties>
        <Property name="log-path">${MULE_HOME}/logs/sfdc</Property>
    </Properties>
    <Appenders>
        <Console name="console-log" target="SYSTEM_OUT">
            <PatternLayout
                pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" />
        </Console>
        <RollingFile name="info-log" fileName="${log-path}/sfdc-info.log"
            filePattern="${log-path}/sfdc-info-%d{yyyy-MM-dd}.log">
            <PatternLayout>
                <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
                </pattern>
            </PatternLayout>
            <Policies>
                <TimeBasedTriggeringPolicy interval="1"
                    modulate="true" />
            </Policies>
        </RollingFile>
        <RollingFile name="trace-log" fileName="${log-path}/sfdc-trace.log"
            filePattern="${log-path}/sfdc-trace-%d{yyyy-MM-dd}.log">
            <PatternLayout>
                <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
                </pattern>
            </PatternLayout>
            <Policies>
                <TimeBasedTriggeringPolicy interval="1"
                    modulate="true" />
            </Policies>
        </RollingFile>
        <RollingFile name="error-log" fileName="${log-path}/sfdc-error.log"
            filePattern="${log-path}/sfdc-error-%d{yyyy-MM-dd}.log">
            <PatternLayout>
                <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
                </pattern>
            </PatternLayout>
            <Policies>
                <TimeBasedTriggeringPolicy interval="1"
                    modulate="true" />
            </Policies>
        </RollingFile>
    </Appenders>
    <Loggers>
        <AsyncLogger name="org.apache" level="WARN"/>
        <AsyncLogger name="org.springframework.beans.factory" level="WARN"/>
        <AsyncLogger name="org.mule" level="INFO"/>
        <AsyncLogger name="com.mulesoft" level="INFO"/>
        <Logger name="com.test" level="info" additivity="false">
            <appender-ref ref="info-log" level="info" />
            <appender-ref ref="trace-log" level="debug" />
            <appender-ref ref="error-log" level="error" />
            <appender-ref ref="console-log" level="debug" />
        </Logger>
        <Root level="info" additivity="false">
            <AppenderRef ref="info-log" />
        </Root>
    </Loggers>
</Configuration>

In mule-app.properties specified MULE_HOME=C:/sfproject/test

Problem I am facing is it doesn't get the path ${MULE_HOME} location from mule-app.properties but it goes and creates a directory under home location of the project(MULE_HOME=C:/sfproject/) as ${MULE_HOME}/logs in my local directory. I want all log files should go under C:/sfproject/test/logs directory.

when I deploy same in server( commented mule_home path in mule-app.properties since it is not required and it should point to server location then logs directory), no log files are created under servers/logs directory.

EDIT:

Based on Ryan answer given below, to work locally in anypoint studio, right click on project->Run as->run configuration->ENVIRONMENT->New->Name(MULE_HOME)->Value(c:/project/test)->ok->apply->run.

Upvotes: 1

Views: 3567

Answers (1)

Ryan Carter
Ryan Carter

Reputation: 11606

Try using the env prefix to lookup an environment variable:

 ${env:MULE_HOME}

https://logging.apache.org/log4j/2.0/manual/lookups.html#EnvironmentLookup

Upvotes: 2

Related Questions