Board index » jbuilder » Message Pane and log4J

Message Pane and log4J


2005-01-28 11:01:27 PM
jbuilder10
All -
I am using log4J 1.2.8 with my JBuilder 2005 project. I have it
configured to use a custom layout with a ConsoleAppender. When I run
from within the IDE, I get no console output (i.e. in the message pane).
When I run from outside the IDE, I get all kinds of console output. I
know the JB redirects console output (System.out) normally so that
messages show up in the message pane - but it seems like there is some
contention for that purpose when log4J is involved.
Direct access in my application to System.out.println() works as
expected (i.e. they show up in the message pane).
Ideas?
Tad
 
 

Re:Message Pane and log4J

On 1/28/2005 at 10:01:27 AM, Tad Frysinger wrote:
Quote
I am using log4J 1.2.8 with my JBuilder 2005 project. I have it
configured to use a custom layout with a ConsoleAppender. When I run
from within the IDE, I get no console output (i.e. in the message pane).
When I run from outside the IDE, I get all kinds of console output. I
know the JB redirects console output (System.out) normally so that
messages show up in the message pane - but it seems like there is some
contention for that purpose when log4J is involved.

Direct access in my application to System.out.println() works as
expected (i.e. they show up in the message pane).

Ideas?
AFAIK, a ConsoleAppender always writes to either System.out or System.err,
and both of those should show up in the console window. The only thing
that makes sense to me is that Log4j might be configured differently in
the two environments. Could it be that it is being configured from a
properties file or some other resource that is not being located when run
from JBuilder?
Probably the easiest way to tell would be to step into the program with
JBuilder's de{*word*81}. The logic in Log4j is pretty straight-forward, and
the library includes debug support, so it should be easy to tell what is
going on.
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
www.JPMcGrath.net/newsgroups/e-mail.html
 

Re:Message Pane and log4J

Tad Frysinger wrote:
Quote
All -

I am using log4J 1.2.8 with my JBuilder 2005 project. I have it
configured to use a custom layout with a ConsoleAppender. When I run
from within the IDE, I get no console output (i.e. in the message pane).
When I run from outside the IDE, I get all kinds of console output. I
know the JB redirects console output (System.out) normally so that
messages show up in the message pane - but it seems like there is some
contention for that purpose when log4J is involved.

Direct access in my application to System.out.println() works as
expected (i.e. they show up in the message pane).

Ideas?

Tad
Tad, did this used to work in another version of JBuilder? Or are you
trying out running with log4j from JBuilder for the first time? Can you
configure a different appender (say a File Appender) and see if you can
get any output (when running from inside JBuilder) to a file?
Because I had major problems getting a configuration for log4j to work
from inside JBuilder. In the end, because we had other restrictions I
won't bother going into, I HAD place the log4j configuration file in the
project's root directory, and I had to leave it with it's default name
(log4j.properties/log4j.xml).
--
Regards,
Lori Olson [TeamB]
------------
Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.
Google Advanced Newsgroup Search
www.google.ca/advanced_group_search
Other Newsgroup Searches:
www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
www.visi.com/~gyles19/fom-serve/cache/1.html
 

{smallsort}

Re:Message Pane and log4J

Lori M Olson [TeamB] wrote:
Quote
Tad Frysinger wrote:

>All -
>
>I am using log4J 1.2.8 with my JBuilder 2005 project. I have it
>configured to use a custom layout with a ConsoleAppender. When I run
>from within the IDE, I get no console output (i.e. in the message
>pane). When I run from outside the IDE, I get all kinds of console
>output. I know the JB redirects console output (System.out) normally
>so that messages show up in the message pane - but it seems like there
>is some contention for that purpose when log4J is involved.
>
>Direct access in my application to System.out.println() works as
>expected (i.e. they show up in the message pane).
>
>Ideas?
>
>Tad


Tad, did this used to work in another version of JBuilder? Or are you
trying out running with log4j from JBuilder for the first time? Can you
configure a different appender (say a File Appender) and see if you can
get any output (when running from inside JBuilder) to a file?

Because I had major problems getting a configuration for log4j to work
from inside JBuilder. In the end, because we had other restrictions I
won't bother going into, I HAD place the log4j configuration file in the
project's root directory, and I had to leave it with it's default name
(log4j.properties/log4j.xml).

Oops. AND we had to manually add that config file to the project, and
set up that kind of file to "Copy" when we did a make or rebuild.
--
Regards,
Lori Olson [TeamB]
------------
Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.
Google Advanced Newsgroup Search
www.google.ca/advanced_group_search
Other Newsgroup Searches:
www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
www.visi.com/~gyles19/fom-serve/cache/1.html
 

Re:Message Pane and log4J

Quote

Tad, did this used to work in another version of JBuilder? Or are you
trying out running with log4j from JBuilder for the first time? Can you
configure a different appender (say a File Appender) and see if you can
get any output (when running from inside JBuilder) to a file?

Because I had major problems getting a configuration for log4j to work
from inside JBuilder. In the end, because we had other restrictions I
won't bother going into, I HAD place the log4j configuration file in the
project's root directory, and I had to leave it with it's default name
(log4j.properties/log4j.xml).

Don't know about prior versions of JBuilder.
This appender is programmatically set, and it replaces the appender
configured via any log4j.properties. In this case, there is no
log4j.properties at all, and so it is using the "default" log, like this:
public class MasterLogger {
/*
* The name of the logger.
* For this class to recognize the appender, the name specified in the
* log4j.properties file must match. e.g.:
*
* log4j.category.com.newco=DEBUG, stdout, log2file
*
*/
private static final String DEFAULT_LOGGER_CATEgory_NAME = "com.newco";
// The name of the appender to modify
private static final String APPENDER_NAME = "log2file";
// Directory relative to the user home directory to put the log files.
private static final String DIRPATH = "/NewCo";
public static Logger logger;
static {
try {
// Create the directory for the log files.
String home = System.getProperty("newco.home");
if (home == null) {
home = System.getProperty("user.home");
}
File logDir = new File(home + DIRPATH);
logDir.mkdirs();
String fileName = null;
// Get the logger already defined in log4j.properties
logger = Logger.getLogger(DEFAULT_LOGGER_CATEgory_NAME);
// Get the specific appender & remove it.
RollingFileAppender rollingFileAppender = (RollingFileAppender)
logger.getAppender(APPENDER_NAME);
RollingFileAppender newRollingFileAppender = null;
Layout layout = null;
if (rollingFileAppender != null) {
logger.removeAppender(rollingFileAppender);
// Get the critical parameters from the old appender
layout = rollingFileAppender.getLayout();
int backupIndex = rollingFileAppender.getMaxBackupIndex();
long maxFileSize = rollingFileAppender.getMaximumFileSize();
fileName = File.separator + rollingFileAppender.getFile();
// Create a new appender using the old parameters but with the
// new path.
newRollingFileAppender = new RollingFileAppender(layout,
logDir.getAbsolutePath() +
fileName,
true);
newRollingFileAppender.setMaxBackupIndex(backupIndex);
newRollingFileAppender.setMaximumFileSize(maxFileSize);
logger.addAppender(newRollingFileAppender);
}
else {
System.out.println("Could not find requested appender: " +
APPENDER_NAME + ", creating default.");
// Create it
fileName = File.separator + "default.log";
layout = new PatternLayout("%d{dd MMM yyyy HH:mm:ss}
%-10.20c{2} %C{1}.%M.%L %x: %m%n");
// Create a new appender using the old parameters but with the
// new path.
newRollingFileAppender = new RollingFileAppender(layout,
logDir.getAbsolutePath() +
fileName,
true);
newRollingFileAppender.setMaxBackupIndex(100);
newRollingFileAppender.setMaximumFileSize(1024 * 1024);
logger.addAppender(newRollingFileAppender);
}
layout = new PatternLayout("%d{dd MMM yyyy HH:mm:ss}
%-10.20c{2} %C{1}.%M.%L %x: %m%n");
ConsoleAppender consoleAppender = new ConsoleAppender(layout);
logger.addAppender(consoleAppender);
System.out.println("Logging subsystem initialized");
} catch (Exception e) {
System.out.println("Got exception setting up appender: " +
e.getMessage() );
}
}
}
Tad
 

Re:Message Pane and log4J

Tad Frysinger wrote:
Quote
Don't know about prior versions of JBuilder.

This appender is programmatically set, and it replaces the appender
configured via any log4j.properties. In this case, there is no
log4j.properties at all, and so it is using the "default" log, like this:


public class MasterLogger {
Well, I have no experience with programmatically replacing the default
configuration. And a review of the "complete log4j manual" reveals
absolutely nothing useful on that topic. :-p Seems that Ceki doesn't
believe in them.
Hopefully someone else with experience in using programmatically defined
log4j configurations can weigh in on the matter. Or you can take the
question up in the log4j mailing lists.
logging.apache.org/site/mailing-lists.html
--
Regards,
Lori Olson [TeamB]
------------
Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.
Google Advanced Newsgroup Search
www.google.ca/advanced_group_search
Other Newsgroup Searches:
www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
www.visi.com/~gyles19/fom-serve/cache/1.html