1 2 24 package com.sun.enterprise.server.logging; 25 26 27 28 import java.io.IOException ; 29 import java.io.File ; 30 31 import java.util.Enumeration ; 32 import java.util.logging.Logger ; 33 import java.util.logging.LogManager ; 34 import java.util.logging.Level ; 35 import java.util.logging.Handler ; 36 import java.util.logging.FileHandler ; 37 import java.util.logging.SimpleFormatter ; 38 39 import com.sun.enterprise.config.ConfigContext; 40 import com.sun.enterprise.config.ConfigException; 41 import com.sun.enterprise.config.ConfigFactory; 42 import com.sun.enterprise.config.clientbeans.ClientContainer; 43 import com.sun.enterprise.config.clientbeans.ClientBeansFactory; 44 45 import com.sun.logging.LogDomains; 46 47 53 public class ACCLogManager extends BaseLogManager { 54 55 private final String CLIENT_XML_FULL_NAME = 58 "com.sun.enterprise.appclient.ClientContainer"; 59 private final String DEFAULT_CLIENT_CONTAINER_XML = "sun-acc.xml"; 60 61 private Handler _clientHandler = null; 62 private Level _logLevel = Level.INFO; 63 64 private boolean initialized = false; 65 66 public ACCLogManager() { 67 super(); 68 } 69 70 synchronized public void init(String configFile) { 73 74 if (initialized) return; 75 initialized = true; 76 77 try { 78 ConfigContext ctx = 79 ConfigFactory.createConfigContext 80 (configFile, true, false, false, 81 com.sun.enterprise.config.clientbeans.ClientContainer.class, 82 new com.sun.enterprise.config.clientbeans.ClientBeansResolver()); 83 final ClientContainer cc = 84 ClientBeansFactory.getClientBean(ctx); 85 86 String logLevel = cc.getLogService().getLevel(); 87 if (logLevel != null && !logLevel.equals("")) { 88 _logLevel = Level.parse(logLevel); 89 } 90 91 String logFileName = cc.getLogService().getFile(); 92 if (logFileName != null && !logFileName.equals("")) { 93 _clientHandler = new FileHandler (logFileName, true); 94 _clientHandler.setFormatter(new SimpleFormatter ()); 95 96 File lockFile = new File (logFileName + ".lck"); 98 lockFile.deleteOnExit(); 99 } 100 101 } catch (Exception ex) { 102 if (_logger != null) { 103 _logger.logrb(Level.SEVERE, null, null, 104 "com.sun.logging.enterprise.system.container.appclient.LogStrings", 105 "acc.cannot_create_log_handler", ex); 106 } 107 } 108 109 Enumeration e = getLoggerNames(); 113 while (e.hasMoreElements()) { 114 String loggerName = (String ) e.nextElement(); 115 Logger l = getLogger(loggerName); 116 initializeLogger(l); 117 } 118 } 119 120 121 synchronized protected void initializeLogger(final Logger l) { 122 java.security.AccessController.doPrivileged( 123 new java.security.PrivilegedAction () { 124 public Object run() { 125 126 l.setLevel(_logLevel); 127 128 if (_clientHandler != null) { 130 Handler [] h = l.getHandlers(); 132 for (int i = 0; i < h.length; i++) { 133 l.removeHandler(h[i]); 134 } 135 136 l.setUseParentHandlers(false); 137 138 l.addHandler(_clientHandler); 143 } 144 return null; 145 } 146 } 147 ); 148 } 149 } 150 | Popular Tags |