A marine logger inside a servlet?

Is there a way to use Seam Logger inside a standard Java servlet? I have one servlet that I use to serve content while the rest of my application is being developed using Seam. I would like to be able to use the built-in Log In function in my servlet, just like for the rest of my Seam-based classes. In my servlet constructor, I tried calling

Log logger = (Log)Component.getInstance(Log.class); 

... but I get an exception. Is there a better way to β€œinsert” a registrar into a servlet? Is something missing? Thanks!!

+4
source share
2 answers

I have not tested it, but you can try the following:

 Log mylog = Logging.getLogger(MyClass.class); 

What I use in my tests.

+3
source

To use the seam context, you can wrap the doPost or doGet methods with ContextualHttpServletRequest , which allows you to search for components.

 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final HttpServletRequest req = request; new ContextualHttpServletRequest( req ) { public void process() throws Exception { wrappedPost( req ); } }.run(); } // you renamed original doPost method private void wrappedPost(HttpServletRequest request) { ... } 

The above code example allows you to access components by name, which are declared using name annotation:

 @Name("MyCcomponent") 

The logger is usually introduced by @Logger annotation, I checked the source package logs, there is no component with @Name annotation that could be found. If you call a component (using @Logger) from a wrapped context, a registrar is inserted into it (into the called componenttent).


The seam uses in its components:

 private static final LogProvider log = Logging .getLogProvider(MailSession.class); 
+2
source

All Articles