Skip to content
This repository has been archived by the owner on Oct 8, 2023. It is now read-only.

Commit

Permalink
Make logging optional
Browse files Browse the repository at this point in the history
  • Loading branch information
raydouglass committed Feb 7, 2020
1 parent 7070e5b commit 3058e64
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ Note: it is likely that any previously scheduled recordings will NOT work after
## Contact
You can reach me at ray@raydouglass.com

If you have a problem, please try running with the `--debug` flag then provide the xmltv file along with the log file (xmltvtomxf.log).
If you have a problem, please try running with `java -Ddebug.logging=true -jar ...` then provide the xmltv file along with the log file (xmltvtomxf.log).
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
<artifactId>logback-classic</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
<version>3.0.6</version>
</dependency>
<dependency>
<groupId>net.sourceforge.argparse4j</groupId>
<artifactId>argparse4j</artifactId>
Expand Down
24 changes: 5 additions & 19 deletions src/main/java/com/dontocsata/xmltv/XmlTvParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public class XmlTvParser {
private static final Logger log = LoggerFactory.getLogger(XmlTvParser.class);

public static void main(String[] args) throws Exception {
if(Boolean.parseBoolean(System.getProperty("debug.logging"))){
((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME))
.setLevel(ch.qos.logback.classic.Level.TRACE);
}

log.info("Starting with args={}", Arrays.deepToString(args));
ArgumentParser argParse = ArgumentParsers.newArgumentParser("XMLTVtoMXF", true)
.description("This converts an XMLTV file to the Microsoft Windows Media Center MXF XML format.");
Expand Down Expand Up @@ -109,26 +114,7 @@ public boolean consumeArgument() {
}
}).help("The XMLTV file to parse");
argParse.addArgument("-o", "--output").setDefault("mxf.xml").help("The MXF file output location");
argParse.addArgument("--debug").help("Run in debug most which produces detailed logs")
.action(new ArgumentAction() {

@Override
public void run(ArgumentParser parser, Argument arg, Map<String, Object> attrs, String flag,
Object value) throws ArgumentParserException {
((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME))
.setLevel(ch.qos.logback.classic.Level.TRACE);
}

@Override
public void onAttach(Argument arg) {

}

@Override
public boolean consumeArgument() {
return false;
}
});
// argParse.addArgument("--low-memory").dest("lowMemory").action(Arguments.storeTrue()).setDefault(Boolean.FALSE).help("Run
// in low memory mode");
Namespace ns = null;
Expand Down
35 changes: 25 additions & 10 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
<configuration debug="false">
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>xmltvtomxf.log</file>
<encoder>
<pattern>%date %level [%thread] %C{16}:%line - %m%n</pattern>
</encoder>
<param name="Append" value="false"/>
</appender>
<root level="INFO">
<appender-ref ref="FILE" />
</root>
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
<if condition='Boolean.parseBoolean(property("debug.logging"))'>
<then>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>xmltvtomxf.log</file>
<encoder>
<pattern>%date %level [%thread] %C{16}:%line - %m%n</pattern>
</encoder>
<param name="Append" value="false"/>
</appender>
<root level="OFF">
<appender-ref ref="FILE"/>
</root>
</then>
<else>
<appender name="CON" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date %level - %m%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="CON"/>
</root>
</else>
</if>
</configuration>

0 comments on commit 3058e64

Please sign in to comment.