Does anyone know how to specify a default value for a missing entry in the MDC using log4j's config xml? I have an appender defined in my XML file like so:
<appender name="DBAppender" class="org.apache.log4j.jdbc.JDBCAppender">
<param name="URL" value="jdbc:sqlserver://phenom\\MSSQLSERVER_2012\;databaseName=pickmax_express" />
<param name="Driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<param name="User" value="user" />
<param name="Password" value="password" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="INSERT INTO LOG (source, message, order_id, log_level) VALUES ( 'TESTSOURCE','%m', %X{orderID}, 0)"
/>
</layout>
</appender>
The part in question is the order ID from the MDC (%X{orderID}). I searched around and only found duplicates of the same thread saying something along the lines of $${orderID:-DefaultValue}, but this doesnt work in this context. I need to be able to default the value to 0 or -1 or some other sentinal value when log messages are received in contexts which wont have an order ID