Discussion:
[jira] [Created] (LOG4J2-829) Error replace slash in pattern file when rolling file appender
Pablo Vidal Otero (JIRA)
2014-09-15 13:34:33 UTC
Permalink
Pablo Vidal Otero created LOG4J2-829:
----------------------------------------

Summary: 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
Priority: Minor


With following log configuration

<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>

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)
Pablo Vidal Otero (JIRA)
2014-09-15 13:56:34 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-829?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Pablo Vidal Otero updated LOG4J2-829:
-------------------------------------
Priority: Major (was: Minor)
Post by Pablo Vidal Otero (JIRA)
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
Labels: appender, file-pattern, slashes
Original Estimate: 24h
Remaining Estimate: 24h
With following log configuration
<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>
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)
Remko Popma (JIRA)
2014-09-18 17:37:33 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-829?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Remko Popma updated LOG4J2-829:
-------------------------------
Description:
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

was:
With following log configuration

<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>

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
Post by Pablo Vidal Otero (JIRA)
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
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)
Remko Popma (JIRA)
2014-09-19 10:36:33 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-829?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Remko Popma reassigned LOG4J2-829:
----------------------------------

Assignee: Remko Popma
Post by Pablo Vidal Otero (JIRA)
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)
Remko Popma (JIRA)
2014-09-19 12:21:34 UTC
Permalink
[ 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.
Post by Pablo Vidal Otero (JIRA)
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)
Remko Popma (JIRA)
2014-09-19 12:25:34 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-829?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Remko Popma updated LOG4J2-829:
-------------------------------
Remaining Estimate: (was: 24h)
Original Estimate: (was: 24h)
Post by Pablo Vidal Otero (JIRA)
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
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)
Remko Popma (JIRA)
2014-09-19 12:27:34 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-829?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14140410#comment-14140410 ]

Remko Popma commented on LOG4J2-829:
------------------------------------

How did log4j-1.2 handle this?
Post by Pablo Vidal Otero (JIRA)
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
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)
Pablo Vidal Otero (JIRA)
2014-09-19 13:24:34 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-829?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14140458#comment-14140458 ]

Pablo Vidal Otero commented on LOG4J2-829:
------------------------------------------

We do a temporal fix ussing double slash when we add these new file appenders programaticaly but we cant't use the property replace management with ${sys:user.home}
Post by Pablo Vidal Otero (JIRA)
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
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)
Pablo Vidal Otero (JIRA)
2014-09-19 13:27:33 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-829?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14140458#comment-14140458 ]

Pablo Vidal Otero edited comment on LOG4J2-829 at 9/19/14 1:26 PM:
-------------------------------------------------------------------

We do a temporal fix ussing double slash when we add these new file appenders programaticaly but we cant't use the property replace management with ${sys:user.home}

// System properties
private static final String FILE_SEPARATOR = System.getProperty("file.separator");

String FILE_PATTERN = FILE_PATH + FILE_SEPARATOR + FILE_SEPARATOR + FILE_NAME + FILE_PATTERN_ROLL + FILE_EXTENSION;



was (Author: limkin):
We do a temporal fix ussing double slash when we add these new file appenders programaticaly but we cant't use the property replace management with ${sys:user.home}
Post by Pablo Vidal Otero (JIRA)
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
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)
Remko Popma (JIRA)
2014-09-19 14:28:34 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-829?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14140641#comment-14140641 ]

Remko Popma commented on LOG4J2-829:
------------------------------------

I think I have a solution.
The intention of LOG4J2-682 was not for special characters to be used in file paths, it was mainly for the PatternLayout of log events in the log file. It's just that the code where the special character sequences are converted is also used by the RollingFileManager.

So, when used by the RollingFileManager, we _don't_ want backslashes to be treated as escape characters, but _otherwise we do_.

The easiest way to fix this is to add another boolean parameter to {{PatternParser.parse(String, List<PatternConverter>, List<FormattingInfo>, boolean)}} and to the {{LiteralPatternConverter}} constructor. This boolean would control whether {{OptionConverter.convertSpecialChars}} is invoked or not.
Post by Pablo Vidal Otero (JIRA)
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
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)
Remko Popma (JIRA)
2014-09-19 16:40:34 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-829?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Remko Popma resolved LOG4J2-829.
--------------------------------
Resolution: Fixed
Fix Version/s: 2.1

Fixed in master in commit b4ad64f3dad6cbe9fdb8ca7427fc941661ab83ea.
Please verify and close.
Post by Pablo Vidal Otero (JIRA)
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
Fix For: 2.1
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)

Loading...