001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache license, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the license for the specific language governing permissions and
015 * limitations under the license.
016 */
017package org.apache.logging.log4j.taglib;
018
019import javax.servlet.jsp.JspException;
020import javax.servlet.jsp.tagext.Tag;
021
022import org.apache.logging.log4j.Level;
023
024/**
025 * This class implements the {@code <log:exit>} tag.
026 *
027 * @since 2.0
028 */
029public class ExitTag extends LoggerAwareTagSupport {
030    private static final long serialVersionUID = 1L;
031
032    private static final String FQCN = ExitTag.class.getName();
033
034    private transient Object result;
035
036    @Override
037    protected void init() {
038        super.init();
039        this.result = null;
040    }
041
042    public void setResult(final Object result) {
043        this.result = result;
044    }
045
046    @Override
047    public int doEndTag() throws JspException {
048        final Log4jTaglibLogger logger = this.getLogger();
049
050        if (TagUtils.isEnabled(logger, Level.TRACE, null)) {
051            if (this.result == null) {
052                logger.exit(FQCN, null);
053            } else {
054                logger.exit(FQCN, this.result);
055            }
056        }
057
058        return Tag.EVAL_PAGE;
059    }
060}