Friday, December 21, 2012

Log to Weblogic logs files from your code. | Weblogic - Java programming: Tips



This is an attempt to gather some of the things I have struggled with initially so I decided to blog some tips and tricks so I can come back to them and others can benefit too:

  • Easy Log from your component: 
There are various ways to implement logging, but the simplest way is to log using "System.out.println" and "System.err.println". These are not good long term and production ready way to achieve this, but this blog is for getting your feet wet in this area, and this should suffice, allowing one to concentrate on the main task at hand. Please come back and re-factor to fix this later.
So to ensure that your logs are recognized by weblogic and saved in the appropriate files, you will have to turn on this feature. Go to Console (url:port/console, login, (left panel)/Environment/(right panel)Servers > AdminServer > Logging -> General (open advanced)
Home >Summary of Environment >Summary of Servers >AdminServer > Logging … advanced
And check “Redirect stdout logging enabled” & “Redirect stderr logging enabled”.
Bow you can simply write commands like
System.out.println(“Message”);
AND
System.err.println(“error”)
I would suggest that you create a new class called
customMessageHandler, and expose two static functions
logMessage(String msg) and logErr(String err) and call these in these functions. This way when you come back to re-factor, you can make your changes in one location.



Sachin
BuzzClan LLC

What is Zero Trust Architecture?