LogService

LogService

LogService is deprecated

uPortal LogService is deprecated as of uPortal 2.4. Don't use it. Use Apache Commons Logging directly instead.

However, in uPortal < 2.4, logging to LogService remains an option, though of course there's nothing to prevent your using Commons Logging in uPortal < 2.4.

How to use LogService

Log like this:

// This will print the Exception message followed by a full stack trace.
 LogService.log(LogService.ERROR, e);

or

// It can be helpful to print out some variables values.
 // The stack trace is still printed as above because the Exception e is not 
 // concatenated to the message. Instead the whole excption is passed in.
 LogService.log(LogService.ERROR, "username: " + username, e);

Don't log like this, ever:

// No stack trace is printed. Only the text in the error message and the exception
 // class name are printed. This usually isn't enough to track down an Exception
 // and may even lie to you about the real cause.
 LogService.log(LogService.ERROR, "ERROR in MyClass.myMethod() " + e);

This is clearly a case where less is more. Another problem with this is methods get renamed and code gets cut and pasted into a different class. It is very common for these messages to not be in sync with the code. You won't be able to tell where the error is being printed from.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.