Example #1
0
        /// <summary>
        ///     Creates a new <see cref="ILogEntryFilter" /> from the given values.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="matchType"></param>
        /// <param name="ignoreCase"></param>
        /// <param name="isInverted"></param>
        /// <returns></returns>
        public static ILogEntryFilter Create(string value, FilterMatchType matchType, bool ignoreCase, bool isInverted)
        {
            ILogEntryFilter filter = null;

            switch (matchType)
            {
            case FilterMatchType.SubstringFilter:
                if (!string.IsNullOrEmpty(value))
                {
                    filter = new SubstringFilter(value, ignoreCase);
                }
                break;

            case FilterMatchType.WildcardFilter:
                if (!string.IsNullOrEmpty(value))
                {
                    filter = new WildcardFilter(value, ignoreCase);
                }
                break;

            case FilterMatchType.RegexpFilter:
                if (!string.IsNullOrEmpty(value))
                {
                    filter = new RegexFilter(value, ignoreCase);
                }
                break;
            }

            if (filter != null && isInverted)
            {
                filter = new InvertFilter(filter);
            }

            return(filter);
        }
Example #2
0
        public IEnumerable <ILogEntryFilter> CreateFilterChain()
        {
            var filters = new List <ILogEntryFilter>(_viewModels.Count);

            // ReSharper disable LoopCanBeConvertedToQuery
            foreach (var quickFilter in _viewModels)
            // ReSharper restore LoopCanBeConvertedToQuery
            {
                ILogEntryFilter filter = null;
                try
                {
                    filter = quickFilter.CreateFilter();
                }
                catch (Exception)
                {
                }

                if (filter != null)
                {
                    filters.Add(filter);
                }
            }

            if (filters.Count == 0)
            {
                return(null);
            }

            return(filters);
        }
Example #3
0
 /// <summary>
 ///     Creates a filtered view onto this log file.
 /// </summary>
 /// <param name="logFile"></param>
 /// <param name="scheduler"></param>
 /// <param name="logLineFilter"></param>
 /// <param name="logEntryFilter"></param>
 /// <returns></returns>
 public static FilteredLogFile AsFiltered(this ILogFile logFile,
                                          ITaskScheduler scheduler,
                                          ILogLineFilter logLineFilter,
                                          ILogEntryFilter logEntryFilter)
 {
     return(AsFiltered(logFile, scheduler, logLineFilter, logEntryFilter, TimeSpan.FromMilliseconds(value: 10)));
 }
Example #4
0
        /// <inheritdoc />
        public bool PassesFilter(IEnumerable <LogLine> logEntry)
        {
            var passes = new bool[_filters.Length];

            foreach (LogLine logLine in logEntry)
            {
                for (int i = 0; i < _filters.Length; ++i)
                {
                    ILogEntryFilter filter = _filters[i];
                    if (!passes[i])
                    {
                        passes[i] = filter.PassesFilter(logLine);
                    }
                }
            }

// ReSharper disable LoopCanBeConvertedToQuery
// ReSharper disable ForCanBeConvertedToForeach
            for (int i = 0; i < passes.Length; ++i)
// ReSharper restore ForCanBeConvertedToForeach
// ReSharper restore LoopCanBeConvertedToQuery
            {
                if (!passes[i])
                {
                    return(false);
                }
            }

            return(true);
        }
Example #5
0
        public List <ILogEntryFilter> CreateFilterChain()
        {
            var filters = new List <ILogEntryFilter>(_viewModels.Count);

            // ReSharper disable LoopCanBeConvertedToQuery
            foreach (var quickFilter in _viewModels)
            // ReSharper restore LoopCanBeConvertedToQuery
            {
                ILogEntryFilter filter = null;
                try
                {
                    filter = quickFilter.CreateFilter();
                }
                catch (Exception e)
                {
                    Log.DebugFormat("Caught exception while creating quick filter: {0}", e);
                }

                if (filter != null)
                {
                    filters.Add(filter);
                }
            }

            if (filters.Count == 0)
            {
                return(null);
            }

            return(filters);
        }
Example #6
0
        /// <summary>
        ///     Initializes this object.
        /// </summary>
        /// <param name="scheduler"></param>
        /// <param name="maximumWaitTime"></param>
        /// <param name="source"></param>
        /// <param name="logLineFilter"></param>
        /// <param name="logEntryFilter"></param>
        public FilteredLogFile(ITaskScheduler scheduler,
                               TimeSpan maximumWaitTime,
                               ILogFile source,
                               ILogLineFilter logLineFilter,
                               ILogEntryFilter logEntryFilter)
            : base(scheduler)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            _source               = source;
            _logLineFilter        = logLineFilter ?? new NoFilter();
            _logEntryFilter       = logEntryFilter ?? new NoFilter();
            _pendingModifications = new ConcurrentQueue <LogFileSection>();
            _indices              = new List <int>();
            _logEntryIndices      = new Dictionary <int, int>();
            _buffer               = new LogLine[BatchSize];
            _lastLogEntry         = new List <LogLine>();
            _maximumWaitTime      = maximumWaitTime;

            _source.AddListener(this, maximumWaitTime, BatchSize);
            StartTask();
        }
Example #7
0
        public InvertFilter(ILogEntryFilter filter)
        {
            if (filter == null)
                throw new ArgumentNullException("filter");

            _filter = filter;
        }
Example #8
0
        /// <summary>
        ///     Initializes this filter.
        /// </summary>
        /// <param name="filter"></param>
        public InvertFilter(ILogEntryFilter filter)
        {
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            _filter = filter;
        }
Example #9
0
        /// <summary>
        /// LogListener base class.
        /// </summary>
        /// <param name="id">Identifier of the listener.</param>
        /// <param name="name">Name of the listener.</param>
        /// <param name="filter">Filter applied to the incoming log entries.</param>
        /// <param name="formatter">Format used to convert log entry to string.</param>
        protected LogListener(string id, string name, ILogEntryFilter filter, ILogEntryFormatter formatter)
        {
            Id        = id;
            Name      = name;
            Filter    = filter;
            Formatter = formatter;

            IsEnabled = true;
        }
Example #10
0
        /// <summary>
        ///     Creates a filtered view onto this log file.
        /// </summary>
        /// <param name="logFile"></param>
        /// <param name="scheduler"></param>
        /// <param name="logLineFilter"></param>
        /// <param name="logEntryFilter"></param>
        /// <param name="maximumWaitTime"></param>
        /// <returns></returns>
        public static FilteredLogFile AsFiltered(this ILogFile logFile,
                                                 ITaskScheduler scheduler,
                                                 ILogLineFilter logLineFilter,
                                                 ILogEntryFilter logEntryFilter,
                                                 TimeSpan maximumWaitTime)
        {
            var file = new FilteredLogFile(scheduler, maximumWaitTime, logFile, logLineFilter, logEntryFilter);

            return(file);
        }
Example #11
0
        public FilteredLogFile(ITaskScheduler scheduler, TimeSpan maximumWaitTime, ILogFile source, ILogEntryFilter filter)
            : base(scheduler)
        {
            if (source == null) throw new ArgumentNullException("source");
            if (filter == null) throw new ArgumentNullException("filter");

            _source = source;
            _filter = filter;
            _pendingModifications = new ConcurrentQueue<LogFileSection>();
            _indices = new List<int>();
            _buffer = new LogLine[BatchSize];
            _lastLogEntry = new List<LogLine>();
            _maximumWaitTime = maximumWaitTime;

            _source.AddListener(this, maximumWaitTime, BatchSize);
            StartTask();
        }
Example #12
0
        private void CreateFilteredLogFile()
        {
            _filteredLogFile?.Dispose();

            LevelFlags      levelFilter    = LevelFilter;
            ILogLineFilter  logLineFilter  = CreateLogLineFilter();
            ILogEntryFilter logEntryFilter = Filter.Create(levelFilter, _quickFilterChain);

            if (Filter.IsFilter(logEntryFilter) || Filter.IsFilter(logLineFilter))
            {
                _filteredLogFile      = UnfilteredLogFile.AsFiltered(_taskScheduler, logLineFilter, logEntryFilter, _maximumWaitTime);
                _logFile.InnerLogFile = _filteredLogFile;
            }
            else
            {
                _filteredLogFile      = null;
                _logFile.InnerLogFile = UnfilteredLogFile;
            }
        }
        private void CreateFilteredLogFile()
        {
            _filteredLogFile?.Dispose();

            LevelFlags      levelFilter    = LevelFilter;
            ILogLineFilter  logLineFilter  = HideEmptyLines ? (ILogLineFilter) new EmptyLogLineFilter() : new NoFilter();
            ILogEntryFilter logEntryFilter = Filter.Create(levelFilter, _quickFilterChain);

            if (logEntryFilter != null)
            {
                _filteredLogFile      = UnfilteredLogFile.AsFiltered(_taskScheduler, logLineFilter, logEntryFilter, _maximumWaitTime);
                _logFile.InnerLogFile = _filteredLogFile;
            }
            else
            {
                _filteredLogFile      = null;
                _logFile.InnerLogFile = UnfilteredLogFile;
            }
        }
Example #14
0
        /// <summary>
        ///     Initializes this object.
        /// </summary>
        /// <param name="scheduler"></param>
        /// <param name="maximumWaitTime"></param>
        /// <param name="source"></param>
        /// <param name="logLineFilter"></param>
        /// <param name="logEntryFilter"></param>
        public FilteredLogSource(ITaskScheduler scheduler,
                                 TimeSpan maximumWaitTime,
                                 ILogSource source,
                                 ILogLineFilter logLineFilter,
                                 ILogEntryFilter logEntryFilter)
            : base(scheduler)
        {
            _source = source ?? throw new ArgumentNullException(nameof(source));

            _properties       = new ConcurrentPropertiesList(source.Properties);
            _propertiesBuffer = new PropertiesBufferList();             //< Will be used as temporary storage to hold the properties from the source

            _logLineFilter        = logLineFilter ?? new NoFilter();
            _logEntryFilter       = logEntryFilter ?? new NoFilter();
            _pendingModifications = new ConcurrentQueue <LogSourceModification>();
            _indices         = new List <int>();
            _logEntryIndices = new Dictionary <int, int>();
            _array           = new LogBufferArray(BatchSize, Core.Columns.Minimum);
            _lastLogBuffer   = new LogBufferList(Core.Columns.Minimum);
            _maximumWaitTime = maximumWaitTime;

            _source.AddListener(this, maximumWaitTime, BatchSize);
            StartTask();
        }
Example #15
0
 /// <summary>
 /// Add an log event filter
 /// </summary>
 /// <remarks>
 /// Filters are called before sending an event.
 /// This allows the filter to decide whether the log message should not be recorded at all.
 /// </remarks>
 /// <param name="options">The <see cref="SentryLoggingOptions"/> to hold the filter.</param>
 /// <param name="filter">The filter.</param>
 public static void AddLogEntryFilter(this SentryLoggingOptions options, ILogEntryFilter filter)
 => options.Filters = options.Filters.Add(filter);
 public static FilteredLogFile AsFiltered(this ILogFile logFile, ITaskScheduler scheduler, ILogEntryFilter filter)
 {
     return AsFiltered(logFile, scheduler, filter, TimeSpan.FromMilliseconds(10));
 }
Example #17
0
 /// <inheritdoc />
 public ILogFile CreateFilteredLogFile(TimeSpan maximumWaitTime, ILogFile source, ILogEntryFilter filter)
 {
     return(new FilteredLogFile(Retrieve <ITaskScheduler>(), maximumWaitTime, source,
                                null,
                                filter));
 }
 public static FilteredLogFile AsFiltered(this ILogFile logFile, ITaskScheduler scheduler, ILogEntryFilter filter, TimeSpan maximumWaitTime)
 {
     var file = new FilteredLogFile(scheduler, maximumWaitTime, logFile, filter);
     return file;
 }
Example #19
0
        private void UpdateNoEntriesExplanation()
        {
            IDataSource dataSource       = _dataSource.DataSource;
            var         folderDataSource = dataSource as IFolderDataSource;
            ILogSource  source           = dataSource.UnfilteredLogSource;
            ILogSource  filtered         = dataSource.FilteredLogSource;

            if (filtered.GetProperty(Properties.LogEntryCount) == 0)
            {
                ILogEntryFilter filter      = dataSource.LogEntryFilter;
                var             emptyReason = source.GetProperty(Properties.EmptyReason);
                if (emptyReason != null)
                {
                    NoEntriesIcon        = emptyReason.Icon;
                    NoEntriesExplanation = emptyReason.Reason;
                    NoEntriesAction      = emptyReason.Explanation;
                }
                else if (folderDataSource != null && folderDataSource.UnfilteredFileCount == 0)
                {
                    NoEntriesIcon        = null;
                    NoEntriesExplanation = $"The folder \"{Path.GetFileName(dataSource.FullFileName)}\" does not contain any file";
                    NoEntriesAction      = dataSource.FullFileName;
                }
                else if (folderDataSource != null && folderDataSource.FilteredFileCount == 0)
                {
                    NoEntriesIcon        = null;
                    NoEntriesExplanation = $"The folder \"{Path.GetFileName(dataSource.FullFileName)}\" does not contain any file matching \"{folderDataSource.LogFileSearchPattern}\"";
                    NoEntriesAction      = dataSource.FullFileName;
                }
                else if (source.GetProperty(Properties.Size) == Size.Zero)
                {
                    NoEntriesIcon        = Icons.File;
                    NoEntriesExplanation = "Data source is empty";
                    NoEntriesAction      = null;
                }
                else if (dataSource.LevelFilter != LevelFlags.All)
                {
                    NoEntriesIcon        = Icons.FileSearch;
                    NoEntriesExplanation = "Nothing matches level filter";
                    NoEntriesAction      = "Try filtering by different levels or display everything regardless of its level again";
                }
                else if (dataSource.ScreenCleared)
                {
                    NoEntriesIcon        = Icons.PlaylistRemove;
                    NoEntriesExplanation = "The screen was cleared";
                    NoEntriesAction      = "No new log entries have been added to the data source since the screen was cleared. Try waiting for a little longer or show all log entries again.";
                }
                else if (filter != null)
                {
                    NoEntriesIcon        = Icons.FileSearch;
                    NoEntriesExplanation = "Nothing matches quick filter";
                    NoEntriesAction      = filter is FilterExpression
                                                ? $"No log entry matches \"{filter}\".\r\nTry changing your filter(s) or disable them again"
                                                : "Try filtering by different terms or disable all quick filters";
                }
                else if (source is MergedLogSource)
                {
                    NoEntriesIcon        = null;
                    NoEntriesExplanation = "No log entries with timestamps";
                    NoEntriesAction      = "Try merging different data sources, change the timestamp format of the data or create a plugin to help Tailviewer parse its timestamp";
                }
                else
                {
                    NoEntriesIcon        = null;
                    NoEntriesExplanation = null;
                    NoEntriesAction      = null;
                }
            }
            else
            {
                NoEntriesExplanation = null;
                NoEntriesAction      = null;
            }
        }
 /// <summary>
 /// Add an log event filter
 /// </summary>
 /// <remarks>
 /// Filters are called before sending an event.
 /// This allows the filter to decide whether the log message should not be recorded at all.
 /// </remarks>
 /// <param name="options">The <see cref="SentryLoggingOptions"/> to hold the filter.</param>
 /// <param name="filter">The filter.</param>
 public static void AddLogEntryFilter(this SentryLoggingOptions options, ILogEntryFilter filter)
 => options.Filters = options.Filters.Concat(new[] { filter }).ToArray();