Skip to content

Commit 0b44965

Browse files
committed
Updated to using a better DeferredMangoLogger
1 parent 3a9ec71 commit 0b44965

2 files changed

Lines changed: 17 additions & 16 deletions

File tree

src/main/java/org/mangorage/bootstrap/Bootstrap.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.mangorage.bootstrap.api.launch.ILaunchTarget;
44
import org.mangorage.bootstrap.api.logging.IDeferredMangoLogger;
55
import org.mangorage.bootstrap.api.logging.ILoggerFactory;
6-
import org.mangorage.bootstrap.api.logging.IMangoLogger;
76
import org.mangorage.bootstrap.internal.logger.DefaultLoggerFactory;
87
import org.mangorage.bootstrap.internal.util.Util;
98

@@ -35,7 +34,7 @@
3534
*/
3635
public final class Bootstrap {
3736

38-
private static final IDeferredMangoLogger LOGGER = ILoggerFactory.getDefault().getWrappedProvider("slf4j");
37+
private static final IDeferredMangoLogger LOGGER = ILoggerFactory.getDefault().getWrappedProvider("slf4j", Bootstrap.class);
3938
private static final String LAUNCH_TARGET_ARG = "--launchTarget";
4039
private static final String DEFAULT_LAUNCH_PATH = "launch";
4140

@@ -47,14 +46,14 @@ public final class Bootstrap {
4746
* @throws IllegalStateException if launch target cannot be found or executed
4847
*/
4948
public static void main(String[] args) throws Throwable {
50-
LOGGER.info("Starting MangoBotBootstrap framework");
49+
LOGGER.get().info("Starting MangoBotBootstrap framework");
5150

5251
validateArguments(args);
5352

5453
final String launchTarget = args[1];
5554
validateLaunchTarget(launchTarget);
5655

57-
LOGGER.info("Initializing module layers for launch target: " + launchTarget);
56+
LOGGER.get().info("Initializing module layers for launch target: " + launchTarget);
5857

5958
ModuleLayer parent = getParentModuleLayer();
6059
Path launchPath = Path.of(DEFAULT_LAUNCH_PATH);
@@ -71,14 +70,14 @@ public static void main(String[] args) throws Throwable {
7170
launchTarget, launchTargetMap.keySet()));
7271
}
7372

74-
LOGGER.info("Loading BootstrapLifecycle hooks");
73+
LOGGER.get().info("Loading BootstrapLifecycle hooks");
7574

7675
final var lifecycleHooks = ServiceLoader.load(moduleLayer, org.mangorage.bootstrap.api.lifecycle.IBootstrapLifecycle.class)
7776
.stream()
7877
.map(ServiceLoader.Provider::get)
7978
.toList();
8079

81-
LOGGER.info("Launching target: " + launchTarget);
80+
LOGGER.get().info("Launching target: " + launchTarget);
8281

8382
try {
8483
final var target = launchTargetMap.get(launchTarget);
@@ -88,12 +87,12 @@ public static void main(String[] args) throws Throwable {
8887
target.launch(launchLayer, args);
8988
}
9089
} catch (Throwable t) {
91-
LOGGER.error("Error during launch target execution: " + launchTarget, t);
90+
LOGGER.get().error("Error during launch target execution: " + launchTarget, t);
9291
lifecycleHooks.forEach(hook -> hook.onError(t, moduleLayer));
9392
throw t;
9493
}
9594

96-
LOGGER.info("Bootstrap completed successfully");
95+
LOGGER.get().info("Bootstrap completed successfully");
9796
}
9897

9998
/**
@@ -156,11 +155,11 @@ private static ModuleLayer createLaunchModuleLayer(ModuleLayer parent, Path laun
156155
Thread.currentThread().getContextClassLoader()
157156
);
158157

159-
LOGGER.info("Successfully created module layer with " + moduleCfg.modules().size() + " modules");
158+
LOGGER.get().info("Successfully created module layer with " + moduleCfg.modules().size() + " modules");
160159
return moduleLayerController.layer();
161160

162161
} catch (Exception e) {
163-
LOGGER.error("Failed to create module layer from path: " + launchPath, e);
162+
LOGGER.get().error("Failed to create module layer from path: " + launchPath, e);
164163
throw new IllegalStateException("Module layer creation failed", e);
165164
}
166165
}
@@ -180,29 +179,29 @@ private static Map<String, ILaunchTarget> discoverLaunchTargets(ModuleLayer modu
180179
final String targetId = target.getId();
181180

182181
if (targetId == null || targetId.trim().isEmpty()) {
183-
LOGGER.info("Ignoring launch target with null or empty ID from provider: " + provider.type());
182+
LOGGER.get().info("Ignoring launch target with null or empty ID from provider: " + provider.type());
184183
return;
185184
}
186185

187186
if (launchTargetMap.containsKey(targetId)) {
188-
LOGGER.info("Duplicate launch target ID detected: " + targetId + ". Using first occurrence.");
187+
LOGGER.get().info("Duplicate launch target ID detected: " + targetId + ". Using first occurrence.");
189188
return;
190189
}
191190

192191
launchTargetMap.put(targetId, target);
193-
LOGGER.info("Discovered launch target: " + targetId + " (" + provider.type() + ")");
192+
LOGGER.get().info("Discovered launch target: " + targetId + " (" + provider.type() + ")");
194193

195194
} catch (Exception e) {
196-
LOGGER.warn("Failed to load launch target provider: " + provider.type(), e);
195+
LOGGER.get().warn("Failed to load launch target provider: " + provider.type(), e);
197196
}
198197
});
199198

200199
} catch (Exception e) {
201-
LOGGER.error("Failed to discover launch targets", e);
200+
LOGGER.get().error("Failed to discover launch targets", e);
202201
throw new IllegalStateException("Launch target discovery failed", e);
203202
}
204203

205-
LOGGER.info("Discovered " + launchTargetMap.size() + " launch targets: " + launchTargetMap.keySet());
204+
LOGGER.get().info("Discovered " + launchTargetMap.size() + " launch targets: " + launchTargetMap.keySet());
206205
return launchTargetMap;
207206
}
208207
}

src/main/java/org/mangorage/bootstrap/internal/logger/DeferredMangoLogger.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public IMangoLogger get() {
2929
if (logger != null) return logger;
3030
}
3131
}
32+
} else {
33+
return logger;
3234
}
3335
return loggerFunction.apply(ILoggerFactory.getDefault().getProvider("default"));
3436
}

0 commit comments

Comments
 (0)