1 //
2 // Copyright (c) 2003-2005, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 // * Neither the name of the Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.
14 // nor the names of its contributors may be used to endorse or promote products
15 // derived from this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23 // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 // POSSIBILITY OF SUCH DAMAGE.
27 //
28 package org.objectledge.modules.actions.logging;
29
30 import org.apache.log4j.LogManager;
31 import org.apache.log4j.Logger;
32 import org.objectledge.context.Context;
33 import org.objectledge.parameters.RequestParameters;
34 import org.objectledge.pipeline.ProcessingException;
35 import org.objectledge.web.mvc.builders.PolicyProtectedAction;
36 import org.objectledge.web.mvc.security.PolicySystem;
37
38 /***
39 * Tests the logger settings by emmiting a message.
40 *
41 * @author <a href="mailto:rafal@caltha.pl">Rafal Krzewski</a>
42 * @version $Id: TestLogger.java,v 1.2 2005/05/20 04:19:01 rafal Exp $
43 */
44 public class TestLogger
45 extends PolicyProtectedAction
46 {
47
48 /***
49 * Creates new UpdateLogger instance.
50 *
51 * @param policySystem the PolicySystem component.
52 */
53 public TestLogger(PolicySystem policySystem)
54 {
55 super(policySystem);
56 }
57
58 /***
59 * {@inheritDoc}
60 */
61 public void process(Context context)
62 throws ProcessingException
63 {
64 RequestParameters requestParameters = RequestParameters.getRequestParameters(context);
65 String id = requestParameters.get("id");
66 Logger logger;
67 if(id.equals("root"))
68 {
69 logger = LogManager.getRootLogger();
70 }
71 else
72 {
73 if(LogManager.exists(id) == null)
74 {
75 throw new ProcessingException("invalid logger id "+id);
76 }
77 logger = LogManager.getLogger(id);
78 }
79 String level = requestParameters.get("level", "ERROR");
80 String message = requestParameters.get("message", "");
81
82 if("FATAL".equals(level))
83 {
84 logger.fatal(message);
85 }
86 if("ERROR".equals(level))
87 {
88 logger.error(message);
89 }
90 else if("WARN".equals(level))
91 {
92 logger.warn(message);
93 }
94 else if("INFO".equals(level))
95 {
96 logger.info(message);
97 }
98 else if("DEBUG".equals(level))
99 {
100 logger.debug(message);
101 }
102 }
103 }