Author: alexlehm
Date: 2007-11-22 20:24:44 +0000 (Thu, 22 Nov 2007)
New Revision: 15929
Added:
trunk/apps/Freemail/src/freemail/utils/Logger.java
Modified:
trunk/apps/Freemail/src/freemail/InboundContact.java
trunk/apps/Freemail/src/freemail/OutboundContact.java
trunk/apps/Freemail/src/freemail/RTSFetcher.java
Log:
Logger class for Freemail, this tries to mimic the Logger class form Freenet,
maybe we can later exchange the class by simple changing the import. The
logging has to be changed on a few other classes as well, I'll commit that
later.
A regular user will need normal and error messages, anything minor is status
logs that do not show progress (e.g. checking message keys).
Modified: trunk/apps/Freemail/src/freemail/InboundContact.java
===================================================================
--- trunk/apps/Freemail/src/freemail/InboundContact.java 2007-11-22
19:44:49 UTC (rev 15928)
+++ trunk/apps/Freemail/src/freemail/InboundContact.java 2007-11-22
20:24:44 UTC (rev 15929)
@@ -33,6 +33,7 @@
import freemail.FreenetURI;
import freemail.utils.PropsFile;
import freemail.utils.EmailAddress;
+import freemail.utils.Logger;
import freemail.fcp.HighLevelFCPClient;
import freemail.fcp.ConnectionTerminatedException;
@@ -72,7 +73,7 @@
String slots = this.ibct_props.get("slots");
if (slots == null) {
- System.out.println("Contact "+this.ibct_dir.getName()+"
is corrupt - account file has no 'slots' entry!");
+ Logger.normal(this,"Contact "+this.ibct_dir.getName()+"
is corrupt - account file has no 'slots' entry!");
// TODO: probably delete the contact. it's useless now.
return;
}
@@ -82,7 +83,7 @@
String basekey = this.ibct_props.get("commssk");
if (basekey == null) {
- System.out.println("Contact "+this.ibct_dir.getName()+"
is corrupt - account file has no 'commssk' entry!");
+ Logger.normal(this,"Contact "+this.ibct_dir.getName()+"
is corrupt - account file has no 'commssk' entry!");
// TODO: probably delete the contact. it's useless now.
return;
}
@@ -91,16 +92,16 @@
// the slot should be 52 characters long, since this is
how long a 256 bit string ends up when base32 encoded.
// (the slots being base32 encoded SHA-256 checksums)
// TODO: remove this once the bug is ancient history,
or if actually want to check the slots, do so in the SlotManagers.
- // a fix for the bug causing this
(https://bugs.freenetproject.org/view.php?id=1087) was commited on Feb 4 2007,
+ // a fix for the bug causing this
(https://bugs.freenetproject.org/view.php?id=1087) was committed on Feb 4 2007,
// anybody who has started using Freemail after that
date is not affected.
if(slot.length()!=52) {
- System.out.println("ignoring malformed slot
"+slot+" (probably due to previous bug)");
- System.out.println("please the fix the entry in
"+this.ibct_dir);
+ Logger.normal(this,"ignoring malformed slot
"+slot+" (probably due to previous bug)");
+ Logger.normal(this,"please the fix the entry in
"+this.ibct_dir);
break;
}
String key = basekey+slot;
- System.out.println("Attempting to fetch mail on key
"+key);
+ Logger.minor(this,"Attempting to fetch mail on key
"+key);
File msg = null;
try {
msg = fcpcli.fetch(key);
@@ -108,16 +109,16 @@
return;
}
if (msg == null) {
- System.out.println("No mail there.");
+ Logger.minor(this,"No mail there.");
continue;
}
- System.out.println("Found a message!");
+ Logger.normal(this,"Found a message!");
// parse the Freemail header(s) out.
PropsFile msgprops = new PropsFile(msg, true);
String s_id = msgprops.get("id");
if (s_id == null) {
- System.out.println("Got a message with an
invalid header. Discarding.");
+ Logger.normal(this,"Got a message with an
invalid header. Discarding.");
sm.slotUsed();
msgprops.closeReader();
msg.delete();
@@ -128,7 +129,7 @@
try {
id = Integer.parseInt(s_id);
} catch (NumberFormatException nfe) {
- System.out.println("Got a message with an
invalid (non-integer) id. Discarding.");
+ Logger.normal(this,"Got a message with an
invalid (non-integer) id. Discarding.");
sm.slotUsed();
msgprops.closeReader();
msg.delete();
@@ -140,13 +141,13 @@
try {
isDupe = msglog.isPresent(id);
} catch (IOException ioe) {
- System.out.println("Couldn't read logfile, so
don't know whether received message is a duplicate or not. Leaving in the queue
to try later.");
+ Logger.normal(this,"Couldn't read logfile, so
don't know whether received message is a duplicate or not. Leaving in the queue
to try later.");
msgprops.closeReader();
msg.delete();
continue;
}
if (isDupe) {
- System.out.println("Got a message, but we've
already logged that message ID as received. Discarding.");
+ Logger.normal(this,"Got a message, but we've
already logged that message ID as received. Discarding.");
sm.slotUsed();
msgprops.closeReader();
msg.delete();
@@ -155,7 +156,7 @@
BufferedReader br = msgprops.getReader();
if (br == null) {
- System.out.println("Got an invalid message.
Discarding.");
+ Logger.normal(this,"Got an invalid message.
Discarding.");
sm.slotUsed();
msgprops.closeReader();
msg.delete();
@@ -169,21 +170,21 @@
msg.delete();
continue;
} catch (ConnectionTerminatedException cte) {
- // teminated before we could validate the
sender. Give up, and we won't mark the slot used so we'll
+ // terminated before we could validate the
sender. Give up, and we won't mark the slot used so we'll
// pick it up next time.
return;
}
- System.out.println("You've got mail!");
+ Logger.normal(this,"You've got mail!");
sm.slotUsed();
try {
msglog.add(id);
} catch (IOException ioe) {
// how should we handle this? Remove the message
from the inbox again?
- System.out.println("warning: failed to write log
file!");
+ Logger.normal(this,"warning: failed to write log
file!");
}
String ack_key = this.ibct_props.get("ackssk");
if (ack_key == null) {
- System.out.println("Warning! Can't send message
acknowledgement - don't have an 'ackssk' entry! This message will eventually
bounce, even though you've received it.");
+ Logger.normal(this,"Warning! Can't send message
acknowledgement - don't have an 'ackssk' entry! This message will eventually
bounce, even though you've received it.");
continue;
}
ack_key += "ack-"+id;
@@ -207,7 +208,7 @@
// quick sanity check
if (sd.indexOf("\r") > 0 || sd.indexOf("\n") > 0)
return false;
- System.out.println("Attempting to fetch sender's
mailsite to validate From address...");
+ Logger.normal("Attempting to fetch sender's mailsite to
validate From address...");
File result =
cli.fetch("KSK@"+sd+MailSite.ALIAS_SUFFIX);
if (result == null) {
@@ -215,10 +216,10 @@
// network connection is healthy, and the
mailsite
// ought to be easily retrievable, so fail.
// If this proves to be an issue, change it.
- System.out.println("Failed to fetch sender's
mailsite. Sender's From address therefore not valid.");
+ Logger.normal("Failed to fetch sender's
mailsite. Sender's From address therefore not valid.");
return false;
}
- System.out.println("Fetched sender's mailsite");
+ Logger.normal("Fetched sender's mailsite");
if (result.length() > 512) {
result.delete();
return false;
Modified: trunk/apps/Freemail/src/freemail/OutboundContact.java
===================================================================
--- trunk/apps/Freemail/src/freemail/OutboundContact.java 2007-11-22
19:44:49 UTC (rev 15928)
+++ trunk/apps/Freemail/src/freemail/OutboundContact.java 2007-11-22
20:24:44 UTC (rev 15929)
@@ -42,6 +42,7 @@
import freemail.fcp.FCPBadFileException;
import freemail.fcp.SSKKeyPair;
import freemail.fcp.ConnectionTerminatedException;
+import freemail.utils.Logger;
import org.archive.util.Base32;
@@ -155,11 +156,11 @@
HighLevelFCPClient fcpcli = new HighLevelFCPClient();
- System.out.println("polling for CTS message: "+ctskey);
+ Logger.minor(this,"polling for CTS message: "+ctskey);
File cts = fcpcli.fetch(ctskey);
if (cts == null) {
- System.out.println("CTS not received");
+ Logger.minor(this,"CTS not received");
// haven't got the CTS message. should we give
up yet?
String senttime =
this.contactfile.get("rts-sent-at");
@@ -169,7 +170,7 @@
}
} else {
- System.out.println("Sucessfully received CTS
for "+this.address.getSubDomain());
+ Logger.normal(this,"Sucessfully received CTS
for "+this.address.getSubDomain());
cts.delete();
this.contactfile.put("status", "cts-received");
// delete initial slot for forward secrecy
@@ -321,7 +322,7 @@
rtsmessage.append("mailsite="+our_mailsite_uri+"\r\n");
rtsmessage.append("\r\n");
- //System.out.println(rtsmessage.toString());
+ //FreemailLogger.normal(this,rtsmessage.toString());
// sign the message
SHA256Digest sha256 = new SHA256Digest();
@@ -358,7 +359,7 @@
if (aescipher.getBlockSize() != AES_BLOCK_LENGTH) {
// bouncycastle must have changed their implementation,
so
// we're in trouble
- System.out.println("Incompatible block size change
detected in cryptography API! Are you using a newer version of the bouncycastle
libraries? If so, we suggest you downgrade for now, or check for a newer
version of Freemail.");
+ Logger.normal(this,"Incompatible block size change
detected in cryptography API! Are you using a newer version of the bouncycastle
libraries? If so, we suggest you downgrade for now, or check for a newer
version of Freemail.");
return false;
}
@@ -413,16 +414,16 @@
private String fetchKSKRedirect(String key) throws
OutboundContactFatalException, ConnectionTerminatedException {
HighLevelFCPClient cli = new HighLevelFCPClient();
- System.out.println("Attempting to fetch mailsite redirect
"+key);
+ Logger.normal(this,"Attempting to fetch mailsite redirect
"+key);
File result = cli.fetch(key);
if (result == null) {
- System.out.println("Failed to retrieve mailsite
redirect "+key);
+ Logger.normal(this,"Failed to retrieve mailsite
redirect "+key);
return null;
}
if (result.length() > 512) {
- System.out.println("Fatal: mailsite redirect too long.
Ignoring.");
+ Logger.normal(this,"Fatal: mailsite redirect too long.
Ignoring.");
result.delete();
throw new OutboundContactFatalException("Mailsite
redirect too long.");
}
@@ -439,7 +440,7 @@
addr = br.readLine();
br.close();
} catch (IOException ioe) {
- System.out.println("Warning: IO exception whilst
reading mailsite redirect file: "+ioe.getMessage());
+ Logger.normal(this,"Warning: IO exception whilst
reading mailsite redirect file: "+ioe.getMessage());
return null;
}
result.delete();
@@ -449,15 +450,15 @@
private boolean fetchMailSite() throws OutboundContactFatalException,
ConnectionTerminatedException {
HighLevelFCPClient cli = new HighLevelFCPClient();
- System.out.println("Attempting to fetch
"+this.address.getMailpageKey());
+ Logger.normal(this,"Attempting to fetch
"+this.address.getMailpageKey());
File mailsite_file = cli.fetch(this.address.getMailpageKey());
if (mailsite_file == null) {
- System.out.println("Failed to retrieve mailsite
"+this.address.getMailpageKey());
+ Logger.normal(this,"Failed to retrieve mailsite
"+this.address.getMailpageKey());
return false;
}
- System.out.println("got mailsite");
+ Logger.normal(this,"got mailsite");
PropsFile mailsite = new PropsFile(mailsite_file);
@@ -469,7 +470,7 @@
if (rtsksk == null || keymod_str == null || keyexp_str == null)
{
// TODO: More failure mechanisms - this is fatal.
- System.out.println("Mailsite for "+this.address+" does
not contain all necessary information!");
+ Logger.normal(this,"Mailsite for "+this.address+" does
not contain all necessary information!");
throw new OutboundContactFatalException("Mailsite for
"+this.address+" does not contain all necessary information!");
}
@@ -522,7 +523,7 @@
pw = new PrintWriter(new FileOutputStream(msg));
} catch (IOException ioe) {
- System.out.println("IO Error encountered whilst trying
to send message: "+ioe.getMessage()+" Will try again soon");
+ Logger.normal(this,"IO Error encountered whilst trying
to send message: "+ioe.getMessage()+" Will try again soon");
return false;
}
@@ -546,7 +547,7 @@
pw.close();
br.close();
} catch (IOException ioe) {
- System.out.println("IO Error encountered whilst trying
to send message: "+ioe.getMessage()+" Will try again soon");
+ Logger.normal(this,"IO Error encountered whilst trying
to send message: "+ioe.getMessage()+" Will try again soon");
qm.delete();
msg.delete();
return false;
@@ -612,7 +613,7 @@
String key = this.contactfile.get("commssk.privkey");
if (key == null) {
- System.out.println("Contact file does not
contain private communication key! It appears that your Freemail directory is
corrupt!");
+ Logger.normal(this,"Contact file does not
contain private communication key! It appears that your Freemail directory is
corrupt!");
continue;
}
@@ -625,27 +626,27 @@
continue;
}
- System.out.println("Inserting message to "+key);
+ Logger.normal(this,"Inserting message to "+key);
FCPInsertErrorMessage err;
try {
err = fcpcli.put(fis, key);
} catch (FCPBadFileException bfe) {
- System.out.println("Failed sending message.
Will try again soon.");
+ Logger.normal(this,"Failed sending message.
Will try again soon.");
continue;
}
if (err == null) {
- System.out.println("Successfully inserted
"+key);
+ Logger.normal(this,"Successfully inserted
"+key);
if (msgs[i].first_send_time < 0)
msgs[i].first_send_time =
System.currentTimeMillis();
msgs[i].last_send_time =
System.currentTimeMillis();
msgs[i].saveProps();
} else if (msgs[i].added_time + FAIL_DELAY <
System.currentTimeMillis()) {
- System.out.println("Giving up on a message -
been trying to send for too long. Bouncing.");
+ Logger.normal(this,"Giving up on a message -
been trying to send for too long. Bouncing.");
if
(Postman.bounceMessage(msgs[i].getMessageFile(), new
MessageBank(this.accdir.getName()), "Freemail has been trying to deliver this
message for too long without success. This is likley to be due to a poor
connection to Freenet. Check your Freenet node.", true)) {
msgs[i].delete();
}
} else {
- System.out.println("Failed to insert "+key+"
will try again soon.");
+ Logger.normal(this,"Failed to insert "+key+"
will try again soon.");
}
}
}
@@ -663,17 +664,17 @@
String key = this.contactfile.get("ackssk.pubkey");
if (key == null) {
- System.out.println("Contact file does not
contain public ack key! It appears that your Freemail directory is corrupt!");
+ Logger.normal(this,"Contact file does not
contain public ack key! It appears that your Freemail directory is corrupt!");
continue;
}
key += "ack-"+msgs[i].uid;
- System.out.println("Looking for message ack on "+key);
+ Logger.minor(this,"Looking for message ack on "+key);
File ack = fcpcli.fetch(key);
if (ack != null) {
- System.out.println("Ack received for message
"+msgs[i].uid+" on contact "+this.address.domain+". Now that's a job well
done.");
+ Logger.normal(this,"Ack received for message
"+msgs[i].uid+" on contact "+this.address.domain+". Now that's a job well
done.");
ack.delete();
msgs[i].delete();
// treat the ACK as a CTS too
@@ -681,13 +682,13 @@
// delete initial slot for forward secrecy
this.contactfile.remove("initialslot");
} else {
- System.out.println("Failed to receive ack on
"+key);
+ Logger.minor(this,"Failed to receive ack on
"+key);
if (System.currentTimeMillis() >
msgs[i].first_send_time + FAIL_DELAY) {
// give up and bounce the message
File m = msgs[i].getMessageFile();
Postman.bounceMessage(m, new
MessageBank(this.accdir.getName()), "Freemail has been trying for too long to
deliver this message, and has received no acknowledgement. It is possible that
the recipient has not run Freemail since you sent the message. If you believe
this is likely, try resending the message.", true);
- System.out.println("Giving up on
message - been trying for too long.");
+ Logger.normal(this,"Giving up on
message - been trying for too long.");
msgs[i].delete();
} else if (System.currentTimeMillis() >
msgs[i].last_send_time + RETRANSMIT_DELAY) {
// no ack yet - retransmit on another
slot
@@ -713,7 +714,7 @@
uid = Integer.parseInt(files[i].getName());
} catch (NumberFormatException nfe) {
// how did that get there? just delete it
- System.out.println("Found spurious file in send
queue - deleting.");
+ Logger.normal(this,"Found spurious file in send
queue - deleting.");
files[i].delete();
msgs[i] = null;
continue;
Modified: trunk/apps/Freemail/src/freemail/RTSFetcher.java
===================================================================
--- trunk/apps/Freemail/src/freemail/RTSFetcher.java 2007-11-22 19:44:49 UTC
(rev 15928)
+++ trunk/apps/Freemail/src/freemail/RTSFetcher.java 2007-11-22 20:24:44 UTC
(rev 15929)
@@ -25,6 +25,7 @@
import freemail.fcp.ConnectionTerminatedException;
import freemail.utils.DateStringFactory;
import freemail.utils.PropsFile;
+import freemail.utils.Logger;
import java.io.File;
import java.io.FileInputStream;
@@ -101,7 +102,7 @@
}
tries++;
if (tries > RTS_MAX_ATTEMPTS) {
- System.out.println("Maximum attempts at
handling RTS reached - deleting RTS");
+ Logger.normal(this,"Maximum attempts at
handling RTS reached - deleting RTS");
files[i].delete();
} else {
File newname = new
File(this.contact_dir, parts[0] + "," + tries);
@@ -156,12 +157,12 @@
int slot;
while ( (slot = sm.getNextSlotNat()) > 0) {
- System.out.println("trying to fetch "+keybase+slot);
+ Logger.minor(this,"trying to fetch "+keybase+slot);
File result = fcpcli.fetch(keybase+slot);
if (result != null) {
- System.out.println(keybase+slot+": got RTS!");
+ Logger.normal(this,keybase+slot+": got RTS!");
File rts_dest = new File(this.contact_dir,
RTS_UNPROC_PREFIX + "-" + log.getAndIncUnprocNextId()+",0");
@@ -171,7 +172,7 @@
sm.slotUsed();
}
} else {
- System.out.println(keybase+slot+": no RTS.");
+ Logger.minor(this,keybase+slot+": no RTS.");
}
}
}
@@ -187,7 +188,7 @@
if (!rtsmessage.exists()) return false;
if (rtsmessage.length() > RTS_MAX_SIZE) {
- System.out.println("RTS Message is too large -
discarding!");
+ Logger.normal(this,"RTS Message is too large -
discarding!");
return true;
}
@@ -196,10 +197,10 @@
try {
plaintext = decrypt_rts(rtsmessage);
} catch (IOException ioe) {
- System.out.println("Error reading RTS message!");
+ Logger.normal(this,"Error reading RTS message!");
return false;
} catch (InvalidCipherTextException icte) {
- System.out.println("Could not decrypt RTS message -
discarding."+icte.getMessage());
+ Logger.normal(this,"Could not decrypt RTS message -
discarding."+icte.getMessage());
return true;
}
@@ -218,14 +219,14 @@
try {
line = lis.readLine(200, 200, false);
} catch (TooLongException tle) {
- System.out.println("RTS message has
lines that are too long. Discarding.");
+ Logger.normal(this,"RTS message has
lines that are too long. Discarding.");
rtsfile.delete();
return true;
}
messagebytes += lis.getLastBytesRead();
if (line == null || line.equals("")) break;
- //System.out.println(line);
+ //FreemailLogger.normal(this,line);
ps.println(line);
}
@@ -235,7 +236,7 @@
if (line == null) {
// that's not right, we shouldn't have reached
the end of the file, just the blank line before the signature
- System.out.println("Couldn't find signature on
RTS message - ignoring!");
+ Logger.normal(this,"Couldn't find signature on
RTS message - ignoring!");
rtsfile.delete();
return true;
}
@@ -257,7 +258,7 @@
bis.close();
} catch (IOException ioe) {
- System.out.println("IO error whilst handling RTS
message. "+ioe.getMessage());
+ Logger.normal(this,"IO error whilst handling RTS
message. "+ioe.getMessage());
ioe.printStackTrace();
if (rtsfile != null) rtsfile.delete();
return false;
@@ -268,7 +269,7 @@
try {
validate_rts(rtsprops);
} catch (Exception e) {
- System.out.println("RTS message does not contain vital
information: "+e.getMessage()+" - discarding");
+ Logger.normal(this,"RTS message does not contain vital
information: "+e.getMessage()+" - discarding");
rtsfile.delete();
return true;
}
@@ -287,7 +288,7 @@
try {
their_mailsite_furi = new
FreenetURI(their_mailsite_raw);
} catch (MalformedURLException mfue) {
- System.out.println("Mailsite in the RTS message is not
a valid Freenet URI. Discarding RTS message.");
+ Logger.normal(this,"Mailsite in the RTS message is not
a valid Freenet URI. Discarding RTS message.");
rtsfile.delete();
return true;
}
@@ -300,7 +301,7 @@
their_mailsite +=
AccountManager.MAILSITE_VERSION+"/"+MailSite.MAILPAGE;
- System.out.println("Trying to fetch sender's mailsite:
"+their_mailsite);
+ Logger.normal(this,"Trying to fetch sender's mailsite:
"+their_mailsite);
File msfile = fcpcli.fetch(their_mailsite);
if (msfile == null) {
@@ -314,7 +315,7 @@
String their_modulus = mailsite.get("asymkey.modulus");
if (their_exponent == null || their_modulus == null) {
- System.out.println("Mailsite fetched successfully but
missing vital information! Discarding this RTS.");
+ Logger.normal(this,"Mailsite fetched successfully but
missing vital information! Discarding this RTS.");
msfile.delete();
rtsfile.delete();
return true;
@@ -328,7 +329,7 @@
try {
their_hash =
deccipher.processBlock(their_encrypted_sig, 0, deccipher.getInputBlockSize());
} catch (InvalidCipherTextException icte) {
- System.out.println("It was not possible to decrypt the
signature of this RTS message. Discarding the RTS message.");
+ Logger.normal(this,"It was not possible to decrypt the
signature of this RTS message. Discarding the RTS message.");
msfile.delete();
rtsfile.delete();
return true;
@@ -337,7 +338,7 @@
// finally we can now check that our hash and their hash
// match!
if (their_hash.length < our_hash.length) {
- System.out.println("The signature of the RTS message is
not valid (our hash: "+our_hash.length+"bytes, their hash:
"+their_hash.length+"bytes. Discarding the RTS message.");
+ Logger.normal(this,"The signature of the RTS message is
not valid (our hash: "+our_hash.length+"bytes, their hash:
"+their_hash.length+"bytes. Discarding the RTS message.");
msfile.delete();
rtsfile.delete();
return true;
@@ -345,20 +346,20 @@
int i;
for (i = 0; i < our_hash.length; i++) {
if (their_hash[i] != our_hash[i]) {
- System.out.println("The signature of the RTS
message is not valid. Discarding the RTS message.");
+ Logger.normal(this,"The signature of the RTS
message is not valid. Discarding the RTS message.");
msfile.delete();
rtsfile.delete();
return true;
}
}
- System.out.println("Signature valid :)");
+ Logger.normal(this,"Signature valid :)");
// the signature is valid! Hooray!
// Now verify the message is for us
String our_mailsite_keybody;
try {
our_mailsite_keybody = new
FreenetURI(this.accprops.get("mailsite.pubkey")).getKeyBody();
} catch (MalformedURLException mfue) {
- System.out.println("Local mailsite URI is invalid!
Corrupt account file?");
+ Logger.normal(this,"Local mailsite URI is invalid!
Corrupt account file?");
msfile.delete();
rtsfile.delete();
return false;
@@ -376,13 +377,13 @@
String our_subdomain =
Base32.encode(mailsite_furi.getKeyBody().getBytes());
if (!rtsprops.get("to").equalsIgnoreCase(our_subdomain) &&
our_domain_alias != null && !rtsprops.get("to").equals(our_domain_alias)) {
- System.out.println("Recieved an RTS message that was
not intended for the recipient. Discarding.");
+ Logger.normal(this,"Recieved an RTS message that was
not intended for the recipient. Discarding.");
msfile.delete();
rtsfile.delete();
return true;
}
- System.out.println("Original message intended for us :)");
+ Logger.normal(this,"Original message intended for us :)");
// create the inbound contact
InboundContact ibct = new InboundContact(this.contact_dir,
their_mailsite_furi);
@@ -399,7 +400,7 @@
msfile.delete();
rtsfile.delete();
- System.out.println("Inbound contact created!");
+ Logger.normal(this,"Inbound contact created!");
return true;
}
Added: trunk/apps/Freemail/src/freemail/utils/Logger.java
===================================================================
--- trunk/apps/Freemail/src/freemail/utils/Logger.java
(rev 0)
+++ trunk/apps/Freemail/src/freemail/utils/Logger.java 2007-11-22 20:24:44 UTC
(rev 15929)
@@ -0,0 +1,47 @@
+/*
+ * Logger class for Freemail
+ *
+ * this is a first attempt at fixing the logging so that not everything
+ * is written to stdout. This class attempts to mimic the Logger class
+ * from Freenet, later we can probably use the class from Freenet without
+ * changing much except the import statement.
+ *
+ */
+
+package freemail.utils;
+
+public class Logger {
+
+ static final private int INTERNAL=1;
+ static final private int DEBUG=2;
+ static final private int MINOR=4;
+ static final private int NORMAL=8;
+ static final private int ERROR=16;
+
+ //static final private int loglevel=INTERNAL|DEBUG|MINOR|NORMAL|ERROR;
// everything
+ //static final private int loglevel=DEBUG|NORMAL|ERROR;
+ static final private int loglevel=NORMAL|ERROR; // should be ok for
normal users
+
+ static private void log(int l, Object t, String s, String level) {
+ if((l&loglevel)!=0) {
+
System.out.println(level+"("+t.getClass().getSimpleName()+"): "+s);
+ }
+ }
+
+ static public void minor(Object t, String s) {
+ log(MINOR,t,s,"MINOR");
+ }
+
+ static public void normal(Object t, String s) {
+ log(NORMAL,t,s,"NORMAL");
+ }
+
+ static public void error(Object t, String s) {
+ log(ERROR,t,s,"ERROR");
+ }
+
+ static public void debug(Object t, String s) {
+ log(DEBUG,t,s,"DEBUG");
+ }
+
+}