0

I want to do some simple logging, what am I missing here?

I just want to log it as simple as possible (for now). This code seems to work, but not on the web service!

@WebMethod(operationName = "xyz")
public boolean xyz(@WebParam(name = "entityID") final int entityID throws IOException {

    FileHandler fh = new FileHandler("SISlog.txt", true);
    fh.setFormatter(new SimpleFormatter());
    fh.setLevel(Level.FINEST);

    Logger rootLogger = Logger.getLogger("");
    rootLogger.addHandler(fh);
    rootLogger.setLevel(Level.FINEST);

    rootLogger.log(Level.SEVERE, "auiuuuuuuuuuuuuuuuuu");

    return true;
}
Belial
  • 1
  • 1
  • Try using Logger specific to your class as `private static final Logger logger = Logger.getLogger(YourClass.class.getName());` – ring bearer Apr 07 '12 at 21:23
  • I did that at first and got the same result! – Belial Apr 07 '12 at 21:29
  • There is something wired in your prototype can you fix it? And what is the problem on the web service exactly? The file is not created, nothing is written? or ?? – alain.janinm Apr 08 '12 at 09:23
  • Ok, and have you got an error in your server log? Maybe you have not enough permission to write a file. Check if it throws the IOException. – alain.janinm Apr 10 '12 at 09:16

2 Answers2

0

Try to put in the getLogger the name of the super class of your class that uses the logger

GingerHead
  • 8,130
  • 15
  • 59
  • 93
0

You cannot rely on relative paths running inside a webcontainer. Try with an absolute path - like /tmp/SISlog.txt.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347