/// <summary>Determine where, in the end, console output should go.</summary>
 /// <remarks>
 /// Determine where, in the end, console output should go.
 /// The default is stdout.
 /// </remarks>
 /// <param name="method">An output, one of: stdout, stderr, or java.util.logging</param>
 /// <returns>this</returns>
 public virtual Edu.Stanford.Nlp.Util.Logging.RedwoodConfiguration Output(string method)
 {
     if (Sharpen.Runtime.EqualsIgnoreCase(method, "stdout") || Sharpen.Runtime.EqualsIgnoreCase(method, "out"))
     {
         JavaUtilLoggingAdaptor.Adapt();
         this.outputHandler = Redwood.ConsoleHandler.Out();
     }
     else
     {
         if (Sharpen.Runtime.EqualsIgnoreCase(method, "stderr") || Sharpen.Runtime.EqualsIgnoreCase(method, "err"))
         {
             JavaUtilLoggingAdaptor.Adapt();
             this.outputHandler = Redwood.ConsoleHandler.Err();
         }
         else
         {
             if (Sharpen.Runtime.EqualsIgnoreCase(method, "java.util.logging"))
             {
                 JavaUtilLoggingAdaptor.Adapt();
                 this.outputHandler = RedirectOutputHandler.FromJavaUtilLogging(Logger.GetLogger("``error``"));
             }
             else
             {
                 throw new ArgumentException("Unknown value for log.method");
             }
         }
     }
     return(this);
 }
 /// <summary>Simple test case.</summary>
 public static void Main(string[] args)
 {
     if (args.Length > 0 && args[0].Equals("redwood"))
     {
         Redwood.Log(Redwood.Dbg, "at the top");
         Redwood.StartTrack("Adaptor test controlled by redwood");
         Logger topLogger = Logger.GetLogger(Logger.GlobalLoggerName);
         topLogger.Warning("I'm warning you!");
         topLogger.Severe("Now I'm using my severe voice.");
         topLogger.Info("FYI");
         Redwood.Log(Redwood.Dbg, "adapting");
         JavaUtilLoggingAdaptor.Adapt();
         topLogger.Warning("I'm warning you in Redwood!");
         JavaUtilLoggingAdaptor.Adapt();
         // should be safe to call this twice
         topLogger.Severe("Now I'm using my severe voice in Redwood!");
         topLogger.Info("FYI: Redwood rocks");
         // make sure original java.util.logging levels are respected
         topLogger.SetLevel(Level.Off);
         topLogger.Severe("We shouldn't see this message.");
         Redwood.Log(Redwood.Dbg, "at the bottom");
         Redwood.EndTrack("Adaptor test controlled by redwood");
     }
     else
     {
         // Reverse mapping
         Logger topLogger = Logger.GetLogger(Logger.GlobalLoggerName);
         // Can be Logger.getGlobal() in jdk1.7
         // topLogger.addHandler(new ConsoleHandler());
         Logger logger = Logger.GetLogger(typeof(JavaUtilLoggingAdaptor).FullName);
         topLogger.Info("Starting test");
         logger.Log(Level.Info, "Hello from the class logger");
         Redwood.Log("Hello from Redwood!");
         Redwood.RootHandler().AddChild(RedirectOutputHandler.FromJavaUtilLogging(topLogger));
         Redwood.Log("Hello from Redwood -> Java!");
         Redwood.Log("Hello from Redwood -> Java again!");
         logger.Log(Level.Info, "Hello again from the class logger");
         Redwood.StartTrack("a track");
         Redwood.Log("Inside a track");
         logger.Log(Level.Info, "Hello a third time from the class logger");
         Redwood.EndTrack("a track");
         logger.Log(Level.Info, "Hello a fourth time from the class logger");
     }
 }
Пример #3
0
 /// <summary>
 /// Configures the Redwood logger using a reasonable set of defaults,
 /// which can be overruled by the supplied Properties file.
 /// </summary>
 /// <param name="props">The properties file to overrule or augment the default configuration</param>
 public static void Apply(Properties props)
 {
     //--Tweak Properties
     //(output to stderr)
     if (props.GetProperty("log.output") == null)
     {
         props.SetProperty("log.output", "stderr");
     }
     //(capture system streams)
     if (props.GetProperty("log.captureStderr") == null)
     {
         props.SetProperty("log.captureStderr", "true");
     }
     //(apply properties)
     RedwoodConfiguration.Apply(props);
     //--Strange Tweaks
     //(adapt legacy logging systems)
     JavaUtilLoggingAdaptor.Adapt();
 }