Skip to content

Commit

Permalink
Configure logging
Browse files Browse the repository at this point in the history
  • Loading branch information
eschleb committed Dec 9, 2024
1 parent 904cc5c commit 84a8ff1
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 14 deletions.
11 changes: 10 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
<magnolia.version>6.3.1</magnolia.version>
<magnolia.license.version>2.0.0</magnolia.license.version>
<jsr305.nullable.version>3.0.2</jsr305.nullable.version>
<!--Test dependency versions-->
<junit.version>5.11.1</junit.version>
<mockito.version>5.14.0</mockito.version>
<slf4j.bridge.version>2.0.16</slf4j.bridge.version>

<!-- Maven Plugins -->
<mvn.compiler.plugin.version>3.13.0</mvn.compiler.plugin.version>
Expand Down Expand Up @@ -81,6 +81,11 @@
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>${slf4j.bridge.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -132,6 +137,10 @@
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,25 @@
import info.magnolia.test.TestMagnoliaConfigurationProperties;

import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.logging.LogManager;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.slf4j.bridge.SLF4JBridgeHandler;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.apache.commons.lang3.time.StopWatch;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.inject.CreationException;
import com.google.inject.Stage;
Expand All @@ -45,6 +51,7 @@
import com.merkle.oss.magnolia.testing.servlet.ServletContextProvider;

public class MagnoliaIntegrationTestInitializer {
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

public void init(final ExtensionContext extensionContext) throws Exception {
final StopWatch watch = new StopWatch();
Expand All @@ -71,7 +78,7 @@ public void init(final ExtensionContext extensionContext) throws Exception {
throw new RuntimeException("Failed to init: " + e.getErrorMessages(), e);
}
watch.stop();
System.out.println("Initialization took " + watch.getDuration().toMillis() + "ms");
LOG.debug("Initialization took {}ms", watch.getDuration().toMillis());
}

public void destroy() {
Expand All @@ -83,6 +90,8 @@ public void start(final boolean executeFilterChain) throws ModuleManagementExcep
final StopWatch watch = new StopWatch();
watch.start();
System.setProperty("productionMode", "true"); //com.vaadin.server.Constants.SERVLET_PARAMETER_PRODUCTION_MODE
LogManager.getLogManager().reset();
SLF4JBridgeHandler.install();
final ModuleManager moduleManager = Components.getComponent(ModuleManager.class);
moduleManager.checkForInstallOrUpdates();
moduleManager.performInstallOrUpdate();
Expand All @@ -91,7 +100,7 @@ public void start(final boolean executeFilterChain) throws ModuleManagementExcep
executeFilterChain();
}
watch.stop();
System.out.println("Start took " + watch.getDuration().toMillis() + "ms");
LOG.debug("Start took {}ms", watch.getDuration().toMillis());
}

private void executeFilterChain() throws ServletException, IOException {
Expand All @@ -109,7 +118,7 @@ public void stop() {
((AbstractSystemContext) Components.getComponent(SystemContext.class)).getRepositoryStrategy().release();
MgnlContext.setInstance(null);
watch.stop();
System.out.println("Stop took " + watch.getDuration().toMillis() + "ms");
LOG.debug("Stop took {}ms", watch.getDuration().toMillis());
}

private GuiceComponentProvider getPlatformComponentProvider(final Path appRootDir, final ExtensionContext extensionContext) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@
import info.magnolia.module.model.reader.ModuleDefinitionReader;
import info.magnolia.repository.RepositoryManager;

import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang3.time.StopWatch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.inject.Inject;
import com.merkle.oss.magnolia.testing.configuration.TestModuleVersionHandler;

public class TestModuleManager extends ModuleManagerImpl {
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final InstallContextImpl installContext;

@Inject
Expand Down Expand Up @@ -57,6 +61,6 @@ protected void startModule(Object moduleInstance, final ModuleDefinition moduleD
watch.start();
super.startModule(moduleInstance, moduleDefinition, lifecycleContext);
watch.stop();
System.out.println("Starting module " + moduleDefinition.getName() + " took " + watch.getDuration().toMillis() + "ms");
LOG.debug("Starting module {} took {}ms", moduleDefinition.getName(), watch.getDuration().toMillis());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
import info.magnolia.repository.RepositoryManager;

import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.lang.invoke.MethodHandles;

import javax.jcr.ImportUUIDBehavior;
import javax.jcr.Node;
Expand All @@ -20,8 +16,11 @@
import javax.jcr.Value;

import org.junit.jupiter.api.extension.ExtensionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RepositoryUtil {
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final RepositoryManager repositoryManager;

public RepositoryUtil() {
Expand Down Expand Up @@ -67,7 +66,7 @@ public void dump(final String workspace) throws RepositoryException {
*/
public void dump(final Node node) throws RepositoryException {
// First output the node path
System.out.println(node.getPath());
LOG.info(node.getPath());
// Skip the virtual (and large!) jcr:system subtree
if (node.getName().equals("jcr:system")) {
return;
Expand All @@ -81,11 +80,11 @@ public void dump(final Node node) throws RepositoryException {
// A multi-valued property, print all values
Value[] values = property.getValues();
for (int i = 0; i < values.length; i++) {
System.out.println(property.getPath() + " = " + values[i].getString());
LOG.info(property.getPath() + " = " + values[i].getString());
}
} else {
// A single-valued property
System.out.println(property.getPath() + " = " + property.getString());
LOG.info(property.getPath() + " = " + property.getString());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/default-test-magnolia.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ magnolia.cache.startdir=${magnolia.home}/cacheDir
magnolia.author.key.location=${magnolia.home}/authorKey

jaas.config=classpath:/config/current-jaas.config

log4j.configuration=${resource.home}/log4j2-test.xml
19 changes: 19 additions & 0 deletions src/main/resources/log4j2-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="%d %-5p %-50.50c: %m%n"/>
</Console>
</Appenders>
<Loggers>
<!-- Magnolia categories -->
<Logger name="info.magnolia" level="WARN"/>

<!-- Merkle -->
<Logger name="com.merkle.oss.magnolia" level="WARN"/>
<Logger name="com.merkle.oss.magnolia.testing" level="INFO"/>

<!-- 3rd party -->
<logger name="org.atmosphere" level="ERROR" />
</Loggers>
</Configuration>

0 comments on commit 84a8ff1

Please sign in to comment.