Debian Codegraph @

src/footleg/cavesurvey/converter/CmdLineLogger.java

raw symbols SCIP
1 /**
2 * Copyright (C) 2009-2017 Paul Fretwell - aka 'Footleg' ([email protected])
3 *
4 * This file is part of Cave Converter.
5 *
6 * Cave Converter is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Cave Converter is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Cave Converter. If not, see <http://www.gnu.org/licenses/>.
18 */
19 package footleg.cavesurvey.converter;
20
21 import java.text.SimpleDateFormat;
22 import java.util.ArrayList;
23 import java.util.Calendar;
24 import java.util.List;
25 import java.util.TimeZone;
26
27 import footleg.cavesurvey.tools.UtilityFunctions;
28
29 /**
30 * Logging class for command line application.
31 *
32 * @author Footleg
33 * @version 2017.01.09 (ISO 8601 YYYY.MM.DD)
34 * @since 1.6 (The Java version used)
35 *
36 */
37 public class CmdLineLogger extends Logger {
38 private static List<String> log = new ArrayList<String>();
39
40 /**
41 * Logs as message
42 * @param message The message to append to the log
43 */
44 @Override
45 public void logError(String message) {
46 logMessage(message);
47 }
48
49 /**
50 * Formats message with date time stamp, then outputs to console and log
51 * @param message The message to append to the log
52 */
53 @Override
54 public void logMessage(String message) {
55 String logLine;
56
57 Calendar cal = Calendar.getInstance(TimeZone.getDefault());
58 String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
59 SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
60 sdf.setTimeZone(TimeZone.getDefault());
61
62 logLine = sdf.format(cal.getTime()) + ": " + message;
63 log.add( logLine );
64 System.out.println(logLine);
65
66 }
67
68 /**
69 * Writes the contents of the log to a file
70 * @param fileName Full path to the file to write
71 * @param characterSetEncoding Characterset encoding to use in writing the file
72 */
73 public void writeLogToFile(String fileName, String characterSetEncoding) {
74 UtilityFunctions.writeTextFile( log, fileName, characterSetEncoding );
75 }
76
77 }