Example #1
0
        public static void MinimalSetup()
        {
            Properties props = new Properties();

            props.SetProperty("log.output", "stderr");
            RedwoodConfiguration.Apply(props);
        }
 public _FileHandler_202(RedwoodConfiguration config, string baseArg1)
     : base(baseArg1)
 {
     this.config = config;
     {
         this.leftMargin = config.channelWidth;
     }
 }
 public void Apply(RedwoodConfiguration config, Redwood.RecordHandlerTree root)
 {
     if (handlers.Length == 0)
     {
         destination.Apply(config, root);
     }
     else
     {
         root.AddChildTree(this.BuildChain(config, handlers, 0));
     }
 }
 private Redwood.RecordHandlerTree BuildChain(RedwoodConfiguration config, LogRecordHandler[] handlers, int i)
 {
     Redwood.RecordHandlerTree rtn = new Redwood.RecordHandlerTree(handlers[i]);
     if (i < handlers.Length - 1)
     {
         rtn.AddChildTree(this.BuildChain(config, handlers, i + 1));
     }
     else
     {
         destination.Apply(config, rtn);
     }
     return(rtn);
 }
        /// <summary>Run Redwood with SLF4J if available, otherwise with stderr logging at the error only level.</summary>
        /// <returns>
        /// A redwood configuration. Remember to call
        /// <see cref="Apply()"/>
        /// .
        /// </returns>
        public static RedwoodConfiguration ErrorLevel()
        {
            RedwoodConfiguration config;

            try
            {
                MetaClass.Create("org.slf4j.LoggerFactory").CreateInstance();
                config = new RedwoodConfiguration().Clear().Handlers(RedwoodConfiguration.Handlers.Chain(RedwoodConfiguration.Handlers.showOnlyError, RedwoodConfiguration.Handlers.slf4j));
            }
            catch (Exception)
            {
                config = new RedwoodConfiguration().Clear().Handlers(RedwoodConfiguration.Handlers.Chain(RedwoodConfiguration.Handlers.showOnlyError, RedwoodConfiguration.Handlers.stderr));
            }
            return(config);
        }
Example #6
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();
 }
        /// <summary>Configure Redwood (from scratch) based on a Properties file.</summary>
        /// <remarks>
        /// Configure Redwood (from scratch) based on a Properties file.
        /// Currently recognized properties are:
        /// <ul>
        /// <li>log.captureStreams = {true,false}: Capture stdout and stderr and route them through Redwood</li>
        /// <li>log.captureStdout = {true,false}: Capture stdout and route it through Redwood</li>
        /// <li>log.captureStderr = {true,false}: Capture stdout and route it through Redwood</li>
        /// <li>log.channels.width = {number}: Show the channels being logged to, at this width (default: 0; recommended: 20)</li>
        /// <li>log.channels.debug = {true,false}: Show the debugging channel</li>
        /// <li>log.file = By default, write to this file.
        /// <li>log.neatExit = {true,false}: Clean up logs on exception or regular system exit</li>
        /// <li>log.output = {stderr,stdout,java.util.logging}: Output messages to either stderr or stdout by default.</li>
        /// </ul>
        /// </remarks>
        /// <param name="props">The properties to use in configuration</param>
        /// <returns>A new Redwood Configuration based on the passed properties, ignoring any existing custom configuration</returns>
        public static RedwoodConfiguration Parse(Properties props)
        {
            RedwoodConfiguration config = new RedwoodConfiguration().Clear();
            ICollection <string> used   = Generics.NewHashSet();

            //--Capture Streams
            if (Sharpen.Runtime.EqualsIgnoreCase(Get(props, "log.captureStreams", "false", used), "true"))
            {
                config = config.Capture(System.Console.Out).Capture(System.Console.Error);
            }
            if (Sharpen.Runtime.EqualsIgnoreCase(Get(props, "log.captureStdout", "false", used), "true"))
            {
                config = config.Capture(System.Console.Out);
            }
            if (Sharpen.Runtime.EqualsIgnoreCase(Get(props, "log.captureStderr", "false", used), "true"))
            {
                config = config.Capture(System.Console.Error);
            }
            //--Collapse
            string collapse = Get(props, "log.collapse", "none", used);
            IList <LogRecordHandler> chain = new LinkedList <LogRecordHandler>();

            if (Sharpen.Runtime.EqualsIgnoreCase(collapse, "exact"))
            {
                chain.Add(new RepeatedRecordHandler(RepeatedRecordHandler.Exact));
            }
            else
            {
                if (Sharpen.Runtime.EqualsIgnoreCase(collapse, "approximate"))
                {
                    chain.Add(new RepeatedRecordHandler(RepeatedRecordHandler.Approximate));
                }
                else
                {
                    if (!Sharpen.Runtime.EqualsIgnoreCase(collapse, "none"))
                    {
                        throw new ArgumentException("Unknown collapse mode (Redwood): " + collapse);
                    }
                }
            }
            //--Channels.Debug
            bool debug = bool.Parse(Get(props, "log.channels.debug", "true", used));

            if (!debug)
            {
                chain.Add(RedwoodConfiguration.Handlers.hideDebug);
            }
            //--Channels.Width
            config.ChannelWidth(System.Convert.ToInt32(Get(props, "log.channels.width", "0", used)));
            //--Neat exit
            if (Sharpen.Runtime.EqualsIgnoreCase(Get(props, "log.neatExit", "false", used), "true"))
            {
                config = config.NeatExit();
            }
            //--File
            string outputFile = Get(props, "log.file", null, used);

            if (outputFile != null)
            {
                config.defaultFile = new Java.IO.File(outputFile);
                config             = config.Handlers(RedwoodConfiguration.Handlers.defaultFile);
            }
            //--Console
            config = config.Output(Get(props, "log.output", "stdout", used));
            //--Console
            config = config.Handlers(RedwoodConfiguration.Handlers.Chain(Sharpen.Collections.ToArray(chain, new LogRecordHandler[chain.Count]), RedwoodConfiguration.Handlers.output));
            //--Error Check
            foreach (object propAsObj in props.Keys)
            {
                string prop = propAsObj.ToString();
                if (prop.StartsWith("log.") && !used.Contains(prop))
                {
                    throw new ArgumentException("Could not find Redwood log property: " + prop);
                }
            }
            //--Return
            return(config);
        }
 public void Apply(RedwoodConfiguration config, Redwood.RecordHandlerTree root)
 {
     root.AddChild(new _FileHandler_202(config, config.defaultFile.GetPath()));
 }
 public void Apply(RedwoodConfiguration config, Redwood.RecordHandlerTree root)
 {
     root.AddChild(new _FileHandler_185(config, path));
 }