Logger info

S

scoffer

Hi all,

i need to change the Formatter for the Logger that write on the console.
My code is something like that:

logHandler = new FileHandler("RecVenduto.log", true);
theLogger.addHandler(logHandler);
theLogger.setLevel(logLevel);
Handler hdl [] = theLogger.getHandlers();
for (int cnt=0; cnt < hdl.length; cnt++) {
hdl[cnt].setFormatter(new MyCustomFormatter());
hdl[cnt].setLevel(logLevel);
}

This code change the Formatter for the FileHandler, but the console output
don't change.

Can I set different Levels for FileHandler and console output??

Thanks in advance.


Daniele B.
Software Specialist
 
?

=?ISO-8859-1?Q?Eduardo_Y=E1=F1ez_Parareda?=

scoffer said:
Hi all,

i need to change the Formatter for the Logger that write on the console.
My code is something like that:

logHandler = new FileHandler("RecVenduto.log", true);
theLogger.addHandler(logHandler);
theLogger.setLevel(logLevel);
Handler hdl [] = theLogger.getHandlers();
for (int cnt=0; cnt < hdl.length; cnt++) {
hdl[cnt].setFormatter(new MyCustomFormatter());
hdl[cnt].setLevel(logLevel);
}

This code change the Formatter for the FileHandler, but the console output
don't change.

Can I set different Levels for FileHandler and console output??

in the logging.properties file:
java.util.logging.ConsoleHandler.level = FINEST

And to change the formatter:
java.util.logging.ConsoleHandler.formatter = es.bfc.logging.SingleLineFormatter

Why don't you use the properties file to assign handlers to the logger?
 
S

scoffer

Eduardo Yáñez Parareda said:
scoffer said:
Hi all,

i need to change the Formatter for the Logger that write on the console.
My code is something like that:

logHandler = new FileHandler("RecVenduto.log", true);
theLogger.addHandler(logHandler);
theLogger.setLevel(logLevel);
Handler hdl [] = theLogger.getHandlers();
for (int cnt=0; cnt < hdl.length; cnt++) {
hdl[cnt].setFormatter(new MyCustomFormatter());
hdl[cnt].setLevel(logLevel);
}

This code change the Formatter for the FileHandler, but the console
output
don't change.

Can I set different Levels for FileHandler and console output??

in the logging.properties file:
java.util.logging.ConsoleHandler.level = FINEST

And to change the formatter:
java.util.logging.ConsoleHandler.formatter =
es.bfc.logging.SingleLineFormatter

Why don't you use the properties file to assign handlers to the logger?

I have many other properties to store so I want to store the LogLevel with
the other.

Thank's ... i'm going to test.
 
S

scoffer

Eduardo Yáñez Parareda said:
scoffer said:
Hi all,

i need to change the Formatter for the Logger that write on the console.
My code is something like that:

logHandler = new FileHandler("RecVenduto.log", true);
theLogger.addHandler(logHandler);
theLogger.setLevel(logLevel);
Handler hdl [] = theLogger.getHandlers();
for (int cnt=0; cnt < hdl.length; cnt++) {
hdl[cnt].setFormatter(new MyCustomFormatter());
hdl[cnt].setLevel(logLevel);
}

This code change the Formatter for the FileHandler, but the console
output
don't change.

Can I set different Levels for FileHandler and console output??

in the logging.properties file:
java.util.logging.ConsoleHandler.level = FINEST

And to change the formatter:
java.util.logging.ConsoleHandler.formatter =
es.bfc.logging.SingleLineFormatter

Why don't you use the properties file to assign handlers to the logger?


I've tried to add another Handler to the Logger of Consolehandler so my code
now is:

logHandler = new FileHandler("RecVenduto.log", true);
logHandler.setFormatter(new MyCustomFormatter());
logHandler.setLevel(Level.FINEST);
theLogger.addHandler(logHandler);
ConsoleHandler consoleHandler = new ConsoleHandler();
consoleHandler.setLevel(Level.INFO);
consoleHandler.setFormatter(new MyCustomFormatter());
theLogger.addHandler(consoleHandler);
theLogger.setLevel(logLevel);

And now I've two different output to my console.

Can I set this configuration programmatically and not from the properties
file??

I've to distribute this application to many sites and I don't want to change
the properties file for every client.
 
H

Henry

scoffer said:
Eduardo Yáñez Parareda said:
scoffer said:
Hi all,

i need to change the Formatter for the Logger that write on the console.
My code is something like that:

logHandler = new FileHandler("RecVenduto.log", true);
theLogger.addHandler(logHandler);
theLogger.setLevel(logLevel);
Handler hdl [] = theLogger.getHandlers();
for (int cnt=0; cnt < hdl.length; cnt++) {
hdl[cnt].setFormatter(new MyCustomFormatter());
hdl[cnt].setLevel(logLevel);
}

This code change the Formatter for the FileHandler, but the console
output
don't change.

Can I set different Levels for FileHandler and console output??

in the logging.properties file:
java.util.logging.ConsoleHandler.level = FINEST

And to change the formatter:
java.util.logging.ConsoleHandler.formatter =
es.bfc.logging.SingleLineFormatter

Why don't you use the properties file to assign handlers to the logger?


I've tried to add another Handler to the Logger of Consolehandler so my code
now is:

logHandler = new FileHandler("RecVenduto.log", true);
logHandler.setFormatter(new MyCustomFormatter());
logHandler.setLevel(Level.FINEST);
theLogger.addHandler(logHandler);
ConsoleHandler consoleHandler = new ConsoleHandler();
consoleHandler.setLevel(Level.INFO);
consoleHandler.setFormatter(new MyCustomFormatter());
theLogger.addHandler(consoleHandler);
theLogger.setLevel(logLevel);

And now I've two different output to my console.

Can I set this configuration programmatically and not from the properties
file??

I've to distribute this application to many sites and I don't want to change
the properties file for every client.

There is a pretty good article about how logging works and how to do
almost anything you can ever want with it. If you look at the API
documentation in the JDK, you should see a major section called "Guide
to Features - Java Platform". In the subsection called Base Libraries,
you will find a link for "Logging". If you click on that link, you go
to a short page entitled Java Logging APIs. If you click the first link
on that page, "Logging Overview", you will get the document that
describes the concepts behind Logging in Java.

I think this document should answer most of your questions. You should
also be aware that you can set the properties for logging on your
system in the logging.properties file, which you should find in the lib
directory of the JRE (or the jre/lib directory of your JDK).
 
S

scoffer

"Henry" <[email protected]> ha scritto nel messaggio
Eduardo Yáñez Parareda said:
scoffer said:
Hi all,

i need to change the Formatter for the Logger that write on the
console.
My code is something like that:

logHandler = new FileHandler("RecVenduto.log", true);
theLogger.addHandler(logHandler);
theLogger.setLevel(logLevel);
Handler hdl [] = theLogger.getHandlers();
for (int cnt=0; cnt < hdl.length; cnt++) {
hdl[cnt].setFormatter(new MyCustomFormatter());
hdl[cnt].setLevel(logLevel);
}

This code change the Formatter for the FileHandler, but the console
output
don't change.

Can I set different Levels for FileHandler and console output??

in the logging.properties file:
java.util.logging.ConsoleHandler.level = FINEST

And to change the formatter:
java.util.logging.ConsoleHandler.formatter =
es.bfc.logging.SingleLineFormatter

Why don't you use the properties file to assign handlers to the logger?


I've tried to add another Handler to the Logger of Consolehandler so my
code
now is:

logHandler = new FileHandler("RecVenduto.log", true);
logHandler.setFormatter(new MyCustomFormatter());
logHandler.setLevel(Level.FINEST);
theLogger.addHandler(logHandler);
ConsoleHandler consoleHandler = new ConsoleHandler();
consoleHandler.setLevel(Level.INFO);
consoleHandler.setFormatter(new MyCustomFormatter());
theLogger.addHandler(consoleHandler);
theLogger.setLevel(logLevel);

And now I've two different output to my console.

Can I set this configuration programmatically and not from the properties
file??

I've to distribute this application to many sites and I don't want to
change
the properties file for every client.

There is a pretty good article about how logging works and how to do
almost anything you can ever want with it. If you look at the API
documentation in the JDK, you should see a major section called "Guide
to Features - Java Platform". In the subsection called Base Libraries,
you will find a link for "Logging". If you click on that link, you go
to a short page entitled Java Logging APIs. If you click the first link
on that page, "Logging Overview", you will get the document that
describes the concepts behind Logging in Java.

I think this document should answer most of your questions. You should
also be aware that you can set the properties for logging on your
system in the logging.properties file, which you should find in the lib
directory of the JRE (or the jre/lib directory of your JDK).

--
Buzz


The solution is very simple ..... just create the logger with anonymous
reference like this:

private static Logger theLogger = Logger.getLogger("");

and the console logger get the same level and formatter from the
fileHandler.

Thanks for the informations.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,079
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top