Skip to content

Commit

Permalink
GH-548 Remove slf4j logging api (Resolve #546)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzikoysk committed Aug 19, 2020
1 parent 184a080 commit a8a87c7
Show file tree
Hide file tree
Showing 42 changed files with 200 additions and 491 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package org.panda_lang.language;

import org.panda_lang.language.interpreter.messenger.LoggerHolder;
import org.panda_lang.language.interpreter.logging.Logger;
import org.panda_lang.language.interpreter.logging.LoggerHolder;
import org.panda_lang.language.resource.Language;
import org.panda_lang.language.resource.Resources;
import org.slf4j.Logger;

/**
* Panda Framework controller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package org.panda_lang.language;

import org.panda_lang.language.interpreter.logging.Logger;
import org.panda_lang.language.resource.Language;
import org.panda_lang.language.resource.Resources;
import org.slf4j.Logger;

public abstract class PandaFramework implements FrameworkController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package org.panda_lang.language.architecture;

import org.jetbrains.annotations.Nullable;
import org.panda_lang.language.interpreter.messenger.LoggerHolder;
import org.slf4j.Logger;
import org.panda_lang.language.interpreter.logging.Logger;
import org.panda_lang.language.interpreter.logging.LoggerHolder;

/**
* Application is a group of bundled scripts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
import org.panda_lang.language.architecture.module.ModulePath;
import org.panda_lang.language.architecture.module.TypeLoader;
import org.panda_lang.language.interpreter.Interpreter;
import org.panda_lang.language.interpreter.messenger.LoggerHolder;
import org.panda_lang.language.interpreter.messenger.Messenger;
import org.panda_lang.language.interpreter.logging.LoggerHolder;

import java.io.File;

Expand Down Expand Up @@ -51,13 +50,6 @@ public interface Environment extends LoggerHolder {
*/
TypeLoader getTypeLoader();

/**
* Get the environment messenger
*
* @return the messenger
*/
Messenger getMessenger();

/**
* Get working directory
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.panda_lang.language.interpreter;

import org.panda_lang.language.interpreter.messenger.LoggerHolder;
import org.panda_lang.language.interpreter.logging.LoggerHolder;
import org.panda_lang.utilities.commons.function.ThrowingRunnable;
import org.panda_lang.utilities.commons.function.ThrowingSupplier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package org.panda_lang.language.interpreter;

import org.jetbrains.annotations.Nullable;
import org.panda_lang.language.interpreter.logging.Logger;
import org.panda_lang.utilities.commons.function.ThrowingRunnable;
import org.panda_lang.utilities.commons.function.ThrowingSupplier;
import org.slf4j.Logger;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -50,7 +50,6 @@ public <E extends Exception> Interpretation execute(ThrowingRunnable<E> task) {
return isHealthy() ? task.get() : null;
} catch (Exception exception) {
failures.add(exception);
this.healthy = !interpreter.getEnvironment().getMessenger().send(exception);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@

package org.panda_lang.language.resource;

import org.panda_lang.utilities.commons.function.Option;
import org.panda_lang.language.interpreter.messenger.MessengerInitializer;
import org.panda_lang.language.interpreter.messenger.MessengerOutputListener;
import org.panda_lang.language.interpreter.parser.expression.ExpressionSubparsers;
import org.panda_lang.language.interpreter.parser.pipeline.PipelinePath;
import org.panda_lang.language.interpreter.parser.pipeline.PandaPipelinePath;
import org.panda_lang.language.interpreter.parser.pipeline.PipelinePath;

public final class PandaResources implements Resources {

Expand All @@ -41,39 +38,17 @@ public PipelinePath getPipelinePath() {
return builder.pipelinePath;
}

@Override
public Option<MessengerInitializer> getMessengerInitializer() {
return Option.of(builder.messengerInitializer);
}

@Override
public Option<MessengerOutputListener> getOutputListener() {
return Option.of(builder.outputListener);
}

public static PandaResourcesBuilder builder() {
return new PandaResourcesBuilder();
}

public static final class PandaResourcesBuilder {

public MessengerOutputListener outputListener;
public MessengerInitializer messengerInitializer;
public PipelinePath pipelinePath;
public ExpressionSubparsers expressionSubparsers;

private PandaResourcesBuilder() { }

public PandaResourcesBuilder withOutputListener(MessengerOutputListener outputListener) {
this.outputListener = outputListener;
return this;
}

public PandaResourcesBuilder withMessengerInitializer(MessengerInitializer messengerInitializer) {
this.messengerInitializer = messengerInitializer;
return this;
}

public PandaResourcesBuilder withPipelinePath(PipelinePath pipelinePath) {
this.pipelinePath = pipelinePath;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@

package org.panda_lang.language.resource;

import org.panda_lang.language.interpreter.messenger.MessengerInitializer;
import org.panda_lang.language.interpreter.messenger.MessengerOutputListener;
import org.panda_lang.language.interpreter.parser.expression.ExpressionSubparsers;
import org.panda_lang.language.interpreter.parser.pipeline.PipelinePath;

import org.panda_lang.utilities.commons.function.Option;

/**
* Set of resources used by the language
*/
Expand All @@ -42,18 +38,4 @@ public interface Resources {
*/
PipelinePath getPipelinePath();

/**
* Get initializer for {@link org.panda_lang.language.interpreter.messenger.Messenger}
*
* @return the messenger initializer
*/
Option<MessengerInitializer> getMessengerInitializer();

/**
* Get output listener for {@link org.panda_lang.language.interpreter.messenger.Messenger}
*
* @return the output listener to use by messenger
*/
Option<MessengerOutputListener> getOutputListener();

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public PandaProcess(Application application, StandardizedFramedScope mainScope,
Result<?> result = stack.callFrame(instance, instance);
return result != null ? result.getResult() : null;
} catch (Exception e) {
application.getEnvironment().getMessenger().send(new PandaProcessFailure(stack, e));
return -1;
throw new PandaProcessFailure(stack, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,36 @@

package org.panda_lang.language.runtime;

public final class PandaProcessFailure {
import java.io.PrintWriter;

public final class PandaProcessFailure extends PandaRuntimeException {

private final ProcessStack stack;
private final Exception exception;

public PandaProcessFailure(ProcessStack stack, Exception exception) {
super(exception);
this.stack = stack;
this.exception = exception;
}

@Override
public void printStackTrace(PrintWriter s) {
/*
&b- - ~ ~< Runtime Exception >~ ~ - -&r
{{message}}
{{stacktrace}}
{{exception.short}}
Environment: {{environment}}
End of Exception
*/
super.printStackTrace(s);
}

public Exception getException() {
return exception;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ public PandaRuntimeException(String message, Throwable cause) {
super(message, cause);
}

public PandaRuntimeException(Throwable cause) {
super(cause);
}

}
18 changes: 0 additions & 18 deletions panda-utilities/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,6 @@
<artifactId>annotations</artifactId>
</dependency>

<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.tinylog</groupId>
<artifactId>tinylog-api</artifactId>
</dependency>
<dependency>
<groupId>org.tinylog</groupId>
<artifactId>tinylog-impl</artifactId>
</dependency>
<dependency>
<groupId>org.tinylog</groupId>
<artifactId>slf4j-tinylog</artifactId>
</dependency>

<!-- Benchmarks -->
<dependency>
<groupId>org.openjdk.jmh</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public Lazy(Supplier<T> supplier) {
this.supplier = supplier;
}

public Lazy(Runnable runnable) {
this.supplier = () -> {
runnable.run();
return null;
};
}

@Override
public synchronized T get() {
if (initialized) {
Expand Down
21 changes: 0 additions & 21 deletions panda-utilities/src/main/resources/tinylog.properties

This file was deleted.

4 changes: 0 additions & 4 deletions panda/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@

<artifactId>panda</artifactId>

<properties>
<!--<maven.test.skip>true</maven.test.skip>-->
</properties>

<dependencies>
<!-- Panda Framework -->
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion panda/src/main/java/org/panda_lang/panda/Panda.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import org.panda_lang.language.FrameworkController;
import org.panda_lang.language.PandaClassLoader;
import org.panda_lang.language.PandaFramework;
import org.panda_lang.language.interpreter.logging.Logger;
import org.panda_lang.language.resource.Language;
import org.panda_lang.language.resource.Resources;
import org.panda_lang.panda.language.interpreter.PandaFileLoader;
import org.slf4j.Logger;

/**
* The framework controller of Panda language.
Expand Down
17 changes: 6 additions & 11 deletions panda/src/main/java/org/panda_lang/panda/PandaFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@

package org.panda_lang.panda;

import org.panda_lang.language.interpreter.logging.Logger;
import org.panda_lang.language.interpreter.logging.SystemLogger;
import org.panda_lang.language.resource.syntax.PandaSyntax;
import org.panda_lang.panda.bootstrap.PandaBootstrap;
import org.panda_lang.panda.language.interpreter.messenger.formatters.Formatters;
import org.panda_lang.panda.language.interpreter.messenger.layouts.TranslatorLayouts;
import org.panda_lang.panda.language.interpreter.messenger.mappers.StacktraceMapper;
import org.panda_lang.panda.language.resource.syntax.PandaParsers;
import org.panda_lang.panda.language.resource.syntax.expressions.subparsers.assignation.AssignationParsers;
import org.slf4j.Logger;

/**
* Simplify creation of Panda instance
*/
public final class PandaFactory {

public Panda createPanda() {
return createPanda(new SystemLogger());
}

/**
* Create default instance of Panda
*
Expand All @@ -41,13 +43,6 @@ public Panda createPanda(Logger logger) {
// load syntax
.withSyntax(new PandaSyntax())

// initialize messenger
.initializeMessenger()
.addLayouts(TranslatorLayouts.LAYOUTS)
.addDataFormatters(Formatters.FORMATTERS)
.addDataMapper(new StacktraceMapper())
.collect()

// load pipelines
.initializePipelines()
.collect()
Expand Down
4 changes: 2 additions & 2 deletions panda/src/main/java/org/panda_lang/panda/PandaLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package org.panda_lang.panda;

import org.panda_lang.language.interpreter.logging.SystemLogger;
import org.panda_lang.panda.shell.PandaShell;
import org.panda_lang.utilities.commons.ArrayUtils;
import org.slf4j.LoggerFactory;

/**
* Default launcher of Panda
Expand All @@ -34,7 +34,7 @@ private PandaLauncher() { }
* @throws Exception if something happen
*/
public static void main(String... args) throws Exception {
PandaShell shell = new PandaShell(() -> LoggerFactory.getLogger(PandaLauncher.class), System.in);
PandaShell shell = new PandaShell(SystemLogger::new, System.in);

if (ArrayUtils.isEmpty(args)) {
args = new String[] { "--help" };
Expand Down
Loading

0 comments on commit a8a87c7

Please sign in to comment.