1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.logging.log4j.taglib;
18
19 import javax.servlet.jsp.JspException;
20 import javax.servlet.jsp.tagext.Tag;
21
22 import org.apache.logging.log4j.Level;
23
24
25
26
27
28
29 public class CatchingTag extends ExceptionAwareTagSupport {
30 private static final long serialVersionUID = 1L;
31
32 private static final String FQCN = CatchingTag.class.getName();
33
34 private Level level;
35
36 @Override
37 protected void init() {
38 super.init();
39 this.level = null;
40 }
41
42 public void setLevel(final Object level) {
43 this.level = TagUtils.resolveLevel(level);
44 }
45
46 @Override
47 public int doEndTag() throws JspException {
48 final Log4jTaglibLogger logger = this.getLogger();
49
50 if (this.level == null) {
51 logger.catching(FQCN, Level.ERROR, this.getException());
52 } else {
53 logger.catching(FQCN, this.level, this.getException());
54 }
55
56 return Tag.EVAL_PAGE;
57 }
58 }