IDEMPIERE-665 Server: setting logging level have no effect.

This commit is contained in:
Heng Sin Low 2013-02-27 07:58:08 +08:00
parent 002c3c474d
commit 184f457783
2 changed files with 70 additions and 13 deletions

View File

@ -61,6 +61,7 @@ public class CLogFile extends Handler
private String m_fileNameDate = "";
/** Record Counter */
private int m_records = 0;
private File m_previousFile;
/**
* Initialize
@ -202,6 +203,25 @@ public class CLogFile extends Handler
initialize(m_idempiereHome, true, Ini.isClient());
} // rotateLog
public void reopen()
{
if (m_previousFile != null && m_previousFile.exists() && m_file == null && m_writer == null)
{
try
{
m_file = m_previousFile;
m_writer = new FileWriter (m_file, true);
m_records = 0;
}
catch (Exception ex)
{
reportError ("writer", ex, ErrorManager.OPEN_FAILURE);
m_writer = null;
m_file = null;
}
}
}
/**
* Get File Name
* @return file name
@ -337,6 +357,7 @@ public class CLogFile extends Handler
reportError ("close", ex, ErrorManager.CLOSE_FAILURE);
}
m_writer = null;
m_previousFile = m_file;
m_file = null;
} // close

View File

@ -16,6 +16,8 @@
*****************************************************************************/
package org.compiere.util;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.PrintWriter;
@ -25,8 +27,10 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
@ -52,15 +56,43 @@ import org.idempiere.distributed.IClusterService;
*/
public class CLogMgt
{
private static final CLogConsole CONSOLE_HANDLER = new CLogConsole();
private static final CLogErrorBuffer ERROR_BUFFER_HANDLER = new CLogErrorBuffer();
private static CLogFile fileHandler;
private static final Map<String, Level> levelMap = new HashMap<String, Level>();
private final static PropertyChangeListener listener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName() == null) {
reInit();
}
}
};
private static synchronized void reInit() {
CLogMgt.initialize(Ini.isClient());
if (!levelMap.isEmpty()) {
for(String key : levelMap.keySet()) {
setLevel(key, levelMap.get(key));
}
}
if (fileHandler != null) {
fileHandler.reopen();
}
}
/**
* Initialize Logging
* @param isClient client
*/
public static void initialize(boolean isClient)
{
if (isClient)
public static synchronized void initialize(boolean isClient)
{
LogManager mgr = LogManager.getLogManager();
if (isClient)
{
try
{ // Load Logging config from org.compiere.util.*properties
String fileName = "logClient.properties";
@ -147,21 +179,22 @@ public class CLogMgt
}
// Check Loggers
if (!handlerNames.contains(CLogErrorBuffer.class.getName()))
addHandler(new CLogErrorBuffer());
addHandler(ERROR_BUFFER_HANDLER);
if (isClient && !handlerNames.contains(CLogConsole.class.getName()))
addHandler(new CLogConsole());
addHandler(CONSOLE_HANDLER);
if (!handlerNames.contains(CLogFile.class.getName()))
{
Handler fh = new CLogFile(null, true, isClient);
addHandler(fh);
if (fileHandler == null)
fileHandler = new CLogFile(null, true, isClient);
addHandler(fileHandler);
}
setFormatter(CLogFormatter.get());
setFilter(CLogFilter.get());
// setLevel(s_currentLevel);
// setLoggerLevel(Level.ALL, null);
//
// System.out.println("Handlers=" + s_handlers.size() + ", Level=" + s_currentLevel);
mgr.removePropertyChangeListener(listener);
mgr.addPropertyChangeListener(listener);
} // initialize
@ -267,7 +300,7 @@ public class CLogMgt
* Set Level for all handlers
* @param level log level
*/
public static void setLevel (String loggerName, Level level)
public static synchronized void setLevel (String loggerName, Level level)
{
if (level == null)
return;
@ -293,6 +326,9 @@ public class CLogMgt
logger.setUseParentHandlers(true);
}
}
String key = loggerName == null ? "" : loggerName;
if (!levelMap.containsKey(key))
levelMap.put(key, level);
} // setHandlerLevel
/**