From a1bf3bd84775ebc0a393c74a5bca02d4b953fc3a Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Thu, 23 Nov 2017 09:39:31 +1000 Subject: [PATCH 1/6] Dev version bump [Skip CI] --- .../Serilog.Filters.Expressions.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Serilog.Filters.Expressions/Serilog.Filters.Expressions.csproj b/src/Serilog.Filters.Expressions/Serilog.Filters.Expressions.csproj index 6b3f67a..488adbc 100644 --- a/src/Serilog.Filters.Expressions/Serilog.Filters.Expressions.csproj +++ b/src/Serilog.Filters.Expressions/Serilog.Filters.Expressions.csproj @@ -1,8 +1,8 @@ - + Expression-based event filtering for Serilog. - 1.1.0 + 1.1.1 Serilog Contributors net45;netstandard1.5 true From 68a0b8daf956d61f851d23d195f3d7028582b560 Mon Sep 17 00:00:00 2001 From: Matthew Erbs Date: Wed, 9 May 2018 15:56:30 +1000 Subject: [PATCH 2/6] New NuGet API Key --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index cf14c5c..c919437 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -9,7 +9,7 @@ artifacts: deploy: - provider: NuGet api_key: - secure: nvZ/z+pMS91b3kG4DgfES5AcmwwGoBYQxr9kp4XiJHj25SAlgdIxFx++1N0lFH2x + secure: bd9z4P73oltOXudAjPehwp9iDKsPtC+HbgshOrSgoyQKr5xVK+bxJQngrDJkHdY8 skip_symbols: true on: branch: /^(master|dev)$/ From 1b574596707f57461109fa180cbd7d49ec94efa9 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Wed, 23 May 2018 20:34:10 +1000 Subject: [PATCH 3/6] Update Superpower dependency to v2 (-dev); Serilog to 2.7.1 --- .../.idea/contentModel.xml | 198 +++++++++ .../.idea/indexLayout.xml | 7 + .../.idea/modules.xml | 8 + .../.idea/vcs.xml | 6 + .../.idea/workspace.xml | 411 ++++++++++++++++++ .../riderModule.iml | 14 + .../Parsing/FilterExpressionTokenizer.cs | 8 +- .../Serilog.Filters.Expressions.csproj | 17 +- ...ilters.Expressions.PerformanceTests.csproj | 4 +- .../FilterExpressionParserTests.cs | 11 + .../Serilog.Filters.Expressions.Tests.csproj | 14 +- .../app.config | 16 - 12 files changed, 674 insertions(+), 40 deletions(-) create mode 100644 .idea/.idea.serilog-filters-expressions/.idea/contentModel.xml create mode 100644 .idea/.idea.serilog-filters-expressions/.idea/indexLayout.xml create mode 100644 .idea/.idea.serilog-filters-expressions/.idea/modules.xml create mode 100644 .idea/.idea.serilog-filters-expressions/.idea/vcs.xml create mode 100644 .idea/.idea.serilog-filters-expressions/.idea/workspace.xml create mode 100644 .idea/.idea.serilog-filters-expressions/riderModule.iml delete mode 100644 test/Serilog.Filters.Expressions.Tests/app.config diff --git a/.idea/.idea.serilog-filters-expressions/.idea/contentModel.xml b/.idea/.idea.serilog-filters-expressions/.idea/contentModel.xml new file mode 100644 index 0000000..30d4ae5 --- /dev/null +++ b/.idea/.idea.serilog-filters-expressions/.idea/contentModel.xml @@ -0,0 +1,198 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.serilog-filters-expressions/.idea/indexLayout.xml b/.idea/.idea.serilog-filters-expressions/.idea/indexLayout.xml new file mode 100644 index 0000000..f1feadf --- /dev/null +++ b/.idea/.idea.serilog-filters-expressions/.idea/indexLayout.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.serilog-filters-expressions/.idea/modules.xml b/.idea/.idea.serilog-filters-expressions/.idea/modules.xml new file mode 100644 index 0000000..e3c7652 --- /dev/null +++ b/.idea/.idea.serilog-filters-expressions/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.serilog-filters-expressions/.idea/vcs.xml b/.idea/.idea.serilog-filters-expressions/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/.idea.serilog-filters-expressions/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/.idea.serilog-filters-expressions/.idea/workspace.xml b/.idea/.idea.serilog-filters-expressions/.idea/workspace.xml new file mode 100644 index 0000000..91ccdd1 --- /dev/null +++ b/.idea/.idea.serilog-filters-expressions/.idea/workspace.xml @@ -0,0 +1,411 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - 1527068703066 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/.idea.serilog-filters-expressions/riderModule.iml b/.idea/.idea.serilog-filters-expressions/riderModule.iml deleted file mode 100644 index e8439a1..0000000 --- a/.idea/.idea.serilog-filters-expressions/riderModule.iml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file From d6e6eb9fc592edf4e1f8bdb0c44ac8addab9d33e Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Mon, 11 Jun 2018 07:53:51 +1000 Subject: [PATCH 5/6] Fix assembly versioning test, general cleanup, fix tokenizer recognition of '+' as a delimiter --- .../Expressions/FilterExpressionLanguage.cs | 9 +++------ .../Expressions/Parsing/FilterExpressionParser.cs | 11 +++-------- .../Parsing/FilterExpressionTokenParsers.cs | 9 ++++++++- .../Parsing/FilterExpressionTokenizer.cs | 15 ++++++++++++--- .../Serilog.Filters.Expressions.csproj | 2 +- .../FilterExpressionParserTests.cs | 1 + .../PackagingTests.cs | 2 +- 7 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/Serilog.Filters.Expressions/Filters/Expressions/FilterExpressionLanguage.cs b/src/Serilog.Filters.Expressions/Filters/Expressions/FilterExpressionLanguage.cs index 11f6c23..7b67953 100644 --- a/src/Serilog.Filters.Expressions/Filters/Expressions/FilterExpressionLanguage.cs +++ b/src/Serilog.Filters.Expressions/Filters/Expressions/FilterExpressionLanguage.cs @@ -1,5 +1,4 @@ using Serilog.Events; -using Serilog.Filters.Expressions.Ast; using Serilog.Filters.Expressions.Compilation; using System; using System.Linq; @@ -19,9 +18,7 @@ public static class FilterLanguage /// A function that evaluates the expression in the context of the log event. public static Func CreateFilter(string expression) { - Func filter; - string error; - if (!TryCreateFilter(expression, out filter, out error)) + if (!TryCreateFilter(expression, out var filter, out var error)) throw new ArgumentException(error); return filter; @@ -36,8 +33,7 @@ public static Func CreateFilter(string expression) /// True if the filter could be created; otherwise, false. public static bool TryCreateFilter(string expression, out Func filter, out string error) { - FilterExpression root; - if (!FilterExpressionParser.TryParse(expression, out root, out error)) + if (!FilterExpressionParser.TryParse(expression, out var root, out error)) { filter = null; return false; @@ -54,6 +50,7 @@ public static bool TryCreateFilter(string expression, out Func /// The text to escape. /// The text with any special values escaped. Will need to be passed through /// if it is being embedded directly into a filter expression. + // ReSharper disable once UnusedMember.Global public static string EscapeLikeExpressionContent(string text) { if (text == null) throw new ArgumentNullException(nameof(text)); diff --git a/src/Serilog.Filters.Expressions/Filters/Expressions/Parsing/FilterExpressionParser.cs b/src/Serilog.Filters.Expressions/Filters/Expressions/Parsing/FilterExpressionParser.cs index 52d3970..a0c47e9 100644 --- a/src/Serilog.Filters.Expressions/Filters/Expressions/Parsing/FilterExpressionParser.cs +++ b/src/Serilog.Filters.Expressions/Filters/Expressions/Parsing/FilterExpressionParser.cs @@ -1,6 +1,5 @@ using System; using Serilog.Filters.Expressions.Ast; -using Superpower; namespace Serilog.Filters.Expressions.Parsing { @@ -8,9 +7,7 @@ static class FilterExpressionParser { public static FilterExpression Parse(string filterExpression) { - FilterExpression root; - string error; - if (!TryParse(filterExpression, out root, out error)) + if (!TryParse(filterExpression, out var root, out var error)) throw new ArgumentException(error); return root; @@ -20,9 +17,7 @@ public static bool TryParse(string filterExpression, out FilterExpression root, { if (filterExpression == null) throw new ArgumentNullException(nameof(filterExpression)); - var tokenizer = new FilterExpressionTokenizer(); - var tokenList = tokenizer.TryTokenize(filterExpression); - + var tokenList = FilterExpressionTokenizer.Instance.TryTokenize(filterExpression); if (!tokenList.HasValue) { error = tokenList.ToString(); @@ -30,7 +25,7 @@ public static bool TryParse(string filterExpression, out FilterExpression root, return false; } - var result = FilterExpressionTokenParsers.Expr.AtEnd().TryParse(tokenList.Value); + var result = FilterExpressionTokenParsers.TryParse(tokenList.Value); if (!result.HasValue) { error = result.ToString(); diff --git a/src/Serilog.Filters.Expressions/Filters/Expressions/Parsing/FilterExpressionTokenParsers.cs b/src/Serilog.Filters.Expressions/Filters/Expressions/Parsing/FilterExpressionTokenParsers.cs index f214aff..ff3dac8 100644 --- a/src/Serilog.Filters.Expressions/Filters/Expressions/Parsing/FilterExpressionTokenParsers.cs +++ b/src/Serilog.Filters.Expressions/Filters/Expressions/Parsing/FilterExpressionTokenParsers.cs @@ -4,11 +4,18 @@ using System; using System.Globalization; using System.Linq; +using Superpower.Model; namespace Serilog.Filters.Expressions.Parsing { static class FilterExpressionTokenParsers { + public static TokenListParserResult TryParse( + TokenList input) + { + return Expr.AtEnd().TryParse(input); + } + static readonly TokenListParser Add = Token.EqualTo(FilterExpressionToken.Plus).Value(Operators.OpAdd); static readonly TokenListParser Subtract = Token.EqualTo(FilterExpressionToken.Minus).Value(Operators.OpSubtract); static readonly TokenListParser Multiply = Token.EqualTo(FilterExpressionToken.Asterisk).Value(Operators.OpMultiply); @@ -130,7 +137,7 @@ from factor in Factor static readonly TokenListParser Disjunction = Parse.Chain(Or, Conjunction, MakeBinary); - public static readonly TokenListParser Expr = Disjunction; + static readonly TokenListParser Expr = Disjunction; static FilterExpression MakeBinary(string operatorName, FilterExpression leftOperand, FilterExpression rightOperand) { diff --git a/src/Serilog.Filters.Expressions/Filters/Expressions/Parsing/FilterExpressionTokenizer.cs b/src/Serilog.Filters.Expressions/Filters/Expressions/Parsing/FilterExpressionTokenizer.cs index 2ab1c90..bdc038b 100644 --- a/src/Serilog.Filters.Expressions/Filters/Expressions/Parsing/FilterExpressionTokenizer.cs +++ b/src/Serilog.Filters.Expressions/Filters/Expressions/Parsing/FilterExpressionTokenizer.cs @@ -27,7 +27,7 @@ class FilterExpressionTokenizer : Tokenizer FilterExpressionToken.Is }; - static readonly FilterExpressionKeyword[] SqlKeywords = + static readonly FilterExpressionKeyword[] Keywords = { new FilterExpressionKeyword("and", FilterExpressionToken.And), new FilterExpressionKeyword("in", FilterExpressionToken.In), @@ -90,7 +90,7 @@ protected override IEnumerable> Tokenize( next = real.Remainder.ConsumeChar(); } - if (next.HasValue && !char.IsPunctuation(next.Value) && !char.IsWhiteSpace(next.Value)) + if (!IsDelimiter(next)) { yield return Result.Empty(next.Location, new[] { "digit" }); } @@ -178,9 +178,16 @@ protected override IEnumerable> Tokenize( } while (next.HasValue); } + static bool IsDelimiter(Result next) + { + return !next.HasValue || + char.IsWhiteSpace(next.Value) || + next.Value < SimpleOps.Length && SimpleOps[next.Value] != FilterExpressionToken.None; + } + static bool TryGetKeyword(TextSpan span, out FilterExpressionToken keyword) { - foreach (var kw in SqlKeywords) + foreach (var kw in Keywords) { if (span.EqualsValueIgnoreCase(kw.Text)) { @@ -192,5 +199,7 @@ static bool TryGetKeyword(TextSpan span, out FilterExpressionToken keyword) keyword = FilterExpressionToken.None; return false; } + + public static FilterExpressionTokenizer Instance { get; } = new FilterExpressionTokenizer(); } } diff --git a/src/Serilog.Filters.Expressions/Serilog.Filters.Expressions.csproj b/src/Serilog.Filters.Expressions/Serilog.Filters.Expressions.csproj index 26aa862..1f10000 100644 --- a/src/Serilog.Filters.Expressions/Serilog.Filters.Expressions.csproj +++ b/src/Serilog.Filters.Expressions/Serilog.Filters.Expressions.csproj @@ -23,7 +23,7 @@ - + diff --git a/test/Serilog.Filters.Expressions.Tests/FilterExpressionParserTests.cs b/test/Serilog.Filters.Expressions.Tests/FilterExpressionParserTests.cs index 034a231..4c771ec 100644 --- a/test/Serilog.Filters.Expressions.Tests/FilterExpressionParserTests.cs +++ b/test/Serilog.Filters.Expressions.Tests/FilterExpressionParserTests.cs @@ -38,6 +38,7 @@ public class FilterExpressionParserTests [InlineData("@EventType = 0xC0ffee", "Equal(@EventType,12648430)")] [InlineData("@Level in ['Error', 'Warning']", "_Internal_In(@Level,[@\"Error\",@\"Warning\"])")] [InlineData("5 not in [1, 2]", "_Internal_NotIn(5,[1,2])")] + [InlineData("1+1", "Add(1,1)")] public void ValidSyntaxIsAccepted(string input, string expected = null) { var roundTrip = FilterExpressionParser.Parse(input).ToString(); diff --git a/test/Serilog.Filters.Expressions.Tests/PackagingTests.cs b/test/Serilog.Filters.Expressions.Tests/PackagingTests.cs index 07ba975..5cfff1d 100644 --- a/test/Serilog.Filters.Expressions.Tests/PackagingTests.cs +++ b/test/Serilog.Filters.Expressions.Tests/PackagingTests.cs @@ -9,7 +9,7 @@ public class PackagingTests public void AssemblyVersionIsSet() { var version = typeof(LoggerFilterConfigurationExtensions).GetTypeInfo().Assembly.GetName().Version; - Assert.Equal("1", version.ToString(1)); + Assert.Equal("2", version.ToString(1)); } } } From 8b9ded8800da24ed958b43b5e5598c103d62ed3e Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Mon, 11 Jun 2018 08:32:19 +1000 Subject: [PATCH 6/6] Superpower v2 final --- .../Serilog.Filters.Expressions.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Filters.Expressions/Serilog.Filters.Expressions.csproj b/src/Serilog.Filters.Expressions/Serilog.Filters.Expressions.csproj index 1f10000..9531817 100644 --- a/src/Serilog.Filters.Expressions/Serilog.Filters.Expressions.csproj +++ b/src/Serilog.Filters.Expressions/Serilog.Filters.Expressions.csproj @@ -23,7 +23,7 @@ - +