• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Subtle, subtle, little Log4j difficulty

 
Suz Reiner
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a custom logger and a log4j.xml combination that, I hoped would send output to a specified persistent file. However, the content is being created and logged to the console instead. I'm not sure why (considering log4j is creating the intended log file). Clearly I'm missing a step. Can someone take a peak and clue me in? The code snippets are below:


private static final Logger logger = LoggerFactory.getLogger("DailyRoll");
logger.info(“text to add... report some stuff”);


<appender name="stickyBuns" class="org.apache.log4j.DailyRollingFileAppender">
<param name="file" value="daily.log" />
<param name="datePattern" value="'.'yyyy-MM-dd" />
<param name="append" value="false" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %C{6} (%F:%L) - %m%n"/>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="DEBUG"/>
<param name="LevelMax" value="INFO"/>
</filter>
</appender>

<logger name="DailyRoll " additivity="false" >
<level value="info" />
<appender-ref ref="stickyBuns"/>
</logger>



 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In [logger name="DailyRoll "], is the space a typo ? I don't know if log4j ignores it or not, but it's worth removing it.
 
Vijitha Kumara
Bartender
Posts: 4109
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to CodeRanch, Suz Reiner
 
Suz Reiner
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christophe Verré wrote:In [logger name="DailyRoll "], is the space a typo ? I don't know if log4j ignores it or not, but it's worth removing it.



Yep, the space is a typo (I changed the names to protect the innocent... from public exposure ).

Thank you for taking a look.

And thank you for the warm welcome, Vijitha Kumara.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How did you call your log4j property file, and where did you put it ?
 
Suz Reiner
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christophe Verré wrote:How did you call your log4j property file, and where did you put it ?



I am using a log4j.xml file placed within reach of my package. So, in eclipse it would be located at: /src/log4j.xml. Log4j is creating all the log files specified by the appenders I have defined. And, data is being written to those log files with the exception of my custom logger/appender definition (despite the file having been created by log4j).

It is curious. I thought I was having a conflict between jars somewhere but I ran through my environment to root-out potential conflicts. I think I have cleared them but still I'm stubbing my toes and smiling about it.

Suz
 
prem pillai
Ranch Hand
Posts: 87
Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the version of log4j that you are using ?
 
prem pillai
Ranch Hand
Posts: 87
Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Log4j is raising the below warnig for your configuration



As mentioned by Christophe Verré, that space in the logger name is the problem. log4j does not ingore it. I have removed the space and tried ..its logging correctly to the log file.

Do you have a console appender configured in your xml? That may be the reason why log statements are going to the console.
 
Suz Reiner
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought those who replied might like an update (so often missing from discussions). I located the source of my problem. It is a package conflict, after all. It would appear a vendor decided it would be a great idea to repackage all sorts of common/utility libraries with new names. They added a few folders to the base structure and TA-DAH... no-one's the wiser that name conflicts and package hell is afoot.... NOT!

Now... to figure a way isolate those monsters. Anyone have experience with this sort of suffering?

Suz
 
What does a metric clock look like? I bet it is nothing like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic