Show
Ignore:
Timestamp:
07/18/07 08:25:45 PM (18 months ago)
Author:
octorian
Message:

Initial logging code (#30)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/LogicMail/src/org/logicprobe/LogicMail/util/Connection.java

    r130 r134  
    4343 * receiving Internet mail messages using the SMTP and POP3 protocols. 
    4444 * 
    45  * Copyright (c) 2000-2002 Jrg Pleumann <joerg@pleumann.de> 
     45 * Copyright (c) 2000-2002 Jorg Pleumann <joerg@pleumann.de> 
    4646 * 
    4747 * Mail4ME is part of the EnhydraME family of projects. See the following web 
     
    6767import javax.microedition.io.StreamConnection; 
    6868import javax.microedition.io.Connector; 
     69import net.rim.device.api.system.EventLogger; 
     70import org.logicprobe.LogicMail.AppInfo; 
    6971 
    7072/** 
     
    102104     
    103105    /** 
    104      * If true, protocol debugging information is written to standard output. 
    105      */ 
    106     private boolean debug; 
    107      
    108     /** 
    109106     * Provides a buffer used for incoming data. 
    110107     */ 
     
    126123        this.useSSL = useSSL; 
    127124        this.deviceSide = deviceSide; 
    128         this.debug = false; 
    129125        this.input = null; 
    130126        this.output = null; 
     
    136132     */ 
    137133    public void open() throws IOException { 
    138         close(); 
     134        if(input != null || output != null || socket != null) { 
     135            close(); 
     136        } 
    139137 
    140138        synchronized(openConnections) { 
     
    150148        String connectStr = protocolStr + "://" + serverName + 
    151149                ":" + serverPort + paramStr; 
    152         if (debug) { 
    153             System.out.println("[OPEN] " + connectStr); 
    154         } 
     150         
     151        if(EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { 
     152            String msg = "Opening connection:\r\n"+connectStr+"\r\n"; 
     153            EventLogger.logEvent(AppInfo.GUID, msg.getBytes(), EventLogger.DEBUG_INFO); 
     154        } 
     155         
    155156        socket = (StreamConnection)Connector.open(connectStr, Connector.READ_WRITE, true); 
    156157        input = socket.openDataInputStream(); 
    157158        output = socket.openDataOutputStream(); 
    158159        localAddress = ((SocketConnection)socket).getLocalAddress(); 
     160 
     161        if(EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { 
     162            String msg = 
     163                "Connection established:\r\n"+ 
     164                "Input: "+input.getClass().toString()+"\r\n"+ 
     165                "Output: "+input.getClass().toString()+"\r\n"+ 
     166                "Local address: "+localAddress+"\r\n"; 
     167            EventLogger.logEvent(AppInfo.GUID, msg.getBytes(), EventLogger.DEBUG_INFO); 
     168        } 
    159169    } 
    160170     
     
    181191            } 
    182192        } 
     193         
     194        EventLogger.logEvent(AppInfo.GUID, "Connection closed".getBytes(), EventLogger.DEBUG_INFO); 
    183195    } 
    184196     
     
    255267         */ 
    256268        if (s.length() == 0) { 
    257             if (debug) { 
    258                 System.out.println("[SEND]"); 
    259             } 
     269            EventLogger.logEvent(AppInfo.GUID, "[SEND]".getBytes(), EventLogger.DEBUG_INFO); 
    260270             
    261271            output.write(CRLF, 0, 2); 
     
    277287                } 
    278288                 
    279                 if (debug) { 
    280                     System.out.println("[SEND] " + s.substring(i, j)); 
    281                 } 
     289                EventLogger.logEvent(AppInfo.GUID, ("[SEND] " + s.substring(i, j)).getBytes(), EventLogger.DEBUG_INFO); 
    282290                 
    283291                /** 
     
    297305            } 
    298306        } 
    299         output.flush(); // I can't believe this wasn't here before (DK) 
     307        output.flush(); 
    300308    } 
    301309     
     
    312320        int length = bytes.length; 
    313321         
    314         if (debug) { 
    315             System.out.println("[SEND] " + s); 
    316         } 
     322        EventLogger.logEvent(AppInfo.GUID, ("[SEND RAW]\r\n" + s).getBytes(), EventLogger.DEBUG_INFO); 
    317323 
    318324        output.write(bytes, 0, bytes.length); 
     
    386392                    try { 
    387393                        close(); 
    388                     } catch (IOException ignored) { 
    389                     } 
     394                    } catch (IOException e) { } 
    390395                     
    391396                    throw new IOException("Connection closed"); 
     
    399404                    try { 
    400405                        Thread.yield(); 
    401                     } catch (Exception ignored) { 
    402                     } 
     406                    } catch (Exception e) { } 
    403407                } 
    404408                 
     
    439443        } 
    440444         
    441         if (debug) { 
    442             System.out.println("[RECV] " + resultBuffer.toString()); 
    443         } 
     445        EventLogger.logEvent(AppInfo.GUID, ("[RECV] " + resultBuffer.toString()).getBytes(), EventLogger.DEBUG_INFO); 
    444446         
    445447        return resultBuffer.toString(); 
    446448    } 
    447      
    448     /** 
    449      * Controls the output of debugging information to standard output. Set it to 
    450      * true to see all protocol information exchanged. 
    451      * 
    452      * @see #getDebug 
    453      */ 
    454     public void setDebug(boolean debug) { 
    455         this.debug = debug; 
    456     } 
    457      
    458     /** 
    459      * Queries the current value of the debugging flag. 
    460      * 
    461      * @see #setDebug 
    462      */ 
    463     public boolean getDebug() { 
    464         return debug; 
    465     } 
    466449} 
    467450