Skip to content

Commit

Permalink
improve POM loading and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Nov 1, 2024
1 parent 770bb1a commit 922b74c
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 13 deletions.
43 changes: 40 additions & 3 deletions core/src/main/java/lucee/commons/io/log/LogUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,36 @@ public static void log(Config config, int level, String type, String msg) {

//////////
public static void log(String type, Throwable t) {
log("application", type, t);
log((Config) null, type, t, Log.LEVEL_ERROR, "application");
}

public static void log(int level, String type, Throwable t) {
log((Config) null, type, t, level, "application");
}

public static void log(PageContext pc, String type, Throwable t) {
log(pc, "application", type, t);
}

public static void log(Config config, String type, Throwable t) {
log(config, "application", type, t, Log.LEVEL_ERROR);
log(config, type, t, Log.LEVEL_ERROR, "application");
}

//////////
public static void log(String logName, String type, Throwable t) {
log(logName, type, t, Log.LEVEL_ERROR);
log((Config) null, type, t, Log.LEVEL_ERROR, logName);
}

public static void log(String type, Throwable t, String... logNames) {
log((Config) null, type, t, Log.LEVEL_ERROR, logNames);
}

public static void log(PageContext pc, String logName, String type, Throwable t) {
log(pc, logName, type, t, Log.LEVEL_ERROR);
}

//////////
@Deprecated
public static void log(String logName, String type, Throwable t, int logLevel) {
Log log = ThreadLocalPageContext.getLog(logName);
if (log != null) {
Expand All @@ -126,6 +135,7 @@ public static void log(String logName, String type, Throwable t, int logLevel) {
else logGlobal(ThreadLocalPageContext.getConfig(), logLevel, type, ExceptionUtil.getStacktrace(t, true));
}

@Deprecated
public static void log(Config config, String logName, String type, Throwable t, int logLevel) {
Log log = ThreadLocalPageContext.getLog(config, logName);
if (log != null) {
Expand All @@ -135,6 +145,20 @@ public static void log(Config config, String logName, String type, Throwable t,
else logGlobal(config, logLevel, type, ExceptionUtil.getStacktrace(t, true));
}

public static void log(Config config, String type, Throwable t, int logLevel, String... logNames) {
Log log = null;
for (String ln: logNames) {
log = ThreadLocalPageContext.getLog(config, ln);
if (log != null) break;
}

if (log != null) {
if (Log.LEVEL_ERROR == logLevel) log.error(type, t);
else log.log(logLevel, type, t);
}
else logGlobal(ThreadLocalPageContext.getConfig(config), logLevel, type, ExceptionUtil.getStacktrace(t, true));
}

public static void log(PageContext pc, String logName, String type, Throwable t, int logLevel) {
Log log = ThreadLocalPageContext.getLog(pc, logName);
if (log != null) {
Expand All @@ -153,6 +177,19 @@ public static void log(int level, String logName, String type, String msg) {
}
}

public static void logx(Config config, int level, String type, String msg, String... logNames) {
Log log = null;
for (String ln: logNames) {
log = ThreadLocalPageContext.getLog(config, ln);
if (log != null) break;
}

if (log != null) log.log(level, type, msg);
else {
logGlobal(ThreadLocalPageContext.getConfig(config), level, logNames[0] + ":" + type, msg);
}
}

public static void log(Config config, int level, String logName, String type, String msg) {
Log log = ThreadLocalPageContext.getLog(config, logName);
if (log != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ public boolean validateObject(PooledObject<DatasourceConnection> p) {
if (dc.getConnection().isClosed()) return false;
}
catch (Exception e) {
LogUtil.log(config, logName, "connection", e, Log.LEVEL_ERROR);
LogUtil.log(config, "connection", e, Log.LEVEL_ERROR, logName);
return false;
}

try {
if (dc.getDatasource().validate() && !DataSourceUtil.isValid(dc, 1000)) return false;
}
catch (Exception e) {
LogUtil.log(config, logName, "connection", e, Log.LEVEL_ERROR);
LogUtil.log(config, "connection", e, Log.LEVEL_ERROR, logName);
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/lucee/runtime/dump/DumpUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ public int compare(Method m1, Method m2) {

// parameters
StringBuilder sbParams = new StringBuilder(method.getName());
sbParams.append(" (");
sbParams.append("(");
Class[] parameters = method.getArgumentClasses();
for (int p = 0; p < parameters.length; p++) {
if (p > 0) sbParams.append(", ");
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/lucee/runtime/engine/CFMLEngineImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ private void addEventListener(ServletContext sc) {
catch (Exception e) {
// because this is optional and not all servlet engine do support this, we keep the log level on
// info
LogUtil.log(configServer, "application", "add-event-listener", e, Log.LEVEL_INFO);
LogUtil.log(configServer, "add-event-listener", e, Log.LEVEL_INFO, "application");
}

}
Expand All @@ -796,7 +796,7 @@ private void addEventListener(ServletContext sc) {
catch (Exception e) {
// because this is optional and not all servlet engine do support this, we keep the log level on
// info
LogUtil.log(configServer, "application", "add-event-listener", e, Log.LEVEL_INFO);
LogUtil.log(configServer, "add-event-listener", e, Log.LEVEL_INFO, "application");
}
}

Expand Down Expand Up @@ -1167,7 +1167,7 @@ else if (ended > -1 && ended + 10000 <= System.currentTimeMillis()) {
catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
if (t instanceof Exception && !Abort.isSilentAbort(t))
LogUtil.log(configServer, "application", "controller", t, t instanceof MissingIncludeException ? Log.LEVEL_WARN : Log.LEVEL_ERROR);
LogUtil.log(configServer, "controller", t, t instanceof MissingIncludeException ? Log.LEVEL_WARN : Log.LEVEL_ERROR, "application");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/lucee/runtime/exp/ExceptionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public final class ExceptionHandler {
public static void log(Config config, Throwable t) {
PageException pe = Caster.toPageException(t);
int ll = t instanceof MissingIncludeException ? Log.LEVEL_WARN : Log.LEVEL_ERROR;
LogUtil.log(config, "exception", "", t, ll);
LogUtil.log(config, "", t, ll, "exception");
}

public static void printStackTrace(PageContext pc, Throwable t) {
Expand Down
10 changes: 9 additions & 1 deletion core/src/main/java/lucee/runtime/mvn/MavenUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import lucee.commons.io.IOUtil;
import lucee.commons.io.log.Log;
import lucee.commons.io.log.LogUtil;
import lucee.commons.io.res.Resource;
import lucee.commons.io.res.util.ResourceUtil;
import lucee.commons.lang.ExceptionUtil;
Expand Down Expand Up @@ -183,6 +184,7 @@ public static GAVSO getDependency(POMReader.Dependency rd, POM parent, POM curre
throw new IOException("could not find version for dependency [" + g + ":" + a + "] in [" + current + "]");
}
}

v = resolvePlaceholders(current, v, properties);
// PATCH TODO better solution for this
if (v != null && v.startsWith("[")) {
Expand Down Expand Up @@ -258,7 +260,13 @@ public static List<POM> getDependencyManagement(List<POMReader.Dependency> rawDe

if (rawDependencies != null) {
for (Dependency rd: rawDependencies) {
GAVSO gavso = getDependency(rd, parent, current, properties, null, true);
GAVSO gavso = null;
try {
gavso = getDependency(rd, parent, current, properties, null, true);
}
catch (IOException ioe) {
LogUtil.log(null, "mvn", ioe, Log.LEVEL_WARN, "application");
}
if (gavso == null) continue;
POM p = POM.getInstance(localDirectory, current.getRepositories(), gavso.g, gavso.a, gavso.v, gavso.s, gavso.o, current.getDependencyScope(),
current.getDependencyScopeManagement(), log);
Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="6.2.0.147-SNAPSHOT"/>
<property name="version" value="6.2.0.148-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>6.2.0.147-SNAPSHOT</version>
<version>6.2.0.148-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit 922b74c

Please sign in to comment.