My assumption is wish to log events/activities - not debug stuff
This is not portable to other containers but you could do this. Declare
a common object name to go into your ServletRequest object ( like
event.login, event.logout) so when "things" occur you could have in your
code:
request.setAttribute("event.login", whatever);
Then create a valve similar to the AccessLogValve which will pluck out
items in the ServletRequest object and write them to file.
The tricky parts:
- defining log file format (columns defs, etc)
- what to call the stuff in the request object
- getting your developers to adhere to the conventions
- handling multivalue attributes and/or new attributes to log for
backwards compat.
All the above are pretty easy. For max flex (but pain in parsing) is to
treat the log like a query string so you could have as many attribtues
as you want on one line.
EX:
{date} {ip} foo=bar&name=fred&answer=42
To pick off the stuff left of the equals sign - you could say that is
the keys in the SerlvetRequest prefixed by "event." Then you could
iterate through the keys in SerlvetRequest object and look for anything
prefixed by "event." then write:
foo=fooValue where foo is part of "event.foo" and fooValue is the
attribute in the ServletRequest for "event.foo".
To handle multi-values - you could check if the value implements
java.util.List -then write out foo=bar&foo=bar2,...
Seems pretty easy, but then again I'm pulling this out of thin air after
thinking about it for 30 seconds.
Good luck.
-
Guillermo Payet wrote:
> Hi,
>
> I'd like to keep certain application logs as text files. Things like
> "search parameters used in a search form", or logs of "what users
> logged in or out and when".
>
> I'm wondering what's the simplest, most elegant, best performance way
> to do this. I was thinking about using Log4j for this, but it seems
> like overkill. Should I just create static PrintWriter(FileWriter),
> objects, and have my JSP pages and servlets write to those? Will this
> serialize writes effectively? Is there a better way?? Any ideas?
>
> thanks
>
> --G
>
>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>