001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.exp; 020 021import java.io.PrintWriter; 022 023import lucee.commons.io.log.Log; 024import lucee.commons.io.log.LogUtil; 025import lucee.runtime.PageContext; 026import lucee.runtime.config.Config; 027import lucee.runtime.config.ConfigImpl; 028import lucee.runtime.engine.ThreadLocalPageContext; 029import lucee.runtime.op.Caster; 030 031/** 032 * Handle Excpetions 033 */ 034public final class ExceptionHandler { 035 036 public static void log(Config config, Throwable t) { 037 038 PageException pe=Caster.toPageException(t); 039 //pe.printStackTrace(config.getErrWriter()); 040 041 // apllication Log 042 //LogUtil.log(((ConfigImpl)config).getLog("application"),Log.LEVEL_ERROR, "",pe); 043 044 // exception.log 045 //String st = ExceptionUtil.getStacktrace(pe,true); 046 LogUtil.log(((ConfigImpl)config).getLog("exception"),Log.LEVEL_ERROR, "",pe); 047 048 049 } 050 051 public static void printStackTrace(PageContext pc, Throwable t) { 052 PrintWriter pw = (pc.getConfig()).getErrWriter(); 053 t.printStackTrace(pw); 054 pw.flush(); 055 } 056 057 public static void printStackTrace(Throwable t) { 058 PageContext pc = ThreadLocalPageContext.get(); 059 if(pc!=null)printStackTrace(pc,t); 060 else t.printStackTrace(); 061 } 062}