Added some minor logging functionality using log4j
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
a977ff8cfe
commit
a8302c38e0
10
pom.xml
10
pom.xml
@ -23,6 +23,16 @@
|
|||||||
<artifactId>tomlj</artifactId>
|
<artifactId>tomlj</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-api</artifactId>
|
||||||
|
<version>2.17.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-core</artifactId>
|
||||||
|
<version>2.17.2</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
@ -23,7 +23,7 @@ public class App {
|
|||||||
Transcoder t = new Transcoder(c);
|
Transcoder t = new Transcoder(c);
|
||||||
Timer timer = new Timer();
|
Timer timer = new Timer();
|
||||||
timer.scheduleAtFixedRate(new RunTranscoderTask(t), 2500, ((long) c.getInt("transcoder.interval") * msToMinutes));
|
timer.scheduleAtFixedRate(new RunTranscoderTask(t), 2500, ((long) c.getInt("transcoder.interval") * msToMinutes));
|
||||||
System.out.printf("Starting transcoder, running in %d minute intervals.%n", c.getInt("transcoder.interval"));
|
Logger.logger.info(String.format("Starting transcoder, running in %d minute intervals.", c.getInt("transcoder.interval")));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
9
src/main/java/tech/bitgoblin/Logger.java
Normal file
9
src/main/java/tech/bitgoblin/Logger.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package tech.bitgoblin;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
|
||||||
|
public class Logger {
|
||||||
|
|
||||||
|
public static org.apache.logging.log4j.Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
|
}
|
@ -8,6 +8,7 @@ import java.util.Objects;
|
|||||||
|
|
||||||
import org.tomlj.Toml;
|
import org.tomlj.Toml;
|
||||||
import org.tomlj.TomlParseResult;
|
import org.tomlj.TomlParseResult;
|
||||||
|
import tech.bitgoblin.Logger;
|
||||||
import tech.bitgoblin.io.IOUtils;
|
import tech.bitgoblin.io.IOUtils;
|
||||||
|
|
||||||
public class Config {
|
public class Config {
|
||||||
@ -21,7 +22,7 @@ public class Config {
|
|||||||
try {
|
try {
|
||||||
this.parseConfig();
|
this.parseConfig();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("Unable to read config file; please check that " + this.configPath + " is available.");
|
Logger.logger.info("Unable to read config file; please check that " + this.configPath + " is available.");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package tech.bitgoblin.transcoder;
|
package tech.bitgoblin.transcoder;
|
||||||
|
|
||||||
|
import tech.bitgoblin.Logger;
|
||||||
import tech.bitgoblin.io.IOUtils;
|
import tech.bitgoblin.io.IOUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -33,7 +34,7 @@ public class Repository {
|
|||||||
|
|
||||||
// searches this ingest directory for video files
|
// searches this ingest directory for video files
|
||||||
public File[] searchIngest() {
|
public File[] searchIngest() {
|
||||||
System.out.println("Searching for files to transcode in " + this.ingestPath);
|
Logger.logger.info("Searching for files to transcode in " + this.ingestPath);
|
||||||
File repo = new File(this.ingestPath);
|
File repo = new File(this.ingestPath);
|
||||||
return repo.listFiles();
|
return repo.listFiles();
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import java.nio.file.Paths;
|
|||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
|
|
||||||
|
import tech.bitgoblin.Logger;
|
||||||
import tech.bitgoblin.config.Config;
|
import tech.bitgoblin.config.Config;
|
||||||
import tech.bitgoblin.io.IOUtils;
|
import tech.bitgoblin.io.IOUtils;
|
||||||
|
|
||||||
@ -46,12 +47,12 @@ public class Transcoder {
|
|||||||
|
|
||||||
// check if the ingest directory is empty
|
// check if the ingest directory is empty
|
||||||
if (sourceFiles.length == 0) {
|
if (sourceFiles.length == 0) {
|
||||||
System.out.println("There is nothing to transcode in ingest.");
|
Logger.logger.info("There is nothing to transcode in ingest.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// transcode
|
// transcode
|
||||||
System.out.println("Transcoding video files ingest...");
|
Logger.logger.info("Transcoding video files ingest...");
|
||||||
for (File f : sourceFiles) {
|
for (File f : sourceFiles) {
|
||||||
String filePath = f.toString().substring(0, f.toString().lastIndexOf("."));
|
String filePath = f.toString().substring(0, f.toString().lastIndexOf("."));
|
||||||
String filename = Paths.get(filePath).getFileName().toString();
|
String filename = Paths.get(filePath).getFileName().toString();
|
||||||
@ -73,16 +74,16 @@ public class Transcoder {
|
|||||||
try {
|
try {
|
||||||
Process process = pb.start();
|
Process process = pb.start();
|
||||||
int ret = process.waitFor();
|
int ret = process.waitFor();
|
||||||
System.out.printf("Program exited with code: %d\n", ret);
|
Logger.logger.info("Program exited with code: %d", ret);
|
||||||
System.out.println();
|
Logger.logger.info("");
|
||||||
} catch (IOException | InterruptedException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// end output
|
// end output
|
||||||
System.out.println("------------ End of transcoding ------------");
|
Logger.logger.info("------------ End of transcoding ------------");
|
||||||
System.out.println();
|
Logger.logger.info("");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
15
src/main/resources/log4j2.xml
Normal file
15
src/main/resources/log4j2.xml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Configuration status="info" name="Dragoon" packages="">
|
||||||
|
<Appenders>
|
||||||
|
<File name="DragoonLog" fileName="logs/dragoon.log">
|
||||||
|
<PatternLayout>
|
||||||
|
<Pattern>%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n</Pattern>
|
||||||
|
</PatternLayout>
|
||||||
|
</File>
|
||||||
|
</Appenders>
|
||||||
|
<Loggers>
|
||||||
|
<Root level="info">
|
||||||
|
<AppenderRef ref="DragoonLog"/>
|
||||||
|
</Root>
|
||||||
|
</Loggers>
|
||||||
|
</Configuration>
|
Loading…
Reference in New Issue
Block a user