Skip to content

Commit

Permalink
[sre] Enable logging on stdout and stderr.
Browse files Browse the repository at this point in the history
Errors and warnings are logged on the standard error output.
The other messages are logged on the standard output.

close #626

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Mar 30, 2017
1 parent e8a0207 commit 1d9abff
Show file tree
Hide file tree
Showing 8 changed files with 489 additions and 380 deletions.
11 changes: 6 additions & 5 deletions sre/io.janusproject/io.janusproject.feature/feature.xml
Expand Up @@ -225,22 +225,23 @@
<import plugin="io.sarl.core" version="0.6.0" match="greaterOrEqual"/>
<import plugin="io.sarl.util" version="0.6.0" match="greaterOrEqual"/>
<import plugin="io.sarl.eclipse" version="0.6.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.osgi" version="3.11.3" match="greaterOrEqual"/>
<import plugin="com.hazelcast" version="3.8.0" match="greaterOrEqual"/>
<import plugin="org.zeromq.jeromq" version="0.3.6" match="greaterOrEqual"/>
<import plugin="com.google.guava" version="18.0.0" match="greaterOrEqual"/>
<import plugin="com.google.inject" version="4.1.0" match="greaterOrEqual"/>
<import plugin="org.apache.commons.cli" version="1.3.1" match="greaterOrEqual"/>
<import plugin="org.eclipse.jdt.core" version="3.12.3" match="greaterOrEqual"/>
<import plugin="org.eclipse.core.runtime" version="3.12.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.ui.workbench" version="3.108.3" match="greaterOrEqual"/>
<import plugin="org.eclipse.jdt.ui" version="3.12.2" match="greaterOrEqual"/>
<import plugin="org.eclipse.jface" version="3.12.2" match="greaterOrEqual"/>
<import plugin="org.arakhne.afc.core.vmutils" version="14.0.0" match="greaterOrEqual"/>
<import plugin="org.arakhne.afc.core.util" version="14.0.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.swt" version="3.105.3" match="greaterOrEqual"/>
<import plugin="org.eclipse.jdt.launching" version="3.8.101" match="greaterOrEqual"/>
<import plugin="com.google.code.gson" version="2.8.0" match="greaterOrEqual"/>
<import plugin="org.eclipse.osgi" version="3.11.3" match="greaterOrEqual"/>
<import plugin="org.eclipse.jdt.core" version="3.12.3" match="greaterOrEqual"/>
<import plugin="org.eclipse.ui.workbench" version="3.108.3" match="greaterOrEqual"/>
<import plugin="org.eclipse.jface" version="3.12.2" match="greaterOrEqual"/>
<import plugin="org.eclipse.swt" version="3.105.3" match="greaterOrEqual"/>
<import plugin="aopalliance" version="1.0.0" match="greaterOrEqual"/>
</requires>

<plugin
Expand Down
Expand Up @@ -22,7 +22,8 @@ Require-Bundle: io.sarl.core;bundle-version="0.6.0",
org.arakhne.afc.core.util;bundle-version="14.0.0",
org.eclipse.swt;bundle-version="3.105.3",
org.eclipse.jdt.launching;bundle-version="3.8.101",
com.google.code.gson;bundle-version="2.8.0"
com.google.code.gson;bundle-version="2.8.0",
aopalliance;bundle-version="1.0.0"
Bundle-Activator: io.janusproject.eclipse.JanusEclipsePlugin
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %Bundle-Vendor
Expand Down
Expand Up @@ -84,20 +84,6 @@ public final class JanusConfig {
*/
public static final Boolean JANUS_LOGO_SHOW = Boolean.TRUE;

/**
* Name of the property that contains the verbosity level of Janus.
*
* @see #LOGGING_PROPERTY_FILE_VALUE
*/
public static final String LOGGING_PROPERTY_FILE_NAME = "java.util.logging.config.file"; //$NON-NLS-1$

/**
* The default name of the logging property file of Janus.
*
* @see #LOGGING_PROPERTY_FILE_NAME
*/
public static final String LOGGING_PROPERTY_FILE_VALUE = "resource:io/janusproject/logging.properties"; //$NON-NLS-1$

/**
* Name of the property that contains the identifier of the Janus context.
*
Expand Down Expand Up @@ -285,7 +271,6 @@ public static void getDefaultValues(Properties defaultValues) {
defaultValues.put(PUB_URI, ""); //$NON-NLS-1$
defaultValues.put(RANDOM_DEFAULT_CONTEXT_ID_NAME, RANDOM_DEFAULT_CONTEXT_ID_VALUE.toString());
defaultValues.put(VERBOSE_LEVEL_NAME, VERBOSE_LEVEL_VALUE);
defaultValues.put(LOGGING_PROPERTY_FILE_NAME, LOGGING_PROPERTY_FILE_VALUE);
defaultValues.put(HAZELCAST_LOGGER_FACTORY_NAME, HAZELCAST_LOGGER_FACTORY_VALUE);
defaultValues.put(MIN_NUMBER_OF_THREADS_IN_EXECUTOR_NAME, Integer.toString(MIN_NUMBER_OF_THREADS_IN_EXECUTOR_VALUE));
defaultValues.put(MAX_NUMBER_OF_THREADS_IN_EXECUTOR_NAME, Integer.toString(MAX_NUMBER_OF_THREADS_IN_EXECUTOR_VALUE));
Expand Down
Expand Up @@ -32,6 +32,7 @@
import com.google.common.util.concurrent.Service;

import io.janusproject.services.logging.LogService;
import io.janusproject.util.LoggerCreator;

/**
* This class provides an implementation of the {@link LogService} that outputs nothing.
Expand All @@ -51,7 +52,7 @@ public class EmptyLogService extends AbstractService implements LogService {
* Construct.
*/
public EmptyLogService() {
this.logger = Logger.getLogger(EmptyLogService.class.getName());
this.logger = LoggerCreator.createLogger(EmptyLogService.class.getName());
}

@Override
Expand Down

This file was deleted.

Expand Up @@ -22,36 +22,22 @@
package io.janusproject.modules;

import java.io.IOError;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.net.InetAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.LogManager;
import java.util.logging.Logger;

import com.google.common.base.Strings;
import com.google.inject.AbstractModule;
import com.google.inject.Key;
import com.google.inject.MembersInjector;
import com.google.inject.Provider;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import com.google.inject.matcher.Matchers;
import com.google.inject.name.Named;
import com.google.inject.name.Names;
import com.google.inject.spi.TypeEncounter;
import com.google.inject.spi.TypeListener;
import org.arakhne.afc.vmutil.FileSystem;

import io.janusproject.JanusConfig;
import io.janusproject.services.network.NetworkUtil;
import io.janusproject.util.LoggerCreator;

/**
* The module configures the minimum requirements for the system variables.
Expand All @@ -65,10 +51,6 @@ public class BootModule extends AbstractModule {

@Override
protected void configure() {
// Custom logger
LoggerCreator.useJanusMessageFormat();
bindListener(Matchers.any(), new LoggerMemberListener());

// Bind the system properties.
boolean foundPubUri = false;
String name;
Expand Down Expand Up @@ -199,94 +181,4 @@ public String get() {

}

/**
* Provider of logger.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
private static final class LoggerMemberListener implements TypeListener {

private final AtomicBoolean isInit = new AtomicBoolean(false);

/**
* Construct.
*/
LoggerMemberListener() {
//
}

private static void init() {
final String propertyFileName = JanusConfig.getSystemProperty(JanusConfig.LOGGING_PROPERTY_FILE_NAME,
JanusConfig.LOGGING_PROPERTY_FILE_VALUE);
if (propertyFileName != null && !propertyFileName.isEmpty()) {
final URL url = FileSystem.convertStringToURL(propertyFileName, true);
if (url != null) {
try (InputStream is = url.openStream()) {
LogManager.getLogManager().readConfiguration(is);
} catch (IOException e) {
throw new IOError(e);
}
}
}
}

@Override
public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
for (final Field field : type.getRawType().getDeclaredFields()) {
if (field.getType() == Logger.class) {
if (!this.isInit.getAndSet(true)) {
init();
}
encounter.register(new LoggerMemberInjector<I>(field));
}
}
}

}

/**
* Provider of logger.
*
* @param <T>
* the type of the type of the field.
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
*/
private static final class LoggerMemberInjector<T> implements MembersInjector<T> {

private final Field field;

/**
* Construct.
*
* @param field
* the field to inject.
*/
LoggerMemberInjector(Field field) {
this.field = field;
}

@Override
public void injectMembers(T instance) {
final Logger logger = LoggerCreator.createLogger(JanusConfig.JANUS_DEFAULT_PLATFORM_NAME + " (" //$NON-NLS-1$
+ this.field.getDeclaringClass().getSimpleName() + ")"); //$NON-NLS-1$

final boolean accessible = this.field.isAccessible();
try {
this.field.setAccessible(true);
this.field.set(instance, logger);
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
} finally {
this.field.setAccessible(accessible);
}
}

}

}

0 comments on commit 1d9abff

Please sign in to comment.