Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Logging a single java application into 2 logs

 
cle tan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's say my application have 2 outcomes, success and failure

If success, it will log into one log, if fail it will log into another

but somehow, when it logs, logging messages will show in both of the logs

The code is shown below:
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using log4j as the underlying framework?

If so, check the addidivity clause, e.g:


WP
 
cle tan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William P O'Sullivan wrote:Are you using log4j as the underlying framework?

If so, check the addidivity clause, e.g:


WP


no i am using java.util.logging framework

i have probs configuring with the log4j, first is the log4j.properties, i find it a bit troublesome and confusing

is it possible to implement it with java.util.logging framework?
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post your properties file then?

WP
 
cle tan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William P O'Sullivan wrote:Can you post your properties file then?

WP

not very sure whether my installation was correct for log4j

i just put the log4j.jar inside the java ext lib for jdk and jre

then now there seems to be a log4j alpha ver, without a jar

not sure what's it used for


 
cle tan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William P O'Sullivan wrote:Can you post your properties file then?

WP


this is my log4j.properties file

not very sure where should i place in eclipse , and where is my output for the logger
 
cle tan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anyone knows how to solve this problem?

i need more guidance regarding this

i have been going through log4j documentation but can't get it to work as it can't locate the log4j.properties file
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You said you were not using log4j due to problems you had!

I think you're confused. Logging frameworks such as commons and slf4j can be complex but usually
sit on top of a physical logging layer (They are facades). I would write a very simple servlet and test
the logging that your code uses.

Also, what is your application server?

WP
 
Bill Clar
Ranch Hand
Posts: 163
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


What's happening here? Should errorLogger and auditLogger be distinct, separate logs?

 
cle tan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William P O'Sullivan wrote:You said you were not using log4j due to problems you had!

I think you're confused. Logging frameworks such as commons and slf4j can be complex but usually
sit on top of a physical logging layer (They are facades). I would write a very simple servlet and test
the logging that your code uses.

Also, what is your application server?

WP


I am still welcoming any solution that can solve my problem, be it java .util.logging or log4j.

I am using the log4j as i assume there is no easy solution if i use java.util.logging


I am just running a eclipse java application but am having problems with log4j logger

Somehow I put the log4j.properties in the src file and it works, but i can't output the file
src
|---package
|----log4j.properties


may i know whether I can write this code in log4j.properties?
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=C:/logging.log
 
cle tan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bill Clar wrote:

What's happening here? Should errorLogger and auditLogger be distinct, separate logs?



yes, how do i configure them to be distinct and separate logs to log the same java application?

Note that the code above uses java.util.logging
 
cle tan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
implemented separate logging in 2 classes

so that if success logging will be done in another class

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic