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); }
/// <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)); }
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); }
/// <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> 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); } }
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)))); }
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())); }