diff --git a/.gitignore b/.gitignore index d12ac77..c6bc386 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ !.mvn target META-INF -*.log \ No newline at end of file +*.log +code2svg-logback.xml \ No newline at end of file diff --git a/app/src/main/java/org/fuin/code2svg/app/Code2SvgApp.java b/app/src/main/java/org/fuin/code2svg/app/Code2SvgApp.java index d437275..3da41d2 100644 --- a/app/src/main/java/org/fuin/code2svg/app/Code2SvgApp.java +++ b/app/src/main/java/org/fuin/code2svg/app/Code2SvgApp.java @@ -18,15 +18,19 @@ package org.fuin.code2svg.app; import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Writer; import java.net.MalformedURLException; import java.net.URL; +import java.nio.charset.Charset; import java.util.Arrays; import java.util.List; import org.fuin.code2svg.core.Code2Svg; import org.fuin.code2svg.core.Code2SvgConfig; import org.fuin.code2svg.core.Code2SvgUtils; -import org.fuin.ext4logback.LogbackStandalone; import org.fuin.ext4logback.NewLogConfigFileParams; import org.fuin.utils4j.JaxbUtils; import org.fuin.utils4j.Utils4J; @@ -54,7 +58,7 @@ private static void execute(final File configFile, final File targetDir, final L final Code2SvgConfig config = JaxbUtils.unmarshal(configXml, Code2SvgUtils.JAXB_CLASSES); final Code2Svg converter = new Code2Svg(); - filenames.forEach( filename -> { + filenames.forEach(filename -> { final File file = new File(filename); if (file.isDirectory()) { converter.convertDir(config, file, targetDir); @@ -65,15 +69,59 @@ private static void execute(final File configFile, final File targetDir, final L } + private static void writeInitialLogbackXml(final File logbackXmlFile, final NewLogConfigFileParams params) throws IOException { + final String logFilename = params.getLogFilename(); + // @formatter:off + final String xml = "\n" + + "\n" + + " \n" + + " ${log_path}/" + logFilename + ".log\n" + + " \n" + + " " + logFilename + ".%d{yyyy-MM-dd}.log\n" + + " 30\n" + + " \n" + + " true\n" + + " \n" + + " " + params.getLayoutPattern() + "\n" + + " \n" + + " \n" + + " " + + " " + + " " + params.getLayoutPattern() + "\n" + + " " + + " " + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "\n"; + // @formatter:on + try (final Writer fw = new OutputStreamWriter(new FileOutputStream(logbackXmlFile), Charset.forName("UTF-8"))) { + fw.write(xml); + } + } + + private static void initLogback() { + final File logbackXmlFile = new File("code2svg-logback.xml"); + if (!logbackXmlFile.exists()) { + try { + writeInitialLogbackXml(logbackXmlFile, new NewLogConfigFileParams("org.fuin.code2svg.app", "code2svg")); + } catch (final IOException ex) { + throw new RuntimeException("Failed to create initial logback XML configuration", ex); + } + } + } + public static void main(String[] args) { if (args == null || args.length < 3) { System.out.println("Required arguments: ... "); System.exit(1); } - + try { - new LogbackStandalone().init(new File("code2svg"), new NewLogConfigFileParams("org.fuin.code2svg.app", "code2svg")); + initLogback(); LOG.info("Application running..."); final File configFile = new File(args[0]);