[
https://issues.apache.org/jira/browse/LOG4J2-829?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14140407#comment-14140407
]
Remko Popma commented on LOG4J2-829:
------------------------------------
*Cause*
Special character sequences like {{backslash t}} are converted to the
corresponding special characters (e.g. tab) to accommodate users that migrated
to log4j2 from log4j-1.2 who rely on this behaviour. This behaviour was
introduced in log4j2 in LOG4J2-682.
When the rollover pattern is parsed, it is split into "literal" parts and
"date/index converter" parts.
In the example above, the pattern has value
"C:\Users\popmarem/logs/app-%d\{yyyy-MM-dd_HHmm\}.log", and the first part of
that pattern, "C:\Users\popmarem/logs/app-" is remembered as a literal.
The class responsible for remembering literal strings, LiteralPatternConverter,
will convert special characters in that string in order to address LOG4J2-682.
Any backslash characters in the path are taken as an escape character and are
dropped depending the character that follows the backslash.
*Solution?*
To be honest, I can't think of a good solution for this yet.
One option would be to roll back the changes for LOG4J2-682. This is not a
desirable option since that would inconvenience users who migrated to log4j2
from log4j1.2 and rely on this behaviour.
However, that makes things tricky... How do we distinguish intentional special
characters like {{backslash t}} in the path from unintentional sequences like
"C:\Users{color:red}\t{color}imothy/logs"?
By the way, note that the String substitution from $\{sys:user.home\} to
"C:\Users\timothy" is done by the PluginBuilder, a long time before the
PatternParser is invoked. By the time the PatternParser gets the filePattern
value it is no longer possible to know what part came from a string
substitution. (And even if we did know, the user might have configured a system
property whose value contained the character sequence {{backslash t}} with the
intention to have that sequence converted to a tab character...)
{noformat}
OptionConverter.convertSpecialChars(String) line: 57 <---- PROBLEM OCCURS
HERE
LiteralPatternConverter.<init>(Configuration, String) line: 45
PatternParser.parse(String, List<PatternConverter>, List<FormattingInfo>,
boolean) line: 337
PatternProcessor.<init>(String) line: 69
RollingFileManager.<init>(String, String, OutputStream, boolean, long, long,
TriggeringPolicy, RolloverStrategy, String, Layout<Serializable>, int) line: 58
RollingFileManager$RollingFileManagerFactory.createManager(String,
RollingFileManager$FactoryData) line: 323
RollingFileManager$RollingFileManagerFactory.createManager(String, Object)
line: 290
AbstractManager.getManager(String, ManagerFactory<M,T>, T) line: 71
OutputStreamManager.getManager(String, T,
ManagerFactory<OutputStreamManager,T>) line: 60
RollingFileManager.getFileManager(String, String, boolean, boolean,
TriggeringPolicy, RolloverStrategy, String, Layout<Serializable>, int) line: 79
RollingFileAppender.createAppender(String, String, String, String, String,
String, String, TriggeringPolicy, RolloverStrategy, Layout<Serializable>,
Filter, String, String, String, Configuration) line: 184
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available
[native method]
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 57
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43
Method.invoke(Object, Object...) line: 606
PluginBuilder<T>.build() line: 137 <----- STRING SUBSTITUTION IS DONE IN
HERE
XmlConfiguration(AbstractConfiguration).createPluginObject(PluginType<T>, Node,
LogEvent) line: 752
XmlConfiguration(AbstractConfiguration).createConfiguration(Node, LogEvent)
line: 691
XmlConfiguration(AbstractConfiguration).createConfiguration(Node, LogEvent)
line: 683
XmlConfiguration(AbstractConfiguration).doConfigure() line: 358
XmlConfiguration(AbstractConfiguration).start() line: 159
LoggerContext.setConfiguration(Configuration) line: 385
LoggerContext.reconfigure() line: 444
LoggerContext.start() line: 151
Log4jContextFactory.getContext(String, ClassLoader, Object, boolean) line: 85
Log4jContextFactory.getContext(String, ClassLoader, Object, boolean) line: 37
LogManager.getLogger(String) line: 475
RolloverTest.<clinit>() line: 14
{noformat}
I cannot think of a solution for this yet.
> Error replace slash in pattern file when rolling file appender
> --------------------------------------------------------------
>
> Key: LOG4J2-829
> URL: https://issues.apache.org/jira/browse/LOG4J2-829
> Project: Log4j 2
> Issue Type: Bug
> Components: Appenders
> Affects Versions: 2.0.2
> Environment: Development machine Windows 7
> Reporter: Pablo Vidal Otero
> Assignee: Remko Popma
> Labels: appender, file-pattern, slashes
> Original Estimate: 24h
> Remaining Estimate: 24h
>
> With following log configuration
> {code}
> <RollingFile name="RollingFile" fileName="${sys:user.home}/logs/app.log"
> filePattern="${sys:user.home}/logs/app-%d{MM-dd-yyyy}.log">
> <PatternLayout>
> <pattern>%d %p %c{1.} [%t] %m%n</pattern>
> </PatternLayout>
> <TimeBasedTriggeringPolicy />
> </RollingFile>
> {code}
> When start, the file name is created correctly (C:\user/logs/app.log) but
> when the file will rotate with file pattern, the path name is wrong. The
> system property user.home doesn't has slashes. C:user/logs/app-0915-2014.log
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]