<%@ page contentType="text/html;charset=utf-8"%>
<%@page import="ch.qos.logback.core.*"%>
<%@page import="ch.qos.logback.classic.*"%>
<%@page import="org.slf4j.*"%>
<%@page import="java.util.*"%>
<% 

	String loggerName = request.getParameter("loggerName");
	String slevel      = request.getParameter("level");
	LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();	
	if (loggerName != null && !"".equals(loggerName) && slevel != null && !"".equals(slevel)){
		Level level = Level.ERROR;
		if ("DEBUG".equals(slevel)){
			level = Level.DEBUG;
		}else if ("INFO".equals(slevel)){
			level = Level.INFO;
		}else if ("WARN".equals(slevel)){
			level = Level.WARN;
		}else if ("ERROR".equals(slevel)){
			level = Level.ERROR;
		}else if ("TRACE".equals(slevel)){
			level = Level.TRACE;
		}

		lc.getLogger(loggerName).setLevel(level);
%>
	<%=loggerName %> 의 로그 level이 <%=slevel %> 로 변경되었습니다.
<%
	}

	List<ch.qos.logback.classic.Logger> logs = lc.getLoggerList();;

%>
    <script type="text/javascript">
    function changeSessionKey(selectBox) {
        var loggerName = selectBox.title;
        var level = selectBox.value;
        document.frm.loggerName.value=loggerName;
        document.frm.level.value=level;
        document.frm.submit();
    }
</script>
<form name="frm" action="">
<input type=hidden name="loggerName" />
<input type=hidden name="level" />

</form>
<table>
<%
	ArrayList<String> al = new ArrayList<String>();
	for(ch.qos.logback.classic.Logger log : logs){
		if (log.getLevel() != null){
			al.add(log.getName());
		}
	}
	al.sort(null);
	for(String name : al){
		ch.qos.logback.classic.Logger l = lc.getLogger(name);
%>
<tr>
	<td><%=l.getName() %></td><td><select name="level" onchange="changeSessionKey(this)" title="<%=l.getName()%>">
				<option value=TRACE <%=Level.TRACE==l.getLevel()?"selected":"" %>>
					TRACE
				</option>
				<option value="DEBUG" <%=Level.DEBUG==l.getLevel()?"selected":"" %>>
					DEBUG
				</option>
				<option value="INFO" <%=Level.INFO==l.getLevel()?"selected":"" %>>
					INFO
				</option>
				<option value="WARN" <%=Level.WARN==l.getLevel()?"selected":"" %>>
					WARN
				</option>
				<option value="ERROR" <%=Level.ERROR==l.getLevel()?"selected":"" %>>
					ERROR
				</option>
			</select>
	</td>
</tr>	
<%
	} 
%>
</table>
