Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Appender Layout Problem- log4j:ERROR Unexpected char [u] at position

 
Mat Anthony
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I'm currently trying to programmatically create a DailyRollingFileAppender using the following method:-

private DailyRollingFileAppender createDailyRollingFileAppender(String appenderName, String file)
{
DailyRollingFileAppender appender = new DailyRollingFileAppender();
appender.requiresLayout();
appender.setName(appenderName);
appender.setFile(file);
appender.setDatePattern(log4jDatePatternFileExt);
Layout layout = new PatternLayout(log4jInternalFilePattern);
appender.setLayout(layout);
return appender;
}

The log4jInternalFilePattern contains the following:-
"%d{EEE MMM dd HH:mm:ss} BST %d{yyyy} [%u] %m%n"

Every time I call:-
Layout layout = new PatternLayout(log4jInternalFilePattern);

The following error appears in the console:-

log4j:ERROR Unexpected char [u] at position 39 in conversion patterrn.

Has anybody seen this before??
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope, what is %u supposed to be replaced by? Is it valid in that location?
 
Mat Anthony
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Martijn,
That was a quick response, I just typed it in.

The %u is supposed to be replaced by the username of the person that has just logged in.

Richard

 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume you've played around with removing the %u, removing the '[' and ']' characters?
 
Mat Anthony
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Martijn,
just found out that we seem to be using a customized PatternLayout that overrides
the createPatternParser method, hence since I was using the default the error ocurred.

Richard


 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad you figured it out!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic