Skip to content
This repository has been archived by the owner on Feb 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #19 from serilog/dev
Browse files Browse the repository at this point in the history
1.1.0 Release
  • Loading branch information
nblumhardt authored Nov 22, 2017
2 parents 3fdfc0f + 380a596 commit 337a919
Show file tree
Hide file tree
Showing 40 changed files with 431 additions and 294 deletions.
31 changes: 20 additions & 11 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,49 @@ if(Test-Path .\artifacts) {
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL];
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"]
$commitHash = $(git rev-parse --short HEAD)
$buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""]

echo "build: Version suffix is $suffix"
echo "build: Package version suffix is $suffix"
echo "build: Build version suffix is $buildSuffix"

foreach ($src in ls src/*) {
Push-Location $src

echo "build: Packaging project in $src"

& dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix
& dotnet build -c Release --version-suffix=$buildSuffix

if($suffix) {
& dotnet pack -c Release --include-source --no-build -o ..\..\artifacts --version-suffix=$suffix
} else {
& dotnet pack -c Release --include-source --no-build -o ..\..\artifacts
}
if($LASTEXITCODE -ne 0) { exit 1 }

Pop-Location
}

foreach ($test in ls test/*.PerformanceTests) {
foreach ($test in ls test/*.Tests) {
Push-Location $test

echo "build: Building performance test project in $test"
echo "build: Testing project in $test"

& dotnet build -c Release
if($LASTEXITCODE -ne 0) { exit 2 }
& dotnet test -c Release
if($LASTEXITCODE -ne 0) { exit 3 }

Pop-Location
}

foreach ($test in ls test/*.Tests) {
foreach ($test in ls test/*.PerformanceTests) {
Push-Location $test

echo "build: Testing project in $test"
echo "build: Building performance test project in $test"

& dotnet test -c Release
if($LASTEXITCODE -ne 0) { exit 3 }
& dotnet build -c Release
if($LASTEXITCODE -ne 0) { exit 2 }

Pop-Location
}

Pop-Location
Pop-Location
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Serilog.Filters.Expressions [![Build status](https://ci.appveyor.com/api/projects/status/wnh0ig2udlld9oe4?svg=true)](https://ci.appveyor.com/project/serilog/serilog-filters-expressions) [![NuGet Pre Release](https://img.shields.io/nuget/vpre/Serilog.Filters.Expressions.svg)](https://nuget.org/packages/serilog.filters.expressions)
# Serilog.Filters.Expressions [![Build status](https://ci.appveyor.com/api/projects/status/wnh0ig2udlld9oe4?svg=true)](https://ci.appveyor.com/project/serilog/serilog-filters-expressions) [![NuGet Release](https://img.shields.io/nuget/v/Serilog.Filters.Expressions.svg)](https://nuget.org/packages/serilog.filters.expressions)

Expression-based event filtering for [Serilog](https://serilog.net).

Expand All @@ -8,7 +8,7 @@ var expr = "@Level = 'Information' and AppId is not null and Items[?] like 'C%'"
Log.Logger = new LoggerConfiguration()
.Enrich.WithProperty("AppId", 10)
.Filter.ByIncludingOnly(expr)
.WriteTo.LiterateConsole()
.WriteTo.Console()
.CreateLogger();

// Printed
Expand Down Expand Up @@ -40,10 +40,10 @@ The syntax is based on SQL, with added support for object structures, arrays, an
| :--- | :--- |
| **Literals** | `123`, `123.4`, `'Hello'`, `true`, `false`, `null` |
| **Properties** | `A`, `A.B`, `@Level`, `@Timestamp`, `@Exception`, `@Message`, `@MessageTemplate`, `@Properties['A-b-c']` |
| **Comparisons** | `A = B`, `A <> B`, `A > B`, `A >= B`, `A is null`, `A is not null` |
| **Text** | `A like 'H%'`, `A not like 'H%'`, `A like 'Hel_o'`, `Contains(A, 'H')`, `StartsWith(A, 'H')`, `EndsWith(A, 'H')`, `IndexOf(A, 'H')` |
| **Comparisons** | `A = B`, `A <> B`, `A > B`, `A >= B`, `A is null`, `A is not null`, `A in [1, 2]` |
| **Text** | `A like 'H%'`, `A not like 'H%'`, `A like 'Hel_o'`, `Contains(A, 'H')`, `StartsWith(A, 'H')`, `EndsWith(A, 'H')`, `IndexOf(A, 'H')`, `Length(A)` |
| **Regular expressions** | `A = /H.*o/`, `Contains(A, /[lL]/)`, other string functions |
| **Collections** | `A[0] = 'Hello'`, `A[?] = 'Hello'` (any), `StartsWith(A[*], 'H')` (all) |
| **Collections** | `A[0] = 'Hello'`, `A[?] = 'Hello'` (any), `StartsWith(A[*], 'H')` (all), `Length(A)` |
| **Maths** | `A + 2`, `A - 2`, `A * 2`, `A % 2` |
| **Logic** | `not A`, `A and B`, `A or B` |
| **Grouping** | `A * (B + C)` |
Expand Down
9 changes: 1 addition & 8 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
version: '{build}'
skip_tags: true
image: Visual Studio 2015
configuration: Release
install:
- ps: mkdir -Force ".\build\" | Out-Null
- ps: Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview2/scripts/obtain/dotnet-install.ps1" -OutFile ".\build\installcli.ps1"
- ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetcli"
- ps: '& .\build\installcli.ps1 -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath -Version 1.0.0-preview2-003131'
- ps: $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path"
image: Visual Studio 2017
build_script:
- ps: ./Build.ps1
test: off
Expand Down
22 changes: 22 additions & 0 deletions example/Sample/Sample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework>
<AssemblyName>Sample</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>Sample</PackageId>
<PackageTargetFallback>$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Serilog.Filters.Expressions\Serilog.Filters.Expressions.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Serilog.Sinks.Literate" Version="2.0.0" />
</ItemGroup>

</Project>
21 changes: 0 additions & 21 deletions example/Sample/Sample.xproj

This file was deleted.

21 changes: 0 additions & 21 deletions example/Sample/project.json

This file was deleted.

6 changes: 0 additions & 6 deletions global.json

This file was deleted.

15 changes: 7 additions & 8 deletions serilog-filters-expressions.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
# Visual Studio 15
VisualStudioVersion = 15.0.26430.15
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{91E482DE-E1E7-4CE1-9511-C0AF07F3648A}"
EndProject
Expand All @@ -11,23 +11,22 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "global", "global", "{24B112
.gitignore = .gitignore
appveyor.yml = appveyor.yml
Build.ps1 = Build.ps1
global.json = global.json
LICENSE = LICENSE
README.md = README.md
RunPerfTests.ps1 = RunPerfTests.ps1
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "example", "example", "{BD94A77E-34B1-478E-B921-E87A5F71B574}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Sample", "example\Sample\Sample.xproj", "{776EECAC-3C50-45EA-847D-0EBE5158E51E}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{B03B3086-D197-4B32-9AE2-8536C345EA2D}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Filters.Expressions", "src\Serilog.Filters.Expressions\Serilog.Filters.Expressions.xproj", "{A420C4E3-3A2D-4369-88EB-77E4DB1D0219}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample", "example\Sample\Sample.csproj", "{776EECAC-3C50-45EA-847D-0EBE5158E51E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{B03B3086-D197-4B32-9AE2-8536C345EA2D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Filters.Expressions", "src\Serilog.Filters.Expressions\Serilog.Filters.Expressions.csproj", "{A420C4E3-3A2D-4369-88EB-77E4DB1D0219}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Filters.Expressions.Tests", "test\Serilog.Filters.Expressions.Tests\Serilog.Filters.Expressions.Tests.xproj", "{3C2D8E01-5580-426A-BDD9-EC59CD98E618}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Filters.Expressions.Tests", "test\Serilog.Filters.Expressions.Tests\Serilog.Filters.Expressions.Tests.csproj", "{3C2D8E01-5580-426A-BDD9-EC59CD98E618}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Filters.Expressions.PerformanceTests", "test\Serilog.Filters.Expressions.PerformanceTests\Serilog.Filters.Expressions.PerformanceTests.xproj", "{D7A37F73-BBA3-4DAE-9648-1A753A86F968}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Filters.Expressions.PerformanceTests", "test\Serilog.Filters.Expressions.PerformanceTests\Serilog.Filters.Expressions.PerformanceTests.csproj", "{D7A37F73-BBA3-4DAE-9648-1A753A86F968}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Linq;

namespace Serilog.Filters.Expressions.Ast
{
class FilterArrayExpression : FilterExpression
{
public FilterArrayExpression(FilterExpression[] elements)
{
Elements = elements ?? throw new ArgumentNullException(nameof(elements));
}

public FilterExpression[] Elements { get; }

public override string ToString()
{
return "[" + string.Join(",", Elements.Select(o => o.ToString())) + "]";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,19 @@ namespace Serilog.Filters.Expressions.Ast
{
class FilterCallExpression : FilterExpression
{
readonly string _operatorName;
readonly FilterExpression[] _operands;

public FilterCallExpression(string operatorName, params FilterExpression[] operands)
{
if (operatorName == null) throw new ArgumentNullException(nameof(operatorName));
if (operands == null) throw new ArgumentNullException(nameof(operands));
_operatorName = operatorName;
_operands = operands;
OperatorName = operatorName ?? throw new ArgumentNullException(nameof(operatorName));
Operands = operands ?? throw new ArgumentNullException(nameof(operands));
}

public string OperatorName
{
get { return _operatorName; }
}
public string OperatorName { get; }

public FilterExpression[] Operands
{
get { return _operands; }
}
public FilterExpression[] Operands { get; }

public override string ToString()
{
if (OperatorName == "ElementAt" && Operands.Length == 2)
if (OperatorName == Operators.OpElementAt && Operands.Length == 2)
{
return Operands[0] + "[" + Operands[1] + "]";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ enum FilterExpressionType
Subproperty,
Wildcard,
Parameter,
Lambda
Lambda,
Array
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Linq;
using Serilog.Events;
using Serilog.Filters.Expressions.Ast;
using Serilog.Filters.Expressions.Compilation.Transformations;
using Serilog.Filters.Expressions.Runtime;

namespace Serilog.Filters.Expressions.Compilation.Arrays
{
class FilterExpressionConstantArrayEvaluator : FilterExpressionIdentityTransformer
{
public static FilterExpression Evaluate(FilterExpression expression)
{
var evaluator = new FilterExpressionConstantArrayEvaluator();
return evaluator.Transform(expression);
}

protected override FilterExpression Transform(FilterArrayExpression ax)
{
// This should probably go depth-first.

if (ax.Elements.All(el => el is FilterConstantExpression))
{
return new FilterConstantExpression(
new SequenceValue(ax.Elements
.Cast<FilterConstantExpression>()
.Select(ce => Representation.Recapture(ce.ConstantValue))));
}

return base.Transform(ax);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Serilog.Filters.Expressions.Ast;
using Serilog.Filters.Expressions.Compilation.Transformations;
using Superpower;
using System.Collections.Generic;
using System.Linq;

Expand Down Expand Up @@ -134,5 +133,10 @@ protected override FilterExpressionCosting Transform(FilterCallExpression lx)
new FilterCallExpression(lx.OperatorName, operands.Select(o => o.Expression).ToArray()),
operands.Sum(o => o.Costing) + 0.1);
}

protected override FilterExpressionCosting Transform(FilterArrayExpression ax)
{
return new FilterExpressionCosting(ax, 0.2);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
using Serilog.Filters.Expressions.Compilation.Text;
using Serilog.Filters.Expressions.Compilation.Wildcards;
using Serilog.Filters.Expressions.Compilation.Properties;
using Serilog.Serilog.Filters.Expressions.Runtime;
using Serilog.Filters.Expressions.Runtime;
using System;
using Serilog.Filters.Expressions.Compilation.Arrays;
using Serilog.Filters.Expressions.Compilation.In;

namespace Serilog.Filters.Expressions.Compilation
{
Expand All @@ -18,6 +20,8 @@ public static Func<LogEvent, object> CompileAndExpose(FilterExpression expressio
{
var actual = expression;
actual = PropertiesObjectAccessorTransformer.Rewrite(actual);
actual = FilterExpressionConstantArrayEvaluator.Evaluate(actual);
actual = FilterExpressionNotInRewriter.Rewrite(actual);
actual = WildcardComprehensionTransformer.Expand(actual);
actual = LikeOperatorTransformer.Rewrite(actual);
actual = IsOperatorTransformer.Rewrite(actual);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Serilog.Filters.Expressions.Ast;
using Serilog.Filters.Expressions.Compilation.Transformations;

namespace Serilog.Filters.Expressions.Compilation.In
{
class FilterExpressionNotInRewriter : FilterExpressionIdentityTransformer
{
public static FilterExpression Rewrite(FilterExpression expression)
{
var rewriter = new FilterExpressionNotInRewriter();
return rewriter.Transform(expression);
}

protected override FilterExpression Transform(FilterCallExpression lx)
{
if (Operators.SameOperator(Operators.IntermediateOpSqlNotIn, lx.OperatorName))
return new FilterCallExpression(Operators.RuntimeOpStrictNot,
new FilterCallExpression(Operators.RuntimeOpSqlIn, lx.Operands));
return base.Transform(lx);
}
}
}
Loading

0 comments on commit 337a919

Please sign in to comment.