1 package ch
.cyberduck
.connection
;
4 * ch.cyberduck.connection.Log.java
11 * Copyright (c) 2003 David Kocher. All rights reserved.
12 * http://icu.unizh.ch/~dkocher/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * Bug fixes, suggestions and comments should be sent to:
25 * dkocher@cyberduck.ch
30 import ch
.cyberduck
.Cyberduck
;
31 import ch
.cyberduck
.Preferences
;
34 * I am the logger of a connection.
41 Cyberduck
.DEBUG("[Log] new Log()");
42 buffer
= new StringBuffer();
45 public void append(String text
) {
46 // Cyberduck.DEBUG("[Log] append(" + text + ")");
47 buffer
.append(text
+ Cyberduck
.SEPARATOR
);
51 Cyberduck
.DEBUG("[Log] save()");
53 BufferedWriter bw
= null;
55 File prefFile
= new File(Cyberduck
.PREFS_DIRECTORY
, Preferences
.instance().getProperty("connection.log.file"));
56 bw
= new BufferedWriter(fw
= new FileWriter(prefFile
.toString(), true));
57 String logtext
= buffer
.toString();
58 if (logtext
!= null) {
59 // bw.write("////////////////////////////////////////////////");
61 // bw.write(Cyberduck.SEPARATOR + logtext + Cyberduck.SEPARATOR);
64 Cyberduck
.DEBUG("[Log] " + logtext
);
68 catch (IOException e
) {
69 System
.out
.println("Error: " + e
.getMessage());
79 catch(IOException close
) {
80 System
.err
.println("[Log] Error: " + close
.getMessage());
81 close
.printStackTrace();
86 public static String
open() {
87 Cyberduck
.DEBUG("[Log] open()");
88 StringBuffer logtext
= new StringBuffer();
89 File path
= new File(Cyberduck
.PREFS_DIRECTORY
, Preferences
.instance().getProperty("connection.log.file"));
92 FileReader fr
= new FileReader(path
);
93 BufferedReader br
= new BufferedReader(fr
);
96 String line
= br
.readLine();
101 logtext
.append(line
+ Cyberduck
.SEPARATOR
);
105 catch (IOException e
) {
106 System
.err
.println("[Log] Could not open log file." + e
.getMessage());
109 return logtext
.toString();
112 public static void delete() {
113 Cyberduck
.DEBUG("[Log] delete()");
115 File path
= new File(Cyberduck
.PREFS_DIRECTORY
, Preferences
.instance().getProperty("connection.log.file"));
119 catch(SecurityException e
) {
120 System
.err
.println("[Log] Could not delete log file: " + e
.getMessage());