1 23 package com.sun.enterprise.server.logging; 24 25 import java.util.logging.ConsoleHandler ; 26 import java.util.logging.FileHandler ; 27 import java.util.logging.Handler ; 28 29 import com.sun.enterprise.config.ConfigContext; 30 import com.sun.enterprise.config.ConfigException; 31 import com.sun.enterprise.config.serverbeans.LogService; 32 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 33 import com.sun.enterprise.server.ApplicationServer; 34 import com.sun.enterprise.server.ServerContext; 35 import com.sun.enterprise.server.pluggable.LoggingSupport; 36 import com.sun.enterprise.util.StringUtils; 37 38 42 public class TomcatLoggingSupport implements LoggingSupport { 43 44 private static String defaultLogFileName = null; 45 private static String logFileName = null; 46 private static FileHandler fHandler = null; 47 48 51 public Handler createLogHandler() { 52 String fileName = getLogFileName(); 53 Handler h = null; 54 try { 55 if (fHandler == null) { 56 fHandler = new FileHandler (fileName, true); 57 } 58 } catch (Exception e) { 59 System.err.println("Error creating log handler for " + fileName 63 + ". Using ConsoleHandler -- " + e.getMessage()); 64 e.printStackTrace(); 65 h = new ConsoleHandler (); 66 return h; 67 } 68 69 h = fHandler; 70 return h; 71 } 72 73 78 private static String getLogFileName() { 79 if (logFileName == null) { 80 ServerContext sc = ApplicationServer.getServerContext(); 81 if (sc != null) { 82 ConfigContext ctx = sc.getConfigContext(); 83 LogService ls = null; 84 try { 85 ls = ServerBeansFactory.getConfigBean(ctx).getLogService(); 86 } catch (ConfigException ce) { 87 System.err.println("Error accessing log service config -- " 90 + ce.getMessage() + "\nUsing default file"); 91 ce.printStackTrace(); 92 } 93 if (ls != null) { 94 logFileName = ls.getFile(); 95 } 96 } 97 } 98 if (logFileName != null) { 99 return logFileName; 100 } else { 101 return getDefaultLogFileName(); 102 } 103 } 104 105 108 private static String getDefaultLogFileName() { 109 if (defaultLogFileName == null) { 110 ServerContext sc = ApplicationServer.getServerContext(); 111 String instDir; 112 if (sc != null) { 113 instDir = sc.getInstanceEnvironment().getInstancesRoot(); 114 } else { 115 instDir = System.getProperty("user.dir"); 117 } 118 String [] names = {instDir, LOGS_DIR, LOG_FILE}; 119 defaultLogFileName = StringUtils.makeFilePath(names, false); 120 } 121 return defaultLogFileName; 122 } 123 124 private static final String LOGS_DIR = "logs"; 125 private static final String LOG_FILE = "server.log"; 126 127 } 128 | Popular Tags |