Skip to content

Commit

Permalink
Updated logging stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
mrothenbuecher committed Nov 2, 2020
1 parent 07f2b4c commit a82122f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
6 changes: 1 addition & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ esdk {
group = "de.finetech.groovy"

dependencies {
provided "de.abas.homedir:log4j:1.0.0"
provided "de.abas.homedir:abas-db-base:1.0.0"
provided "de.abas.homedir:jedp:1.0.0"
provided "de.abas.homedir:abas-jfop-runtime-api:1.0.0"
Expand All @@ -71,9 +72,6 @@ dependencies {
implementation "de.abas.clientdir:abas-db:1.0.0-SNAPSHOT"
implementation "de.abas.clientdir:abas-db-infosys:1.0.0-SNAPSHOT"
implementation "de.abas.clientdir:abas-db-index:1.0.0-SNAPSHOT"
implementation "de.abas.homedir:slf4j-api:1.0.0"
implementation "de.abas.homedir:slf4j-log4j12:1.0.0"
implementation "de.abas.homedir:log4j:1.0.0"

// custom
implementation "de.abas.homedir:abas-jfop-base:1.0.0"
Expand All @@ -89,13 +87,11 @@ dependencies {
runtime "de.abas.homedir:jcl-over-slf4j:1.0.0"
runtime "de.abas.homedir:slf4j-api:1.0.0"
runtime "de.abas.homedir:slf4j-log4j12:1.0.0"
runtime "de.abas.homedir:log4j:1.0.0"

// custom
runtime 'io.github.http-builder-ng:http-builder-ng-core:1.0.4'
runtime 'org.codehaus.groovy:groovy-all:2.5.13'
runtime 'org.codehaus.groovy:groovy-dateutil:2.5.13'
//runtime 'org.slf4j:slf4j-simple:1.7.21'

testImplementation "junit:junit:4.12"
testImplementation "org.hamcrest:hamcrest-all:1.3"
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/de/finetech/groovy/AbasBaseScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import java.io.PrintWriter;
import java.io.StringWriter;

import org.codehaus.groovy.runtime.StackTraceUtils;
import org.slf4j.MDC;

import de.abas.eks.jfop.remote.FOPSessionContext;
import de.abas.erp.db.DbContext;
import de.finetech.groovy.utils.GroovyFOScript;
Expand Down Expand Up @@ -119,9 +122,11 @@ public Object run() {
this.arg0 = (FOPSessionContext) this.getBinding().getVariable("arg0");
this.args = (String[]) this.getBinding().getVariable("args");
this.scriptfile = (String) this.getBinding().getVariable("scriptfile");
MDC.put("SCRIPT", this.scriptfile);
this.dbContext = (DbContext) this.getBinding().getVariable("dbContext");
o = runCode();
} catch (Exception e) {
log.error("Error in script :",StackTraceUtils.deepSanitize(e));
this.onerror(e);
} finally {
this.always();
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/de/finetech/groovy/ScriptExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.codehaus.groovy.control.CompilationFailedException;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.control.customizers.ImportCustomizer;
import org.codehaus.groovy.runtime.StackTraceUtils;
import org.codehaus.groovy.runtime.metaclass.ConcurrentReaderHashMap;
import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl;
import org.slf4j.Logger;
Expand Down Expand Up @@ -42,7 +43,7 @@
*/
public class ScriptExecutor implements ContextRunnable {

private static Logger Log = LoggerFactory.getLogger(ScriptExecutor.class);
private static final Logger log = LoggerFactory.getLogger(ScriptExecutor.class);

public static String readFile(String path, Charset encoding) throws IOException {
byte[] encoded = Files.readAllBytes(Paths.get(path));
Expand Down Expand Up @@ -99,10 +100,6 @@ public static int executeScript(FOPSessionContext arg0, String[] arg1) {
GroovyShell shell = null;
boolean error = false;

Log.info("Test");
Log.debug("Test 2");
Log.error("Test 3");

EKS.eingabe("DATEI.F");
// Genug Parameter „bergben?
if (arg1.length > 1) {
Expand All @@ -111,7 +108,7 @@ public static int executeScript(FOPSessionContext arg0, String[] arg1) {
if (groovyScript.exists()) {
// ist es eine Datei ?
if (groovyScript.isFile()) {
MDC.put("script", arg1[1]);
MDC.put("SCRIPT", arg1[1]);
Object o = null;
Script gscript = null;
try {
Expand Down Expand Up @@ -139,17 +136,20 @@ public static int executeScript(FOPSessionContext arg0, String[] arg1) {
} catch (CommandException e) {
// FIXME Sprach unabh„ngigkeit
FO.fehler("Unbehandelte Ausnahme in " + arg1[1]+"("+GroovySystem.getVersion()+"/"+AbasBaseScript.version+"):\n"+ getStacktrace(e));
log.error("Unbehandelte Ausnahme in " + arg1[1]+"("+GroovySystem.getVersion()+"/"+AbasBaseScript.version+"):\n", StackTraceUtils.deepSanitize(e));
error = true;
} catch (AbortedException e) {
// FIXME Sprach unabh„ngigkeit
FO.fehler("FOP("+arg1[1]+") abgebrochen \nFOP wurde durch Anwender abgebrochen");
log.error("FOP("+arg1[1]+") abgebrochen \nFOP wurde durch Anwender abgebrochen");
error = true;
} catch (CompilationFailedException e) {
// FIXME Sprach unabh„ngigkeit
// FO.box("„bersetzung fehlgeschlagen", "GroovyFO konnte
// das Script nicht „bersetzen: "
// + e.getMessage() + "\n" + getStacktrace(e));
FO.fehler("šbersetzung fehlgeschlagen ("+arg1[1]+"):\n"+ getStacktrace(e));
log.error("šbersetzung fehlgeschlagen ("+arg1[1]+"):\n", StackTraceUtils.deepSanitize(e));
error = true;
} catch (Exception e) {
// FIXME Sprach unabh„ngigkeit
Expand All @@ -174,16 +174,19 @@ public static int executeScript(FOPSessionContext arg0, String[] arg1) {
} else {
// FIXME Sprach unabh„ngigkeit
FO.fehler("Unzureichende Argumente\nGroovy Script "+arg1[1]+" ist keine Datei!");
log.error("Unzureichende Argumente\nGroovy Script "+arg1[1]+" ist keine Datei!");
return -1;
}
} else {
// FIXME Sprach unabh„ngigkeit
FO.fehler("Unzureichende Argumente\nGroovy Script "+arg1[1]+" existiert nicht!");
log.error("Unzureichende Argumente\nGroovy Script "+arg1[1]+" existiert nicht!");
return -1;
}
} else {
// FIXME Sprach unabh„ngigkeit
FO.fehler("Unzureichende Argumente\nkeine Groovy Script angegeben!");
log.error("Unzureichende Argumente\\nkeine Groovy Script angegeben!", arg1);
return -1;
}
return 0;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/de/finetech/groovy/utils/GroovyFOScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ public abstract class GroovyFOScript extends Script implements GroovyObject {
protected boolean GROOVYFODEBUG = false;

public GroovyFOScript() {
// Log.
// Logger.
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/main/resources/logging.custom.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# groovyfo
log4j.logger.de.finetech.groovy=DEBUG, de.finetech.groovy.RollingFile
log4j.appender.de.finetech.groovy.RollingFile=org.apache.log4j.RollingFileAppender
log4j.appender.de.finetech.groovy.RollingFile.File=java/log/groovyfo.log
log4j.appender.de.finetech.groovy.RollingFile.MaxFileSize=5MB
log4j.appender.de.finetech.groovy.RollingFile.MaxBackupIndex=10
log4j.appender.de.finetech.groovy.RollingFile.layout=org.apache.log4j.PatternLayout
log4j.appender.de.finetech.groovy.RollingFile.layout.ConversionPattern=%d{ISO8601} %-5p %X{script} %c{1}:%L - %m%n
log4j.logger.de.finetech.groovy=debug, fileAppender
log4j.appender.fileAppender=org.apache.log4j.RollingFileAppender
log4j.appender.fileAppender.File=java/log/groovyfo.log
log4j.appender.fileAppender.MaxFileSize=5MB
log4j.appender.fileAppender.MaxBackupIndex=10
log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.fileAppender.layout.ConversionPattern=%d{ISO8601} %-5p %X{USER_CODE}:%X{SCRIPT} %c{1}:%L - %m%n

0 comments on commit a82122f

Please sign in to comment.