예제 #1
0
        private static AttributeMatch CheckLogAttributes(ILogEntry x, ILogEntry y, LogAttribute attribute)
        {
            var match = AttributeMatch.Mismatch;

            if (x.HasAttribute(attribute) == y.HasAttribute(attribute))
            {
                match = AttributeMatch.MatchButMissing;
                if (x.HasAttribute(attribute))
                {
                    match = AttributeMatch.Match;
                }
            }
            return(match);
        }
        private static bool IsValidForTimestamp(this ILogEntry log)
        {
            //XXX is this still needed, or does registry.Logs do this implicitly?

            // Special case to ensure that message (which doesn't apply here anyway) and timestamp match the expected types
            // For failed logs, timestamps that haven't been sorted are ignored.
            var isInvalid = !log.IsValid &&
                            ((log is IInternalLogEntry internalLog && internalLog.HasTimestampChanged) ||
                             !log.HasAttribute(LogAttribute.Timestamp) || !(log.GetAttribute <object>(LogAttribute.Timestamp) is DateTime));

            return(!isInvalid);
        }
예제 #3
0
        /// <summary>
        /// Process an individual log with the stored print mode values.
        /// </summary>
        /// <param name="writer">The writer to write to.</param>
        /// <param name="log">The log to process.</param>
        /// <param name="state">The state generated by <see cref="GenerateStateObject"/></param>
        public void Process(TextWriter writer, ILogEntry log, object state)
        {
            initialized |= true;

            //XXX
            if (log.HasAttribute(attribute))
            {
                writer.Write(format, log.GetAttribute <object>(attribute));
            }
            else
            {
                //XXX
                throw new PrintException(string.Format("Missing Value for \"{0}\"", attribute));
            }
        }
예제 #4
0
        /// <summary>
        /// Add an attribute value to the log entry.
        /// </summary>
        /// <param name="entry">The entry to add an attribute to.</param>
        /// <param name="attribute">The attribute to add to.</param>
        /// <param name="value">The attribute value to add.</param>
        /// <returns><c>true</c> if the entry was added. <c>false</c> if otherwise.</returns>
        public bool AddValueToLog(ILogEntry entry, LogAttribute attribute, object value)
        {
            if (value == null)
            {
                return(false);
            }
            addValueToLogCounter.Increment(attribute.ToString());

            if (entry is IInternalLogEntry internalEntry && !entry.HasAttribute(attribute))
            {
                addValueToLogAddingCounter.Increment();
                internalEntry.AddAttribute(attribute, value);
                return(true);
            }
            return(false);
        }
예제 #5
0
        /// <summary>
        /// Clone a log entry into this log registry.
        /// </summary>
        /// <param name="entry">The log entry to clone.</param>
        /// <returns>The cloned log entry.</returns>
        public ILogEntry CloneLog(ILogEntry entry)
        {
            if (entry == null)
            {
                return(null);
            }

            if (ContainsLog(entry))
            {
                return(entry);
            }
            var existingClone = FindClone(entry);

            if (existingClone != null)
            {
                return(existingClone);
            }

            var addToRegistry   = false;
            var addToProcessing = false;
            IInternalLogEntry cloneEntry;

            if (entry is LogEntry || (entry.IsValid && !(entry is FailedLogEntry)))
            {
                cloneEntry    = new LogEntry(entry.Timestamp, entry.Message);
                addToRegistry = true;
            }
            else
            {
                var failedCloneEntry = new FailedLogEntry();
                if (entry.HasAttribute(LogAttribute.Timestamp))
                {
                    failedCloneEntry.AddAttribute(LogAttribute.Timestamp, entry.GetAttribute <object>(LogAttribute.Timestamp));

                    if (entry is IInternalLogEntry entryInternal)
                    {
                        if (entryInternal.HasTimestampChanged)
                        {
                            // there's a timestamp, but it's still marked as changed. We get an exception if add gets invoked again, so it has only been added once and hasn't been notifed, which means it's still in processing
                            addToProcessing = true;
                        }
                        else
                        {
                            // there's a timestamp, but it hasn't been marked as changed. It means the timestamp change has been reset which only happens in notify
                            failedCloneEntry.ResetTimestampChanged();
                            addToRegistry = true;
                        }
                    }
                }
                else if (entry is FailedLogEntry failedLog)
                {
                    // Edge cases
                    // - no timestamp, not empty : it's not empty, but it lacks a timestamp. It may or may not have been processed
                    // - no timestamp, empty : empty doesn't mean it hasn't been processed (which means it's not in the process list) but also doesn't mean it has been processed (which means it can be discarded)

                    if (failedLog.IsRegistryNotified)
                    {
                        // It it has been processed, then it remains in processing unless it's empty.
                        failedCloneEntry.LogRegistryNotified();
                        if (!failedLog.IsEmpty)
                        {
                            addToProcessing = true;
                        }
                    }
                    else
                    {
                        // If it hasn't been processed, then add it to processing
                        addToProcessing = true;
                    }
                }

                if (entry.HasAttribute(LogAttribute.Message))
                {
                    failedCloneEntry.AddAttribute(LogAttribute.Message, entry.GetAttribute <object>(LogAttribute.Message));
                }

                cloneEntry = failedCloneEntry;
            }

            foreach (var attribute in Enum.GetValues(typeof(LogAttribute)).Cast <LogAttribute>())
            {
                if (attribute == LogAttribute.Timestamp || attribute == LogAttribute.Message)
                {
                    continue;
                }
                if (entry.HasAttribute(attribute))
                {
                    cloneEntry.AddAttribute(attribute, entry.GetAttribute <object>(attribute));
                }
            }

            if (addToRegistry)
            {
                storage.AddLogSorted(cloneEntry);
            }
            else if (addToProcessing)
            {
                lock (logsBeingProcessed)
                {
                    logsBeingProcessed.Add(cloneEntry);
                    logsBeingProcessedCounter.Increment();
                }
            }
            return(cloneEntry);
        }