• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

adding custom log levels to config file

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using java logging. I have coded a solution to create and use a custom log Level, but I don't see a way to add the custom log level to a configuration file. Any advice would be appreciated. thanks
 
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rick, welcome to CodeRanch.
I first edited lib/logging.properties to make .level= MY_LEVEL. My test program prints "true".

This implies that after you make a new instance of your subclass, the Level class will be able to return your custom Level instance using the parse() method.
 
rick smithaldo
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for you reply Stephan,

I've setup a test similar to yours but I keep getting the following error when I execute the test class
$ java -client -Djava.util.logging.config.file=./app.properties logtest
Bad level value for property: .level
logging

doesn't there have to be something in the config properties to Identify my custom level class ??

thanks again
Rick
 
Stephan van Hulst
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, in what way is your test different then?
 
rick smithaldo
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




handlers = java.util.logging.FileHandler

# The logging level for the root logger
.level = TESTLEVEL

java.util.logging.FileHandler.level = INFO
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.FileHandler.limit = 1000000
java.util.logging.FileHandler.count = 10
java.util.logging.FileHandler.pattern = ./test.log
java.util.logging.FileHandler.append = true


Ive also tried setting java.util.logging.FileHandler.level to my log custom level. neither work
 
Stephan van Hulst
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is probably because you are using the logging mechanism (by using Logger.getLogger()) before you use the TestLevel class, giving it no time to register the name through the superclass constructor.

Create your levels *before* you retrieve loggers.

It can be as simple as this:
 
rick smithaldo
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stephan, Thank you !! That worked. You da man !!
 
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic