Changeset 176

Show
Ignore:
Timestamp:
02/26/06 15:36:02 (2 years ago)
Author:
dsandler
Message:

Integrate Pastry logging with FeedTree logging levels, in service of the
following tickets:

  • #37 couldn't create node factory
  • #40 problems joining the network ("Could not dispatch message ...")

There's now quite a bit of spaghetti in WebProxyClient.main() to do
this; perhaps the log configuration stuff should be factored into a separate
function for readability.

Additionally, the proxy now supports the -L (--logfile) flag, to
specify a file where all log messages should be written. This necessitated a
new LogHandler for the FeedTree logging, and as a result FeedTree logs
now go to System.out by default (instead of System.err). This closes ticket
#42.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • feedtree/trunk/src/net/feedtree/proxyapp/WebProxyClient.java

    r174 r176  
    13621362        boolean serveFeedsOnly = false; 
    13631363 
     1364        PrintStream logStream = System.out; 
     1365 
    13641366        List accessRules = new ArrayList(); 
    13651367 
     
    13761378                } catch (UnknownHostException exc) { 
    13771379                    System.out.println("error: address could not be resolved: " + hostSpec); 
     1380                    System.exit(1); 
     1381                } 
     1382            } else if (args[i].equals("--logfile") || args[i].equals("-L")) { 
     1383                try { 
     1384                    logStream = new PrintStream( 
     1385                            new FileOutputStream(args[++i], true /*append*/)); 
     1386                    logStream.print( 
     1387                            "=== Logging started " + new Date().toString() + " ===\n\n"); 
     1388                } catch (Exception exc) { 
     1389                    System.out.println("error: could not write to logfile: " + exc.toString()); 
    13781390                    System.exit(1); 
    13791391                } 
     
    14371449                System.out.println("usage: java -jar ftproxy.jar [flags]\n\n" 
    14381450                    + "flags:\n\n" 
     1451                    + "  -L/--logfile <file>\n" 
     1452                    + "       rediret all proxy output (see -v and -V flags) to\n" 
     1453                    + "       the specified file" 
    14391454                    + "  -g/--public\n" 
    14401455                    + "       allow HTTP connections from any host\n" 
     
    15351550        // We have to turn on log messages first thing, or we won't see  
    15361551        // anything on stdout 
    1537         Logger.global.setLevel(loggingLevel); 
    1538         Handler[] handlers = Logger.getLogger("").getHandlers(); 
     1552        Logger masterLogger = Logger.getLogger(""); 
     1553        Handler[] handlers = masterLogger.getHandlers(); 
    15391554        for(int i=0; i<handlers.length; i++) { 
    1540             handlers[i].setLevel(loggingLevel); 
    1541         } 
     1555            masterLogger.removeHandler(handlers[i]); 
     1556        } 
     1557        Handler logHandler  
     1558            = new StreamHandler(logStream, new SimpleFormatter()  
     1559                    /* 
     1560                     * fancy version of SimpleFormatter, for testing 
     1561                    { 
     1562                        public String format(LogRecord record) { 
     1563                            return "\033[1mLog:\033[0m "  
     1564                                + super.format(record); 
     1565                        } 
     1566                    } 
     1567                    */ 
     1568                    )  
     1569            { 
     1570                // Auto-flush version of StreamHandler 
     1571                public void publish(LogRecord record) { 
     1572                    super.publish(record); 
     1573                    flush(); 
     1574                } 
     1575            }; 
     1576        masterLogger.addHandler(logHandler); 
     1577        masterLogger.setLevel(loggingLevel); 
     1578        logHandler.setLevel(loggingLevel); 
    15421579         
    15431580        // Synchronize Pastry's logging situation with our own. 
     1581        rice.environment.params.Parameters pastryParams =  
     1582            new rice.environment.params.simple.SimpleParameters( 
     1583                rice.environment.Environment.defaultParamFileArray, null); 
    15441584        rice.environment.Environment pastryEnv  
    1545             = new rice.environment.Environment(); 
     1585            = new rice.environment.Environment( 
     1586                    null,  // SelectorManager 
     1587                    null,  // Processor 
     1588                    null,  // RandomSource 
     1589                    null,  // TimeSource 
     1590                    new rice.environment.logging.simple.SimpleLogManager( 
     1591                        logStream, pastryParams), 
     1592                    pastryParams 
     1593                ); 
    15461594        Client.setPastryEnvironment(pastryEnv); 
    15471595        int pastryLogLevel; 
     
    15641612        } 
    15651613        pastryEnv.getParameters().setInt("loglevel", pastryLogLevel); 
    1566  
     1614         
    15671615        // Let's start talking to the user. 
    15681616        Logger.global.info("Version: "