Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZK-5703: Debug messages shouldn't be created if debug is disabled, ma… #3198

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions zcommon/src/main/java/org/zkoss/io/Serializables.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* Serializables.java

Purpose:

Description:

History:
Sun Jun 25 22:54:45 2006, Created by tomyeh

Expand Down Expand Up @@ -61,11 +61,15 @@ public static <K, V> void smartWrite(ObjectOutputStream s, Map<K, V> map)
s.writeObject(nm);
s.writeObject(val);
} catch (java.io.NotSerializableException ex) {
logio.error("Unable to serialize entry: "+nm+'='+val);
logio.error("Unable to serialize entry: {}={}", nm,
val);
throw ex;
}
} else if (nm != null && debug) {
logio.debug("Skip not-serializable entry: "+nm+'='+val);
if (logio.isDebugEnabled()) {
logio.debug("Skip not-serializable entry: {}={}", nm,
val);
}
}
}
}
Expand Down Expand Up @@ -101,11 +105,13 @@ public static <T> void smartWrite(ObjectOutputStream s, Collection<T> col)
try {
s.writeObject(val);
} catch (java.io.NotSerializableException ex) {
logio.error("Unable to serialize item: "+val);
logio.error("Unable to serialize item: {}", val);
throw ex;
}
} else if (val != null && debug) {
logio.debug("Skip not-serializable item: "+val);
if (logio.isDebugEnabled()) {
logio.debug("Skip not-serializable item: {}", val);
}
}
}
}
Expand Down Expand Up @@ -164,11 +170,13 @@ public static <T> void smartWrite(ObjectOutputStream s, T[] ary)
try {
s.writeObject(val);
} catch (java.io.NotSerializableException ex) {
logio.error("Unable to serialize item: "+val);
logio.error("Unable to serialize item: {}", val);
throw ex;
}
} else if (val != null && debug) {
logio.debug("Skip not-serializable item: "+val);
if (logio.isDebugEnabled()) {
logio.debug("Skip not-serializable item: {}", val);
}
}
}
}
Expand All @@ -182,8 +190,8 @@ public static void smartWrite(ObjectOutputStream s, Object val)
throws IOException {
final boolean bser = val instanceof java.io.Serializable
|| val instanceof java.io.Externalizable;
s.writeObject(bser ? val: null);
s.writeObject(bser ? val : null);
if (!bser && val != null && logio.isDebugEnabled())
logio.debug("Skip not-serializable object: "+val);
logio.debug("Skip not-serializable object: {}", val);
}
}
9 changes: 6 additions & 3 deletions zcommon/src/main/java/org/zkoss/lang/Exceptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


Purpose: Utilities for Exceptions
Description:
Description:
History:
2001/4/22, Tom M. Yeh: Created.

Expand Down Expand Up @@ -80,7 +80,8 @@ public static final Throwable getCause(Throwable ex) {
// return ((javax.servlet.jsp.el.ELException)ex).getRootCause();
}
} catch (Throwable e2) {
if (log.isDebugEnabled()) log.debug("Ignored: unable to resolve " + ex.getClass());
if (log.isDebugEnabled())
log.debug("Ignored: unable to resolve {}", ex.getClass());
}
return t;
}
Expand Down Expand Up @@ -301,7 +302,9 @@ else if (ex instanceof UndeclaredThrowableException)
if (t != null) ex = t;
}
} catch (Throwable e2) {
if (log.isDebugEnabled()) log.debug("Ignored: unable to resolve " + ex.getClass());
if (log.isDebugEnabled())
log.debug("Ignored: unable to resolve {}",
ex.getClass());
}
//Remove the dependence on EL
/* try {
Expand Down
5 changes: 3 additions & 2 deletions zcommon/src/main/java/org/zkoss/lang/Objects.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static final int hashCode(byte[] v) {
h = nextHashCode(h, v[j]);
return h;
}
/**
/**
* Generates hash codes for an array of bytes up to the specified length.
* It is suggested to cache the hash code.
*
Expand Down Expand Up @@ -413,7 +413,8 @@ public static final Object clone(Object o) {
try {
return kls.getMethod("clone").invoke(o);
} catch (NoSuchMethodException ex) {
if (log.isDebugEnabled()) log.debug("No clone() for "+kls);
if (log.isDebugEnabled())
log.debug("No clone() for {}", kls);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* ClassLocator.java

Purpose:

Description:

History:
Tue Aug 30 09:56:06 2005, Created by tomyeh

Expand Down Expand Up @@ -109,7 +109,7 @@ private static void resolveDependency(XMLResource xr,
List<Resource> rcs, Map<String, XMLResource> rcmap, Set<String> resolving, String elName) {
if (!resolving.add(xr.name))
throw new IllegalStateException("Recusrive reference among "+resolving);

checkCompDenpendency(xr, rcmap, elName);

for (String nm: xr.depends) {
Expand All @@ -121,7 +121,8 @@ private static void resolveDependency(XMLResource xr,
rcs.add(new Resource(xr.url, xr.document));
resolving.remove(xr.name);

if (log.isDebugEnabled()) log.debug("Adding resolved resource: "+xr.name);
if (log.isDebugEnabled())
log.debug("Adding resolved resource: {}", xr.name);
}

private static void checkCompDenpendency(XMLResource xr, Map<String, XMLResource> rcmap, String elName) {
Expand Down
10 changes: 5 additions & 5 deletions zcommon/src/main/java/org/zkoss/util/resource/Locators.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* Locators.java


Purpose:
Description:
Purpose:
Description:
History:
90/12/07 10:34:55, Create, Tom M. Yeh.

Expand Down Expand Up @@ -120,16 +120,16 @@ public String toString() {
locale = Locales.getCurrent();

final int jslash = file.lastIndexOf('/'); //>= -1
final int jdot =
final int jdot =
jslash >= 0 ? file.indexOf('.', jslash + 1): file.indexOf('.');
final String ext = jdot >= 0 ? file.substring(jdot): "";
final int jul = Locales.indexOfUnderline(file, jslash >= 0 ? jslash + 1: 0);
final String base = file.substring(0,
jul >= 0 && (jdot < 0 || jul < jdot) ? jul:
jdot >= 0 ? jdot: file.length());
jdot >= 0 ? jdot : file.length());

if (log.isDebugEnabled())
log.debug("svl=" + file + " base=" + base + " ext=" + ext);
log.debug("svl={} base={} ext={}", file, base, ext);

//search the existence based on locale
final int baseLen = base.length();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* LabelLoader.java

Purpose:

Description:

History:
Mon Jun 12 13:05:05 2006, Created by tomyeh

Expand Down Expand Up @@ -52,7 +52,7 @@
* Used to implement {@link org.zkoss.util.resource.Labels}.
*
* <p>Notice that the encoding of the Locale dependent file (*.properties)
* is assumed to be UTF-8. If it is not the case, please refer to
* is assumed to be UTF-8. If it is not the case, please refer to
* <a href="http://books.zkoss.org/wiki/ZK_Configuration_Reference/zk.xml/The_library-property_Element/Library_Properties#org.zkoss.util.label.web.charset">ZK Configuration Reference</a>
* for more information.
* <p> Specify the library property of <code>org.zkoss.util.resource.LabelLoader.class</code>
Expand Down Expand Up @@ -109,7 +109,9 @@ public Object filter(Object key, Object value) {
* @since 8.6.0
*/
protected Object handleMissingLabel(Object key) {
log.debug("The key of [{}] is not found in labels!", key);
if (log.isDebugEnabled()) {
log.debug("The key of [{}] is not found in labels!", key);
}
return null;
}

Expand Down Expand Up @@ -220,7 +222,7 @@ private final Map<String, ExValue> loadLabels(Locale locale) {
WaitLock lock = null;
for (;;) {
final Object o;
synchronized (_syncLabels) {
synchronized (_syncLabels) {
o = _syncLabels.get(locale);
if (o == null)
_syncLabels.put(locale, lock = new WaitLock()); //lock it
Expand Down
14 changes: 7 additions & 7 deletions zcommon/src/main/java/org/zkoss/xel/fn/CommonFns.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* CommonFns.java

Purpose:

Description:

History:
Wed Apr 20 18:35:21 2005, Created by tomyeh

Expand Down Expand Up @@ -119,16 +119,16 @@ public static final String getLabel(String key) {
try {
final Class cls = Classes.forNameByThread(clsnm);
final Field fld = cls.getField(fldnm);
return Messages.get(((Integer)fld.get(null)).intValue());
return Messages.get(((Integer) fld.get(null)).intValue());
} catch (ClassNotFoundException ex) {
log.warn("Class not found: "+clsnm, ex);
log.warn("Class not found: {}", clsnm, ex);
} catch (NoSuchFieldException ex) {
log.warn("Field not found: "+fldnm, ex);
log.warn("Field not found: {}", fldnm, ex);
} catch (IllegalAccessException ex) {
log.warn("Field not accessible: "+fldnm, ex);
log.warn("Field not accessible: {}", fldnm, ex);
}
} else if (log.isDebugEnabled()) {
log.debug("Not a valid format: "+key);
log.debug("Not a valid format: {}", key);
}
}
return Labels.getLabel(key);
Expand Down
6 changes: 3 additions & 3 deletions zcommon/src/main/java/org/zkoss/xel/taglib/Taglibs.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* Taglibs.java

Purpose:

Description:

History:
Fri Aug 10 16:42:37 2007, Created by tomyeh

Expand Down Expand Up @@ -330,7 +330,7 @@ private static final Map<String, URL> getDefaultTLDs() {
if (IDOMs.checkVersion(res.document, res.url))
parseConfig(urls, res.document.getRootElement(), loc);
} catch (Exception ex) {
log.error("Failed to parse "+ res.url, ex); //keep running
log.error("Failed to parse {}", res.url, ex); //keep running
}
}
} catch (Exception ex) {
Expand Down
33 changes: 18 additions & 15 deletions zcommon/src/main/java/org/zkoss/xel/util/Evaluators.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* Evaluators.java

Purpose:

Description:

History:
Fri Sep 14 12:24:23 2007, Created by tomyeh

Expand All @@ -16,28 +16,29 @@
*/
package org.zkoss.xel.util;

import static org.zkoss.lang.Generics.cast;

import java.net.URL;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
import java.util.Enumeration;
import java.net.URL;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zkoss.lang.Classes;
import static org.zkoss.lang.Generics.cast;
import org.zkoss.lang.SystemException;

import org.zkoss.util.resource.Locator;
import org.zkoss.util.resource.ClassLocator;
import org.zkoss.idom.input.SAXBuilder;
import org.zkoss.idom.Document;
import org.zkoss.idom.Element;
import org.zkoss.idom.input.SAXBuilder;
import org.zkoss.idom.util.IDOMs;
import org.zkoss.xel.XelContext;
import org.zkoss.lang.Classes;
import org.zkoss.lang.SystemException;
import org.zkoss.util.resource.ClassLocator;
import org.zkoss.util.resource.Locator;
import org.zkoss.xel.ExpressionFactory;
import org.zkoss.xel.VariableResolver;
import org.zkoss.xel.VariableResolverX;
import org.zkoss.xel.XelContext;

/**
* It maps a name with an evaluator implementation.
Expand Down Expand Up @@ -118,7 +119,8 @@ public static final String add(String name, String evalcls) {
|| evalcls == null || evalcls.length() == 0)
throw new IllegalArgumentException("emty or null");

if (log.isDebugEnabled()) log.debug("Evaluator is added: "+name+", "+evalcls);
if (log.isDebugEnabled())
log.debug("Evaluator is added: {}, {}", name, evalcls);

final String evalnm = name.toLowerCase(java.util.Locale.ENGLISH);
final Object old;
Expand Down Expand Up @@ -162,8 +164,9 @@ synchronized static final void load() {
final ClassLocator loc = new ClassLocator();
for (Enumeration en = loc.getResources("metainfo/xel/config.xml");
en.hasMoreElements();) {
final URL url = (URL)en.nextElement();
if (log.isDebugEnabled()) log.debug("Loading "+url);
final URL url = (URL) en.nextElement();
if (log.isDebugEnabled())
log.debug("Loading {}", url);
try {
final Document doc = new SAXBuilder(false, false, true).build(url);
if (IDOMs.checkVersion(doc, url))
Expand Down
10 changes: 6 additions & 4 deletions zk/src/main/java/org/zkoss/zk/au/http/AuDynaMediar.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* AuDynaMediar.java

Purpose:

Description:

History:
Fri Jan 11 19:14:17 2008, Created by tomyeh

Expand Down Expand Up @@ -53,7 +53,7 @@

/**
* The AU processor used to response the content for {@link DynamicMedia#getMedia}
*
*
* @author tomyeh
* @since 3.0.2
*/
Expand Down Expand Up @@ -128,7 +128,9 @@ public void service(HttpServletRequest request, HttpServletResponse response, St
if (comp == null) { // B65-ZK-1599
response.sendError(HttpServletResponse.SC_GONE,
Messages.get(MZk.PAGE_NOT_FOUND, pi + " - " + uuid));
log.debug("Failed to load media, " + pi);
if (log.isDebugEnabled()) {
log.debug("Failed to load media, {}", pi);
}
return;
}
final Object cc = ((ComponentCtrl) comp).getExtraCtrl();
Expand Down
Loading
Loading