예제 #1
0
 private bool RecordVerdict(Redwood.Record r, bool isRepeat, bool shouldPrint, IList <Redwood.Record> willReturn)
 {
     if (r.Force())
     {
         FlushParents(willReturn);
         if (isRepeat)
         {
             Flush(current, willReturn);
         }
         //if not repeat, will flush below
         shouldPrint = true;
     }
     if (!isRepeat)
     {
         Flush(current, willReturn);
         current.lastRecord = r;
     }
     if (shouldPrint)
     {
         current.timeOfLastPrintedRecord = r.timesstamp;
         current.timesPrinted           += 1;
     }
     current.timesSeen       += 1;
     current.somethingPrinted = true;
     //(return)
     return(shouldPrint);
 }
예제 #2
0
        private void Flush(RepeatedRecordHandler.RepeatedRecordInfo info, IList <Redwood.Record> willReturn)
        {
            //(suppress all printing)
            if (info.suppressRecord)
            {
                return;
            }
            //(get time)
            int repeatedRecordCount = info.timesSeen - info.timesPrinted;

            if (repeatedRecordCount > 0)
            {
                //(send message record)
                //((add force tag))
                object[] newTags = new object[info.lastRecord.Channels().Length + 1];
                System.Array.Copy(info.lastRecord.Channels(), 0, newTags, 1, info.lastRecord.Channels().Length);
                newTags[0] = Redwood.Force;
                //((create record))
                Redwood.Record newRecord = new Redwood.Record(repeatSemantics.Message(repeatedRecordCount), newTags, info.lastRecord.depth, info.lastRecord.timesstamp);
                //((pass record))
                willReturn.Add(newRecord);
                info.timesSeen    = 0;
                info.timesPrinted = 0;
            }
        }
예제 #3
0
        /// <summary>
        /// <inheritDoc/>
        ///
        /// </summary>
        public override IList <Redwood.Record> SignalStartTrack(Redwood.Record signal)
        {
            //(handle record)
            IList <Redwood.Record> willReturn = new List <Redwood.Record>();
            bool isPrinting = InternalHandle(signal, willReturn);

            //(adjust state for track)
            if (!signal.Force())
            {
                if (isPrinting)
                {
                    current.trackCountPending = RepeatedRecordHandler.PendingType.Printing;
                    current.timesPrinted     -= 1;
                }
                else
                {
                    current.trackCountPending = RepeatedRecordHandler.PendingType.Seen;
                }
                current.timesSeen -= 1;
            }
            //(push stack)
            stack.Push(current);
            current = new RepeatedRecordHandler.RepeatedRecordInfo();
            if (!isPrinting)
            {
                current.suppressRecord = true;
            }
            return(willReturn);
        }
예제 #4
0
        /// <summary>
        /// <inheritDoc/>
        ///
        /// </summary>
        public override IList <Redwood.Record> Handle(Redwood.Record record)
        {
            IList <Redwood.Record> willReturn = new List <Redwood.Record>();

            if (InternalHandle(record, willReturn))
            {
                willReturn.Add(record);
            }
            return(willReturn);
        }
 public virtual bool Matches(Redwood.Record record)
 {
     foreach (object tag in record.Channels())
     {
         if (tag.Equals(matchingChannel))
         {
             return(true);
         }
     }
     return(false);
 }
 public bool Matches(Redwood.Record message)
 {
     foreach (object channel in message.Channels())
     {
         if (this.matchAgainst.Contains(channel))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #7
0
        /// <summary>
        /// Override the raw handle method, as potentially we are dropping log levels in SLF4J
        /// and we do not want to render the resulting message.
        /// </summary>
        /// <param name="record">The record to handle.</param>
        /// <returns>Nothing -- this is the leaf of a tree.</returns>
        public override IList <Redwood.Record> Handle(Redwood.Record record)
        {
            // Get the implementing SLF4J logger
            Pair <ILogger, Redwood.Flag> loggerAndLevel = GetLoggerAndLevel(record.Channels());

            switch (loggerAndLevel.second)
            {
            case Redwood.Flag.Force:
            {
                // Potentially short-circuit
                break;
            }

            case Redwood.Flag.Error:
            {
                // Always pass it on if explicitly forced
                if (!loggerAndLevel.first.IsErrorEnabled())
                {
                    return(Java.Util.Collections.EmptyList());
                }
                break;
            }

            case Redwood.Flag.Warn:
            {
                if (!loggerAndLevel.first.IsWarnEnabled())
                {
                    return(Java.Util.Collections.EmptyList());
                }
                break;
            }

            case Redwood.Flag.Debug:
            {
                if (!loggerAndLevel.first.IsDebugEnabled())
                {
                    return(Java.Util.Collections.EmptyList());
                }
                break;
            }

            default:
            {
                if (!loggerAndLevel.first.IsInfoEnabled())
                {
                    return(Java.Util.Collections.EmptyList());
                }
                break;
            }
            }
            return(base.Handle(record));
        }
        /// <summary>For BooleanLogRecordHandler, you should leave this alone and implement propagateRecord instead.</summary>
        public override IList <Redwood.Record> Handle(Redwood.Record record)
        {
            bool keep = PropagateRecord(record);

            if (keep)
            {
                List <Redwood.Record> records = new List <Redwood.Record>();
                records.Add(record);
                return(records);
            }
            else
            {
                return(LogRecordHandler.Empty);
            }
        }
예제 #9
0
 public override bool PropagateRecord(Redwood.Record record)
 {
     foreach (ILogFilter filter in filters)
     {
         bool match = filter.Matches(record);
         if (match && disjunctiveMode)
         {
             return(true);
         }
         if (!match && !disjunctiveMode)
         {
             return(false);
         }
     }
     return(!disjunctiveMode);
 }
 /// <summary>
 /// <inheritDoc/>
 ///
 /// </summary>
 public override IList <Redwood.Record> SignalStartTrack(Redwood.Record signal)
 {
     //(queue track)
     this.queuedTracks.AddLast(signal);
     //(push info)
     if (info != null)
     {
         this.trackStack.Push(info);
     }
     info = new OutputHandler.TrackInfo(signal.content.ToString(), signal.timesstamp);
     //(force print)
     if (signal.Force())
     {
         UpdateTracks(signal.depth + 1);
     }
     //(return)
     return(Empty);
 }
예제 #11
0
 private bool InternalHandle(Redwood.Record record, IList <Redwood.Record> willReturn)
 {
     // We are passing the record through a number of filters,
     // ordered by priority, to determine whether or not
     // to continue passing it on
     //--Special Cases
     //--Regular Cases
     //(ckeck squashing)
     if (this.current.suppressRecord)
     {
         return(RecordVerdict(record, false, false, willReturn));
     }
     //arg 2 is irrelevant here
     //(check first record printed)
     if (this.current.lastRecord == null)
     {
         return(RecordVerdict(record, false, true, willReturn));
     }
     //(check equality)
     if (this.repeatSemantics.Equals(current.lastRecord, record))
     {
         //(check time)
         long currentTime = record.timesstamp;
         if (currentTime - this.current.timeOfLastPrintedRecord > this.repeatSemantics.MaxWaitTimeInMillis())
         {
             return(RecordVerdict(record, true, true, willReturn));
         }
         //(check num printed)
         if (this.current.timesSeen < this.repeatSemantics.NumToForcePrint())
         {
             return(RecordVerdict(record, true, true, willReturn));
         }
         else
         {
             return(RecordVerdict(record, true, false, willReturn));
         }
     }
     else
     {
         //(different record)
         return(RecordVerdict(record, false, true, willReturn));
     }
 }
예제 #12
0
        public override IList <Redwood.Record> Handle(Redwood.Record record)
        {
            IList <Redwood.Record> results = new List <Redwood.Record>();

            object[] channels = record.Channels();
            for (int i = 0; i < channels.Length; i++)
            {
                object channel = channels[i];
                if (oldChannelName.Equals(channel))
                {
                    // make a new version of the Record with a different channel name
                    channels[i] = newChannelName;
                    Redwood.Record reroutedRecord = new Redwood.Record(record.content, channels, record.depth, record.timesstamp);
                    results.Add(reroutedRecord);
                    return(results);
                }
            }
            // didn't find any matching records, so just return the original one
            results.Add(record);
            return(results);
        }
 private void UpdateTracks(int untilDepth)
 {
     while (!queuedTracks.IsEmpty())
     {
         //(get record to update)
         Redwood.Record signal = queuedTracks.RemoveFirst();
         if (signal.depth >= untilDepth)
         {
             queuedTracks.Add(signal);
             return;
         }
         //(begin record message)
         StringBuilder b = new StringBuilder();
         if (missingOpenBracket)
         {
             b.Append("{\n");
         }
         //(write margin)
         for (int i = 0; i < leftMargin; i++)
         {
             b.Append(" ");
         }
         //(write name)
         WriteContent(signal.depth, signal.content, b);
         if (signal.content.ToString().Length > 0)
         {
             b.Append(" ");
         }
         //(print)
         Print(null, this.Style(new StringBuilder(), b.ToString(), trackColor, trackStyle).ToString());
         this.missingOpenBracket = true;
         //only set to false if actually updated track state
         //(update lines printed)
         if (info != null)
         {
             info.numElementsPrinted += 1;
         }
     }
 }
 public virtual bool Matches(Redwood.Record record)
 {
     return(record.content.Equals(message));
 }
            public virtual bool Matches(Redwood.Record record)
            {
                string content = record.content.ToString();

                return(content.Contains(this.substring));
            }
예제 #16
0
 public virtual bool Equals(Redwood.Record lastRecord, Redwood.Record record)
 {
     return(Arrays.Equals(record.Channels(), lastRecord.Channels()) && SameMessage(lastRecord.content == null ? "null" : lastRecord.content.ToString(), record.content == null ? "null" : record.content.ToString()));
 }
예제 #17
0
 public virtual bool Equals(Redwood.Record lastRecord, Redwood.Record record)
 {
     return(Arrays.Equals(record.Channels(), lastRecord.Channels()) && ((record.content == null && lastRecord.content == null) || (record.content != null && record.content.Equals(lastRecord.content))));
 }
        /// <summary>
        /// <inheritDoc/>
        ///
        /// </summary>
        public override IList <Redwood.Record> Handle(Redwood.Record record)
        {
            StringBuilder b = new StringBuilder(1024);

            //--Special case for Exceptions
            string[] content;
            if (record.content is Exception)
            {
                //(vars)
                IList <string> lines = new List <string>();
                //(root message)
                Exception exception = (Exception)record.content;
                lines.Add(record.content.ToString());
                StackTraceElement[] trace           = exception.GetStackTrace();
                StackTraceElement   topTraceElement = trace.Length > 0 ? trace[0] : null;
                foreach (StackTraceElement e in exception.GetStackTrace())
                {
                    lines.Add(tab + e.ToString());
                }
                //(causes)
                while (exception.InnerException != null)
                {
                    System.Console.Out.WriteLine("TOP ELEMENT: " + topTraceElement);
                    //((variables))
                    exception = exception.InnerException;
                    trace     = exception.GetStackTrace();
                    lines.Add("Caused by: " + exception.GetType() + ": " + exception.Message);
                    for (int i = 0; i < trace.Length; i++)
                    {
                        //((add trace element))
                        StackTraceElement e_1 = trace[i];
                        lines.Add(tab + e_1.ToString());
                        //((don't print redundant elements))
                        if (topTraceElement != null && e_1.GetClassName().Equals(topTraceElement.GetClassName()) && e_1.GetMethodName().Equals(topTraceElement.GetMethodName()))
                        {
                            lines.Add(tab + "..." + (trace.Length - i - 1) + " more");
                            break;
                        }
                    }
                    //((update top element))
                    topTraceElement = trace.Length > 0 ? trace[0] : null;
                }
                //(set content array)
                content = new string[lines.Count];
                content = Sharpen.Collections.ToArray(lines, content);
            }
            else
            {
                if (record.content == null)
                {
                    content = new string[] { "null" };
                }
                else
                {
                    string toStr;
                    if (record.content is ISupplier)
                    {
                        //noinspection unchecked
                        toStr = ((ISupplier <object>)record.content).Get().ToString();
                    }
                    else
                    {
                        toStr = record.content.ToString();
                    }
                    if (toStr == null)
                    {
                        content = new string[] { "<null toString()>" };
                    }
                    else
                    {
                        content = toStr.Split("\n");
                    }
                }
            }
            //would be nice to get rid of this 'split()' call at some point
            //--Handle Tracks
            UpdateTracks(record.depth);
            if (this.missingOpenBracket)
            {
                this.Style(b, "{\n", trackColor, trackStyle);
                this.missingOpenBracket = false;
            }
            //--Process Record
            //(variables)
            int cursorPos           = 0;
            int contentLinesPrinted = 0;
            //(loop)
            Color color = Color.None;

            Edu.Stanford.Nlp.Util.Logging.Style style = Edu.Stanford.Nlp.Util.Logging.Style.None;
            //(get channels)
            List <object> printableChannels = new List <object>();

            foreach (object chan in record.Channels())
            {
                if (chan is Color)
                {
                    color = (Color)chan;
                }
                else
                {
                    if (chan is Edu.Stanford.Nlp.Util.Logging.Style)
                    {
                        style = (Edu.Stanford.Nlp.Util.Logging.Style)chan;
                    }
                    else
                    {
                        if (chan != Redwood.Force)
                        {
                            printableChannels.Add(chan);
                        }
                    }
                }
            }
            //--Write Channels
            if (leftMargin > 2)
            {
                //don't print if not enough space
                //((print channels)
                b.Append("[");
                cursorPos += 1;
                object lastChan             = null;
                bool   wasAnyChannelPrinted = false;
                for (int i = 0; i < printableChannels.Count; i++)
                {
                    object chan_1 = printableChannels[i];
                    if (chan_1.Equals(lastChan))
                    {
                        continue;
                    }
                    //skip duplicate channels
                    lastChan = chan_1;
                    //(get channel)
                    string toPrint = chan_1.ToString();
                    if (toPrint.Length > leftMargin - 1)
                    {
                        toPrint = Sharpen.Runtime.Substring(toPrint, 0, leftMargin - 2);
                    }
                    if (cursorPos + toPrint.Length >= leftMargin)
                    {
                        //(case: doesn't fit)
                        while (cursorPos < leftMargin)
                        {
                            b.Append(" ");
                            cursorPos += 1;
                        }
                        if (contentLinesPrinted < content.Length)
                        {
                            WriteContent(record.depth, Style(new StringBuilder(), content[contentLinesPrinted], color, style).ToString(), b);
                            contentLinesPrinted += 1;
                        }
                        b.Append("\n ");
                        cursorPos = 1;
                    }
                    //(print flag)
                    bool wasChannelPrinted = FormatChannel(b, toPrint, chan_1);
                    wasAnyChannelPrinted = wasAnyChannelPrinted || wasChannelPrinted;
                    if (wasChannelPrinted && i < printableChannels.Count - 1)
                    {
                        b.Append(channelSeparatorChar);
                        cursorPos += 1;
                    }
                    cursorPos += toPrint.Length;
                }
                if (wasAnyChannelPrinted)
                {
                    b.Append("]");
                    cursorPos += 1;
                }
                else
                {
                    b.Length = b.Length - 1;
                    // remove leading "["
                    cursorPos -= 1;
                }
            }
            //--Content
            //(write content)
            while (contentLinesPrinted < content.Length)
            {
                while (cursorPos < leftMargin)
                {
                    b.Append(" ");
                    cursorPos += 1;
                }
                WriteContent(record.depth, Style(new StringBuilder(), content[contentLinesPrinted], color, style).ToString(), b);
                contentLinesPrinted += 1;
                if (contentLinesPrinted < content.Length)
                {
                    b.Append("\n");
                    cursorPos = 0;
                }
            }
            //(print)
            if (b.Length == 0 || b[b.Length - 1] != '\n')
            {
                b.Append("\n");
            }
            Print(record.Channels(), b.ToString());
            //--Continue
            if (info != null)
            {
                info.numElementsPrinted += 1;
            }
            List <Redwood.Record> rtn = new List <Redwood.Record>();

            rtn.Add(record);
            return(rtn);
        }
 /// <summary>
 /// <inheritDoc/>
 ///
 /// </summary>
 public override IList <Redwood.Record> SignalStartTrack(Redwood.Record signal)
 {
     return(Empty);
 }
        /// <summary>
        /// <inheritDoc/>
        ///
        /// </summary>
        public override IList <Redwood.Record> Handle(Redwood.Record record)
        {
            bool isPrinting = false;

            if (record.Force())
            {
                //--Case: Force Printing
                isPrinting = true;
            }
            else
            {
                switch (this.defaultState)
                {
                case VisibilityHandler.State.HideAll:
                {
                    //--Case: Filter
                    //--Default False
                    foreach (object tag in record.Channels())
                    {
                        if (this.deltaPool.Contains(tag))
                        {
                            isPrinting = true;
                            break;
                        }
                    }
                    break;
                }

                case VisibilityHandler.State.ShowAll:
                {
                    //--Default True
                    if (!this.deltaPool.IsEmpty())
                    {
                        // Short-circuit for efficiency
                        bool somethingSeen = false;
                        foreach (object tag_1 in record.Channels())
                        {
                            if (this.deltaPool.Contains(tag_1))
                            {
                                somethingSeen = true;
                                break;
                            }
                        }
                        isPrinting = !somethingSeen;
                    }
                    else
                    {
                        isPrinting = true;
                    }
                    break;
                }

                default:
                {
                    throw new InvalidOperationException("Unknown default state setting: " + this.defaultState);
                }
                }
            }
            //--Return
            if (isPrinting)
            {
                return(Java.Util.Collections.SingletonList(record));
            }
            else
            {
                return(Empty);
            }
        }
예제 #21
0
 /// <summary>Signal the start of a track, i.e.</summary>
 /// <remarks>Signal the start of a track, i.e. that we have descended a level deeper.</remarks>
 /// <param name="signal">
 /// A record corresponding to the information in the track header.
 /// The depth in this object is the old log depth.
 /// </param>
 /// <returns>
 /// A list of records to pass down the pipeline, not including the startTrack() signal.
 /// The returned records are passed to handle(), not startTrack(),
 /// and are sent before the startTrack() signal.
 /// </returns>
 public virtual IList <Redwood.Record> SignalStartTrack(Redwood.Record signal)
 {
     return(Empty);
 }
 /// <summary>Given a record, return true if it should be propagated to later handlers.</summary>
 public abstract bool PropagateRecord(Redwood.Record record);
예제 #23
0
 /// <summary>Handle a log Record, either as a filter or by producing a side effect.</summary>
 /// <param name="record">The log record to handle</param>
 /// <returns>a (possibly empty) list of records to be sent on in the pipeline</returns>
 public abstract IList <Redwood.Record> Handle(Redwood.Record record);