Discussion:
[jade-develop] proper use of java.util.logging in JADE application
Dave Welchons
2014-09-04 21:32:55 UTC
Permalink
Dear jade-develop mailing list,

I initially placed many prints in my AlertAgent.java application. If I
wanted to turn them off, I had to change the source code. So I thought I
would use java.util.logging as described in the sentence "including
application-specific logging messages" Section 3.7.5 (p. 46) of "Developing
Multi-Agent Systems With JADE". I wanted an output file specific to a
specific agent (i.e. multiple output files with one for each agent), and I
read that java.util.logging does not allow that in the java.util.logging
config file, so I attempted to add a FileHandler in my agent source code as
shown below. I also passed in the argument
"-Djava.util.logging.config.file=logging.properties" and I created the file
logging.properties as shown below, similar to p. 47 of the book. In the
config file I specified that the alert agent logging level should be "fine"
for its package com.brsc.masaide.alertagent. When I run my application I
only see the "info()" log statements, but I do not see the "fine()" log
statements.

Can you see what I am doing wrong?

Thanks,

Dave Welchons



P.S. Maybe this is just a question for java.util.logging use and not
related to JADE, and if so, I apologize for wasting your time







***************************

Selected source code statements in AlertAgent.java:

***************************



package com.brsc.masaide.alertagent;

.

public class AlertAgent extends Agent {



private Logger logger =
jade.util.Logger.getMyLogger(this.getClass().getName());



.





protected void setup()

{



// Create file logger if configuration file level high enough

if (logger.isLoggable(jade.util.Logger.FINE)) {

FileHandler fileHandler;

try {

fileHandler = new FileHandler("AlertAgent_Logger.txt");

} catch (SecurityException | IOException e) {

logger.severe(" AlertAgent.java: FileHandler exception =
"+e.getLocalizedMessage());

e.printStackTrace();

return;

}

fileHandler.setFormatter(new SimpleFormatter());

fileHandler.setLevel(Level.FINE);

logger.addHandler(fileHandler);

}

// Note commented out below. Only see middle logger (logger.fine())
below if next line uncommented.

// Otherwise do not see middle log, implying that the default "info" is
in effect.

// Config file setting of level to "fine" for this package
"com.brsc.masaide.alertagent" does not seem to have an effect.

//logger.setLevel(Level.FINE);



// Print agent data

logger.info(" AlertAgent.java: setup(): my local-name is
"+getAID().getLocalName());

logger.fine(" AlertAgent.java: setup(): my GUID is
"+getAID().getName());

logger.info(" AlertAgent.java: setup(): my AID is: "+getAID());











***********************

Config file logging.properties:

***********************





# Set default log level to INFO, and then override for those packages that

# require more debug info

.level = INFO



# Add ConsoleHandler here for all classes.

# A unique FileHandler will be added in each module to provide different
file

# for each module. If specified FileHandler here one file would be used

# for output of all modules (I think).

handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler



# Modify default level for all handlers which will be overridden below

# with each package level.

java.util.logging.ConsoleHandler.level = ALL

java.util.logging.FileHandler.level = ALL



# Set all handlers to simple (non-xml) format

java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter

java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter



# Set log level for my class of interest to FINE

com.brsc.masaide.alertagent.level = FINE



# Wild guess below since above didn't work, since I think I saw this below
somewhere in JADE documentation

com_brsc_masaide_alertagent_loglevel = FINE





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jade.tilab.com/pipermail/jade-develop/attachments/20140904/71a53dfb/attachment.html>
Scagliotti Enrico (Guest)
2014-09-05 12:58:38 UTC
Permalink
Hi,

Your code and logger configuration are correct.
I tried your implementation and it works well.
One possible problem is the path of the loaded configuration file, try with an absolute path, for example: -Djava.util.logging.config.file=<absolute-path>/logging.properties

Then in logging.properties you must also specify the property java.util.logging.FileHandler.pattern=<filename> to specify the name of the log generic log file.

The final effect is that, when level is INFO, only generic log file is created; while, when level is FINE, two log files are created (one generic and one specific for agent).

Bye
Enrico

Da: jade-develop [mailto:jade-develop-bounces at avalon.tilab.com] Per conto di Dave Welchons
Inviato: giovedì 4 settembre 2014 23:33
A: jade-develop at avalon.tilab.com
Oggetto: [jade-develop] proper use of java.util.logging in JADE application

Dear jade-develop mailing list,
I initially placed many prints in my AlertAgent.java application. If I wanted to turn them off, I had to change the source code. So I thought I would use java.util.logging as described in the sentence "including application-specific logging messages" Section 3.7.5 (p. 46) of "Developing Multi-Agent Systems With JADE". I wanted an output file specific to a specific agent (i.e. multiple output files with one for each agent), and I read that java.util.logging does not allow that in the java.util.logging config file, so I attempted to add a FileHandler in my agent source code as shown below. I also passed in the argument "-Djava.util.logging.config.file=logging.properties" and I created the file logging.properties as shown below, similar to p. 47 of the book. In the config file I specified that the alert agent logging level should be "fine" for its package com.brsc.masaide.alertagent. When I run my application I only see the "info()" log statements, but I do not see the "fine()" log statements.
Can you see what I am doing wrong?
Thanks,
Dave Welchons

P.S. Maybe this is just a question for java.util.logging use and not related to JADE, and if so, I apologize for wasting your time



***************************
Selected source code statements in AlertAgent.java:
***************************

package com.brsc.masaide.alertagent;
...
public class AlertAgent extends Agent {

private Logger logger = jade.util.Logger.getMyLogger(this.getClass().getName());

...


protected void setup()
{

// Create file logger if configuration file level high enough
if (logger.isLoggable(jade.util.Logger.FINE)) {
FileHandler fileHandler;
try {
fileHandler = new FileHandler("AlertAgent_Logger.txt");
} catch (SecurityException | IOException e) {
logger.severe(" AlertAgent.java: FileHandler exception = "+e.getLocalizedMessage());
e.printStackTrace();
return;
}
fileHandler.setFormatter(new SimpleFormatter());
fileHandler.setLevel(Level.FINE);
logger.addHandler(fileHandler);
}
// Note commented out below. Only see middle logger (logger.fine()) below if next line uncommented.
// Otherwise do not see middle log, implying that the default "info" is in effect.
// Config file setting of level to "fine" for this package "com.brsc.masaide.alertagent" does not seem to have an effect.
//logger.setLevel(Level.FINE);

// Print agent data
logger.info(" AlertAgent.java: setup(): my local-name is "+getAID().getLocalName());
logger.fine(" AlertAgent.java: setup(): my GUID is "+getAID().getName());
logger.info(" AlertAgent.java: setup(): my AID is: "+getAID());





***********************
Config file logging.properties:
***********************


# Set default log level to INFO, and then override for those packages that
# require more debug info
.level = INFO

# Add ConsoleHandler here for all classes.
# A unique FileHandler will be added in each module to provide different file
# for each module. If specified FileHandler here one file would be used
# for output of all modules (I think).
handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler

# Modify default level for all handlers which will be overridden below
# with each package level.
java.util.logging.ConsoleHandler.level = ALL
java.util.logging.FileHandler.level = ALL

# Set all handlers to simple (non-xml) format
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter

# Set log level for my class of interest to FINE
com.brsc.masaide.alertagent.level = FINE

# Wild guess below since above didn't work, since I think I saw this below somewhere in JADE documentation
com_brsc_masaide_alertagent_loglevel = FINE


________________________________
Nessun virus nel messaggio.
Controllato da AVG - www.avg.com<http://www.avg.com>
Versione: 2014.0.4745 / Database dei virus: 4015/8144 - Data di rilascio: 02/09/2014
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jade.tilab.com/pipermail/jade-develop/attachments/20140905/ebce8f00/attachment.html>
Dave Welchons
2014-09-05 15:08:31 UTC
Permalink
Hi Enrico,
Your suggestions fixed my problem.
Thank you.
Bye,
Dave


P.S.

I have another question related to logging. In the document
http://jade.tilab.com/doc/tutorials/logging/JADELoggingService.html is the
statement below. It must be important to do this, but doesn't the
java.util.logging system already do that type of checking internally?





The usage of the following coding style is recommended in order to log a
message with a certain level of importance:

if (logger.isLoggable(jade.util.Logger.myLevel))
logger.log(jade.util.Logger.myLevel, "this is the message to log");

where myLevel will be one of the levels allowed ( for instance
jade.util.Logger.SEVERE). Notice that testing if the level is loggable
before actually calling the log method allows relevant performance
improvements.








-----Original Message-----
From: Scagliotti Enrico (Guest)
[mailto:enrico.scagliotti at guest.telecomitalia.it]
Sent: Friday, September 05, 2014 8:59 AM
To: Dave Welchons; jade-develop at avalon.tilab.com
Subject: R: [jade-develop] proper use of java.util.logging in JADE
application

Hi,



Your code and logger configuration are correct.

I tried your implementation and it works well.

One possible problem is the path of the loaded configuration file, try with
an absolute path, for example:
-Djava.util.logging.config.file=<absolute-path>/logging.properties



Then in logging.properties you must also specify the property
java.util.logging.FileHandler.pattern=<filename> to specify the name of the
log generic log file.



The final effect is that, when level is INFO, only generic log file is
created; while, when level is FINE, two log files are created (one generic
and one specific for agent).



Bye

Enrico



Da: jade-develop [mailto:jade-develop-bounces at avalon.tilab.com] Per conto di
Dave Welchons
Inviato: giovedì 4 settembre 2014 23:33
A: jade-develop at avalon.tilab.com
Oggetto: [jade-develop] proper use of java.util.logging in JADE application



Dear jade-develop mailing list,

I initially placed many prints in my AlertAgent.java application. If I
wanted to turn them off, I had to change the source code. So I thought I
would use java.util.logging as described in the sentence “including
application-specific logging messages” Section 3.7.5 (p. 46) of “Developing
Multi-Agent Systems With JADE”. I wanted an output file specific to a
specific agent (i.e. multiple output files with one for each agent), and I
read that java.util.logging does not allow that in the java.util.logging
config file, so I attempted to add a FileHandler in my agent source code as
shown below. I also passed in the argument
“–Djava.util.logging.config.file=logging.properties” and I created the file
logging.properties as shown below, similar to p. 47 of the book. In the
config file I specified that the alert agent logging level should be “fine”
for its package com.brsc.masaide.alertagent. When I run my application I
only see the “info()” log statements, but I do not see the “fine()” log
statements.

Can you see what I am doing wrong?

Thanks,

Dave Welchons



P.S. Maybe this is just a question for java.util.logging use and not
related to JADE, and if so, I apologize for wasting your time







***************************

Selected source code statements in AlertAgent.java:

***************************



package com.brsc.masaide.alertagent;




public class AlertAgent extends Agent {



private Logger logger =
jade.util.Logger.getMyLogger(this.getClass().getName());










protected void setup()

{



// Create file logger if configuration file level high enough

if (logger.isLoggable(jade.util.Logger.FINE)) {

FileHandler fileHandler;

try {

fileHandler = new FileHandler("AlertAgent_Logger.txt");

} catch (SecurityException | IOException e) {

logger.severe(" AlertAgent.java: FileHandler exception =
"+e.getLocalizedMessage());

e.printStackTrace();

return;

}

fileHandler.setFormatter(new SimpleFormatter());

fileHandler.setLevel(Level.FINE);

logger.addHandler(fileHandler);

}

// Note commented out below. Only see middle logger (logger.fine())
below if next line uncommented.

// Otherwise do not see middle log, implying that the default “info” is
in effect.

// Config file setting of level to “fine” for this package
“com.brsc.masaide.alertagent” does not seem to have an effect.

//logger.setLevel(Level.FINE);



// Print agent data

logger.info(" AlertAgent.java: setup(): my local-name is
"+getAID().getLocalName());

logger.fine(" AlertAgent.java: setup(): my GUID is
"+getAID().getName());

logger.info(" AlertAgent.java: setup(): my AID is: "+getAID());











***********************

Config file logging.properties:

***********************





# Set default log level to INFO, and then override for those packages that

# require more debug info

.level = INFO



# Add ConsoleHandler here for all classes.

# A unique FileHandler will be added in each module to provide different
file

# for each module. If specified FileHandler here one file would be used

# for output of all modules (I think).

handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler



# Modify default level for all handlers which will be overridden below

# with each package level.

java.util.logging.ConsoleHandler.level = ALL

java.util.logging.FileHandler.level = ALL



# Set all handlers to simple (non-xml) format

java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter

java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter



# Set log level for my class of interest to FINE

com.brsc.masaide.alertagent.level = FINE



# Wild guess below since above didn’t work, since I think I saw this below
somewhere in JADE documentation

com_brsc_masaide_alertagent_loglevel = FINE





________________________________

Nessun virus nel messaggio.
Controllato da AVG - www.avg.com
Versione: 2014.0.4745 / Database dei virus: 4015/8144 - Data di rilascio:
02/09/2014
Scagliotti Enrico (Guest)
2014-09-05 15:22:40 UTC
Permalink
Hi Dave,

Very well!

Your observation is correct, the check is already done internally.
The preventive control can be useful to optimize the code in the case of multiple lines of log.

Bye
Enrico


-----Messaggio originale-----
Da: Dave Welchons [mailto:welchons at brsc.com]
Inviato: venerdì 5 settembre 2014 17:09
A: Scagliotti Enrico (Guest)
Cc: jade-develop at avalon.tilab.com
Oggetto: RE: [jade-develop] proper use of java.util.logging in JADE application

Hi Enrico,
Your suggestions fixed my problem.
Thank you.
Bye,
Dave


P.S.

I have another question related to logging. In the document http://jade.tilab.com/doc/tutorials/logging/JADELoggingService.html is the
statement below. It must be important to do this, but doesn't the
java.util.logging system already do that type of checking internally?





The usage of the following coding style is recommended in order to log a message with a certain level of importance:

if (logger.isLoggable(jade.util.Logger.myLevel))
logger.log(jade.util.Logger.myLevel, "this is the message to log");

where myLevel will be one of the levels allowed ( for instance jade.util.Logger.SEVERE). Notice that testing if the level is loggable before actually calling the log method allows relevant performance improvements.








-----Original Message-----
From: Scagliotti Enrico (Guest)
[mailto:enrico.scagliotti at guest.telecomitalia.it]
Sent: Friday, September 05, 2014 8:59 AM
To: Dave Welchons; jade-develop at avalon.tilab.com
Subject: R: [jade-develop] proper use of java.util.logging in JADE application

Hi,



Your code and logger configuration are correct.

I tried your implementation and it works well.

One possible problem is the path of the loaded configuration file, try with an absolute path, for example:
-Djava.util.logging.config.file=<absolute-path>/logging.properties



Then in logging.properties you must also specify the property java.util.logging.FileHandler.pattern=<filename> to specify the name of the log generic log file.



The final effect is that, when level is INFO, only generic log file is created; while, when level is FINE, two log files are created (one generic and one specific for agent).



Bye

Enrico



Da: jade-develop [mailto:jade-develop-bounces at avalon.tilab.com] Per conto di Dave Welchons
Inviato: giovedì 4 settembre 2014 23:33
A: jade-develop at avalon.tilab.com
Oggetto: [jade-develop] proper use of java.util.logging in JADE application



Dear jade-develop mailing list,

I initially placed many prints in my AlertAgent.java application. If I wanted to turn them off, I had to change the source code. So I thought I would use java.util.logging as described in the sentence "including application-specific logging messages" Section 3.7.5 (p. 46) of "Developing
Multi-Agent Systems With JADE". I wanted an output file specific to a
specific agent (i.e. multiple output files with one for each agent), and I read that java.util.logging does not allow that in the java.util.logging config file, so I attempted to add a FileHandler in my agent source code as shown below. I also passed in the argument "-Djava.util.logging.config.file=logging.properties" and I created the file
logging.properties as shown below, similar to p. 47 of the book. In the
config file I specified that the alert agent logging level should be "fine"
for its package com.brsc.masaide.alertagent. When I run my application I
only see the "info()" log statements, but I do not see the "fine()" log statements.

Can you see what I am doing wrong?

Thanks,

Dave Welchons



P.S. Maybe this is just a question for java.util.logging use and not related to JADE, and if so, I apologize for wasting your time







***************************

Selected source code statements in AlertAgent.java:

***************************



package com.brsc.masaide.alertagent;

.

public class AlertAgent extends Agent {



private Logger logger =
jade.util.Logger.getMyLogger(this.getClass().getName());



.





protected void setup()

{



// Create file logger if configuration file level high enough

if (logger.isLoggable(jade.util.Logger.FINE)) {

FileHandler fileHandler;

try {

fileHandler = new FileHandler("AlertAgent_Logger.txt");

} catch (SecurityException | IOException e) {

logger.severe(" AlertAgent.java: FileHandler exception = "+e.getLocalizedMessage());

e.printStackTrace();

return;

}

fileHandler.setFormatter(new SimpleFormatter());

fileHandler.setLevel(Level.FINE);

logger.addHandler(fileHandler);

}

// Note commented out below. Only see middle logger (logger.fine()) below if next line uncommented.

// Otherwise do not see middle log, implying that the default "info" is in effect.

// Config file setting of level to "fine" for this package "com.brsc.masaide.alertagent" does not seem to have an effect.

//logger.setLevel(Level.FINE);



// Print agent data

logger.info(" AlertAgent.java: setup(): my local-name is "+getAID().getLocalName());

logger.fine(" AlertAgent.java: setup(): my GUID is "+getAID().getName());

logger.info(" AlertAgent.java: setup(): my AID is: "+getAID());











***********************

Config file logging.properties:

***********************





# Set default log level to INFO, and then override for those packages that

# require more debug info

.level = INFO



# Add ConsoleHandler here for all classes.

# A unique FileHandler will be added in each module to provide different file

# for each module. If specified FileHandler here one file would be used

# for output of all modules (I think).

handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler



# Modify default level for all handlers which will be overridden below

# with each package level.

java.util.logging.ConsoleHandler.level = ALL

java.util.logging.FileHandler.level = ALL



# Set all handlers to simple (non-xml) format

java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter

java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter



# Set log level for my class of interest to FINE

com.brsc.masaide.alertagent.level = FINE



# Wild guess below since above didn't work, since I think I saw this below somewhere in JADE documentation

com_brsc_masaide_alertagent_loglevel = FINE





________________________________

Nessun virus nel messaggio.
Controllato da AVG - www.avg.com
Versione: 2014.0.4745 / Database dei virus: 4015/8144 - Data di rilascio:
02/09/2014



-----
Nessun virus nel messaggio.
Controllato da AVG - www.avg.com
Versione: 2014.0.4745 / Database dei virus: 4015/8144 - Data di rilascio: 02/09/2014
Loading...