pgRouting

Changeset 96

Show
Ignore:
Timestamp:
01/18/08 16:03:38 (11 months ago)
Author:
Matthieu
Message:

Updated Log class

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/routingservice/configuration.xml

    r94 r96  
    22<restlet> 
    33        <port>8182</port> 
    4         <log>./log/access.log</log> 
     4        <log mode="0">./log/access.log</log> 
    55        <localhost>http://localhost</localhost> 
    66        <css>http://localhost/demo/css/style.css</css> 
  • branches/routingservice/src/jp/co/orkney/restlet/geo/ClosestEdge.java

    r94 r96  
    2222 
    2323import jp.co.orkney.restlet.util.IOHelper; 
     24import jp.co.orkney.restlet.util.Log; 
    2425import jp.co.orkney.restlet.util.Point; 
    2526import jp.co.orkney.restlet.util.Configuration; 
     
    5758        private Point point; 
    5859        private Configuration configuration; 
     60        private Log log; 
    5961 
    6062        /** 
     
    7274        { 
    7375                this.configuration = configuration; 
     76                this.log = configuration.createLog(); 
    7477                ioHelper = new IOHelper(configuration); 
    7578 
     
    140143                        query.setAttribute("sridOut", configuration.getService().getParameter("sridOutput").getValue()); 
    141144 
    142                         System.out.println(query.toString()); 
     145                        log.write(query.toString(),1); 
    143146                        ResultSet rs = databaseConnection.getResult(query.toString()); 
    144147 
  • branches/routingservice/src/jp/co/orkney/restlet/geo/DrivingDistance.java

    r95 r96  
    2727import jp.co.orkney.restlet.util.DatabaseConnection; 
    2828import jp.co.orkney.restlet.util.IOHelper; 
     29import jp.co.orkney.restlet.util.Log; 
    2930import jp.co.orkney.restlet.util.Point; 
    3031 
     
    6061        private int time; 
    6162        private int length; 
     63        private Log log; 
    6264         
    6365        /** 
     
    7577        { 
    7678                this.configuration = configuration; 
     79                this.log = configuration.createLog(); 
    7780                ioHelper = new IOHelper(configuration); 
    7881 
     
    177180                        query.setAttribute("sridOut", configuration.getService().getParameter("sridOutput").getValue()); 
    178181                         
    179                         System.out.println(query.toString()); 
     182                        log.write(query.toString(),1); 
    180183                        ResultSet rs = databaseConnection.getResult(query.toString()); 
    181184 
  • branches/routingservice/src/jp/co/orkney/restlet/geo/ShortestPath.java

    r94 r96  
    2525 
    2626import jp.co.orkney.restlet.util.IOHelper; 
     27import jp.co.orkney.restlet.util.Log; 
    2728import jp.co.orkney.restlet.util.Point; 
    2829import jp.co.orkney.restlet.util.Configuration; 
     
    5859        private Point endPoint; 
    5960        private Configuration configuration; 
     61        private Log log; 
    6062 
    6163        /** 
    6264         * Constructor ShortestPath 
    6365         * <p> 
    64          * Creates a new ShortestPath object using the specified Configuration object 
     66         * Creates a new ShortestPath object using the specifieSystem.out.println(query.toString());d Configuration object 
    6567         * and extracts X and Y from the data provides by GET or POST request into a 
    6668         * new point (for start and end point). 
     
    7375        { 
    7476                this.configuration = configuration; 
     77                this.log = configuration.createLog(); 
    7578                ioHelper = new IOHelper(configuration); 
    7679 
     
    146149                        query.setAttribute("sridOut", configuration.getService().getParameter("sridOutput").getValue()); 
    147150 
    148                         System.out.println(query.toString()); 
     151                        log.write(query.toString(),1); 
    149152                        ResultSet rs = databaseConnection.getResult(query.toString()); 
    150153 
  • branches/routingservice/src/jp/co/orkney/restlet/util/Configuration.java

    r67 r96  
    6161        private String port; 
    6262        private String urlLog; 
     63        private int modeLog; 
    6364        private String localhost; 
    6465        private String urlCss; 
     
    8485                port = ""; 
    8586                urlLog = ""; 
     87                modeLog = 0; 
    8688                localhost = ""; 
    8789                urlCss = ""; 
     
    117119                port = root.getChild("port").getText(); 
    118120                urlLog = root.getChild("log").getText(); 
     121                modeLog = Integer.parseInt(root.getChild("log").getAttributeValue("mode")); 
    119122                localhost = root.getChild("localhost").getText(); 
    120123                urlCss = root.getChild("css").getText(); 
     
    282285        public Log createLog() 
    283286        { 
    284                 return new Log(urlLog); 
     287                return new Log(urlLog,modeLog); 
    285288        } 
    286289 
  • branches/routingservice/src/jp/co/orkney/restlet/util/DatabaseConnection.java

    r67 r96  
    7676        public void start() 
    7777        { 
    78                 log.write("Database connection started"); 
     78                log.write("Database connection started",1); 
    7979                try 
    8080                { 
     
    8989                { 
    9090                        start = false; 
    91                         log.write("--ERROR: unkown driver"); 
     91                        log.write("--ERROR: unkown driver",0); 
    9292                } 
    9393                catch (SQLException e) 
    9494                { 
    9595                        start = false; 
    96                         log.write("--ERROR: Can not connect to the database"); 
     96                        log.write("--ERROR: Can not connect to the database",0); 
    9797                } 
    9898                start = true; 
     
    124124                catch (SQLException e1) 
    125125                { 
    126                         log.write("--ERROR: query execution failed"); 
    127                         e1.printStackTrace(); 
     126                        log.write("--ERROR: query execution failed",0); 
     127                        log.getStackTrace(e1); 
    128128                } 
    129129                return null; 
     
    140140                        statement.close(); 
    141141                        connection.close(); 
    142                         log.write("Database connection finished"); 
     142                        log.write("Database connection finished",1); 
    143143                } 
    144144                catch (SQLException e) 
    145145                { 
    146                         log.write("--ERROR: Can not close the connection"); 
     146                        log.write("--ERROR: Can not close the connection",0); 
    147147                } 
    148148        } 
  • branches/routingservice/src/jp/co/orkney/restlet/util/IOHelper.java

    r94 r96  
    8888                catch (JSONException e) 
    8989                { 
    90                         log.write("--ERROR: Can not extract X and Y from Json object"); 
     90                        log.write("--ERROR: Can not extract X and Y from Json object",0); 
    9191                } 
    9292 
     
    909909                catch (JSONException e) 
    910910                { 
    911                         log.write("*ERROR* getOpenLayersIdFromGEOJSON()"); 
     911                        log.write("*ERROR* getOpenLayersIdFromGEOJSON()",0); 
    912912                } 
    913913 
     
    936936                catch (Exception e) 
    937937                { 
    938                         log.write("*ERROR* getOpenLayersIdFromGML()"); 
     938                        log.write("*ERROR* getOpenLayersIdFromGML()",0); 
    939939                } 
    940940 
     
    963963                catch (Exception e) 
    964964                { 
    965                         log.write("*ERROR* getOpenLayersIdFromKML()"); 
     965                        log.write("*ERROR* getOpenLayersIdFromKML()",0); 
    966966                } 
    967967 
  • branches/routingservice/src/jp/co/orkney/restlet/util/Log.java

    r67 r96  
    4242{ 
    4343        private String file; 
     44        private int mode;// 0 default mode, 1: debug mode, 2: full mode 
    4445 
    4546        /** 
     
    5253         *            logs file's URL 
    5354         */ 
    54         public Log(String file
     55        public Log(String file, int mode
    5556        { 
    5657                this.file = file; 
     58                this.mode = mode; 
    5759        } 
    5860 
     
    6365         *            the string that is to be write in log file 
    6466         */ 
    65         public void write(String text
     67        public void write(String text, int mode
    6668        { 
    67                 try 
     69                if (this.mode >= mode) 
    6870                { 
    69                         FileWriter fileWriter = new FileWriter(file, true); 
    70                         BufferedWriter buffer = new BufferedWriter(fileWriter); 
    71                         Calendar calendar = Calendar.getInstance(); 
    72                         Date now = calendar.getTime(); 
    73                         String datelog = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, Locale.FRANCE).format(now); 
    74                         buffer.write("[" + datelog + "]: " + text); 
    75                         buffer.newLine(); 
    76                         buffer.close(); 
     71                        try 
     72                        { 
     73                                FileWriter fileWriter = new FileWriter(file, true); 
     74                                BufferedWriter buffer = new BufferedWriter(fileWriter); 
     75                                Calendar calendar = Calendar.getInstance(); 
     76                                Date now = calendar.getTime(); 
     77                                String datelog = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, Locale.FRANCE).format(now); 
     78                                buffer.write("[" + datelog + "]: " + text); 
     79                                buffer.newLine(); 
     80                                buffer.close(); 
     81                        } 
     82                        catch (IOException e) 
     83                        { 
     84                                System.out.println(e.getMessage()); 
     85                        } 
    7786                } 
    78                 catch (IOException e) 
     87        } 
     88 
     89        /** 
     90         * Writes the stack trace information of the exception 
     91         *  
     92         * @param e 
     93         *            exception 
     94         */ 
     95        public void getStackTrace(Exception e) 
     96        { 
     97                for (int i = 0; i < e.getStackTrace().length; i++) 
    7998                { 
    80                         System.out.println(e.getMessage()); 
     99                        this.write(e.getStackTrace()[i].toString(), 2); 
    81100                } 
    82101        } 
  • branches/routingservice/src/jp/co/orkney/restlet/WebRouting.java

    r94 r96  
    9090                        { 
    9191                                error = false; 
    92                                 log.write("Restlet HANDLE"); 
     92                                log.write("Restlet HANDLE",0); 
    9393 
    9494                                try 
     
    9898                                catch (Exception e1) 
    9999                                { 
    100                                         log.write("--ERROR: Wrong URL"); 
     100                                        log.write("--ERROR: Wrong URL",0); 
    101101                                        System.out.println(e1.getMessage()); 
    102102                                        error = true; 
     
    141141                                                catch (IOException e1) 
    142142                                                { 
    143                                                         log.write("--ERROR: Reading data failed"); 
     143                                                        log.write("--ERROR: Reading data failed",0); 
    144144                                                        error = true; 
    145145                                                } 
     
    157157                                                                catch (SQLException e) 
    158158                                                                { 
    159                                                                         log.write("--ERROR: Exception \"SQLException\" to draw the result"); 
     159                                                                        log.write("--ERROR: Exception \"SQLException\" to draw the result",0); 
     160                                                                        log.getStackTrace(e); 
    160161                                                                        error = true; 
    161162                                                                } 
    162163                                                                catch (JSONException e) 
    163164                                                                { 
    164                                                                         log.write("--ERROR: Exception \"JSONException\" to draw the result"); 
    165                                                                         error = true; 
    166                                                                 } 
    167                                                                 log.write("Closest Edge algorithm started"); 
     165                                                                        log.write("--ERROR: Exception \"JSONException\" to draw the result",0); 
     166                                                                        log.write(e.getMessage(),1); 
     167                                                                        error = true; 
     168                                                                } 
     169                                                                log.write("Closest Edge algorithm started",1); 
    168170                                                                result = closestEdge.get(); 
    169                                                                 log.write("Closest Edge algorithm finished"); 
     171                                                                log.write("Closest Edge algorithm finished",1); 
    170172                                                        } 
    171173                                                        else if (configuration.getService().getName().equals("shortest_path")) 
     
    178180                                                                catch (SQLException e) 
    179181                                                                { 
    180                                                                         log.write("--ERROR: Exception \"SQLException\" to draw the result"); 
     182                                                                        log.write("--ERROR: Exception \"SQLException\" to draw the result",0); 
     183                                                                        log.write(e.getMessage(),1); 
    181184                                                                        error = true; 
    182185                                                                } 
    183186                                                                catch (JSONException e) 
    184187                                                                { 
    185                                                                         log.write("--ERROR: Exception \"JSONException\" to draw the result"); 
    186                                                                         error = true; 
    187                                                                 } 
    188                                                                 log.write("Shortest Path algorithm started"); 
     188                                                                        log.write("--ERROR: Exception \"JSONException\" to draw the result",0); 
     189                                                                        log.write(e.getMessage(),1); 
     190                                                                        error = true; 
     191                                                                } 
     192                                                                log.write("Shortest Path algorithm started",1); 
    189193                                                                result = shortestPath.get(); 
    190                                                                 log.write("Shortest Path algorithm finished"); 
     194                                                                log.write("Shortest Path algorithm finished",1); 
    191195                                                        } 
    192196                                                        else if (configuration.getService().getName().equals("driving_distance")) 
     
    199203                                                                catch (SQLException e) 
    200204                                                                { 
    201                                                                         log.write("--ERROR: Exception \"SQLException\" to draw the result"); 
     205                                                                        log.write("--ERROR: Exception \"SQLException\" to draw the result",0); 
     206                                                                        log.write(e.getMessage(),1); 
    202207                                                                        error = true; 
    203208                                                                } 
    204209                                                                catch (JSONException e) 
    205210                                                                { 
    206                                                                         log.write("--ERROR: Exception \"JSONException\" to draw the result"); 
    207                                                                         error = true; 
    208                                                                 } 
    209                                                                 log.write("Shortest Path algorithm started"); 
     211                                                                        log.write("--ERROR: Exception \"JSONException\" to draw the result",0); 
     212                                                                        log.write(e.getMessage(),1); 
     213                                                                        error = true; 
     214                                                                } 
     215                                                                log.write("Driving Distance algorithm started",1); 
    210216                                                                result = drivingDistance.get(); 
    211                                                                 log.write("Shortest Path algorithm finished"); 
     217                                                                log.write("Driving Distance algorithm finished",1); 
    212218                                                        }// <-- FIN 
    213219