Skip to content

Commit

Permalink
adapt log level for stdout/stderr msg sent by posthook (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Coutadeur committed Jul 12, 2024
1 parent 620fd29 commit 40d80fe
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/main/java/org/lsc/Hooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
*/
package org.lsc;

import org.slf4j.event.Level;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.ProcessBuilder;
Expand Down Expand Up @@ -125,13 +126,15 @@ public final static void callHook( LscModificationType operationType,
operationType.getDescription(),
hook,
outputFormat.toString(),
identifier);
identifier,
Level.INFO);
printHookOutput(p.getErrorStream(),
"stderr",
operationType.getDescription(),
hook,
outputFormat.toString(),
identifier);
identifier,
Level.ERROR);
}
catch(IOException e) {
LOGGER.error("Error while calling {} posthook {} with format {} for {}",
Expand Down Expand Up @@ -162,18 +165,20 @@ public final static String getJsonModifications(final LscModifications lm) {

private static void printHookOutput( final InputStream src, String output,
String operation, String hook,
String outputFormat, String identifier) {
String outputFormat, String identifier,
Level level) {
new Thread(new Runnable() {
public void run() {
Scanner sc = new Scanner(src);
while (sc.hasNextLine()) {
LOGGER.warn("Hook {} with format {} for identifier {} and operation {} returned {}: {}",
hook,
outputFormat,
identifier,
operation,
output,
sc.nextLine());
LOGGER.atLevel(level).log(
"Hook {} with format {} for identifier {} and operation {} returned on {}: {}",
hook,
outputFormat,
identifier,
operation,
output,
sc.nextLine());
}
}
}).start();
Expand Down

0 comments on commit 40d80fe

Please sign in to comment.