source: java/installer2/src/net/oni2/aeinstaller/backend/oni/management/Logger.java@ 925

Last change on this file since 925 was 749, checked in by alloc, 12 years ago

AEI2 0.99x:

  • Refactoring
File size: 1.7 KB
Line 
1package net.oni2.aeinstaller.backend.oni.management;
2
3import java.io.File;
4import java.io.FileNotFoundException;
5import java.io.PrintWriter;
6
7import net.oni2.platformtools.applicationinvoker.ApplicationInvocationResult;
8
9/**
10 * @author Christian Illy
11 */
12public class Logger {
13 PrintWriter log = null;
14
15 /**
16 * @param logfile
17 * File to log to
18 * @throws FileNotFoundException
19 * Huh?
20 */
21 public Logger(File logfile) throws FileNotFoundException {
22 log = new PrintWriter(logfile);
23 }
24
25 /**
26 * Print an empty line
27 */
28 public void println() {
29 log.println();
30 }
31
32 /**
33 * Print a string as a line
34 *
35 * @param line
36 * String to print
37 */
38 public void println(String line) {
39 log.println(line);
40 }
41
42 /**
43 * Print a formatted string as a line
44 *
45 * @param fmt
46 * Format string
47 * @param args
48 * Values
49 */
50 public void printlnFmt(String fmt, Object... args) {
51 log.println(String.format(fmt, args));
52 }
53
54 /**
55 * Close logger
56 */
57 public void close() {
58 log.close();
59 log = null;
60 }
61
62 /**
63 * Log the application invocation result
64 *
65 * @param result
66 * App result
67 * @param onlyOnError
68 * Print returned output only on errorcode != 0
69 */
70 public void logAppOutput(ApplicationInvocationResult result,
71 boolean onlyOnError) {
72 if (result != null) {
73 log.println("\t\t\tCalled:");
74 for (String s : result.cmdLine)
75 log.println("\t\t\t\t" + s);
76 log.println("\t\t\tReturned: " + result.errorCode);
77 if (!onlyOnError || result.errorCode != 0) {
78 for (String s : result.output)
79 log.println("\t\t\t\t" + s);
80 }
81 log.println("\t\t\tDuration: " + result.time + " ms");
82 log.println();
83 }
84 }
85
86}
Note: See TracBrowser for help on using the repository browser.