Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #38 from datalust/dev
Browse files Browse the repository at this point in the history
2.0.0 Release
  • Loading branch information
nblumhardt authored Feb 23, 2022
2 parents 794a8cd + 48ffec4 commit 360c3c7
Show file tree
Hide file tree
Showing 20 changed files with 161 additions and 65 deletions.
19 changes: 16 additions & 3 deletions Build.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$ErrorActionPreference = 'Stop'

$framework = 'net5.0'
$framework = 'net6.0'

function Clean-Output
{
Expand All @@ -25,11 +25,13 @@ function Create-ArtifactDir

function Publish-Archives($version)
{
$rids = @("linux-x64", "linux-musl-x64", "linux-arm64", "osx-x64", "win-x64")
$rids = @("linux-x64", "linux-musl-x64", "linux-arm64", "osx-x64", "win-x64", "osx-arm64")
foreach ($rid in $rids) {
$tfm = $framework

& dotnet publish ./src/Datalust.ClefTool/Datalust.ClefTool.csproj -c Release -f $tfm -r $rid /p:VersionPrefix=$version
& dotnet publish ./src/Datalust.ClefTool/Datalust.ClefTool.csproj -c Release -f $tfm -r $rid --self-contained `
/p:VersionPrefix=$version /p:PublishSingleFile=true /p:PublishReadyToRun=true

if($LASTEXITCODE -ne 0) { exit 4 }

# Make sure the archive contains a reasonable root filename
Expand All @@ -38,6 +40,9 @@ function Publish-Archives($version)
if ($rid.StartsWith("win-")) {
& ./build/7-zip/7za.exe a -tzip ./artifacts/clef-$version-$rid.zip ./src/Datalust.ClefTool/bin/Release/$tfm/$rid/clef-$version-$rid/
if($LASTEXITCODE -ne 0) { exit 5 }

# Back to the original directory name
mv ./src/Datalust.ClefTool/bin/Release/$tfm/$rid/clef-$version-$rid/ ./src/Datalust.ClefTool/bin/Release/$tfm/$rid/publish/
} else {
& ./build/7-zip/7za.exe a -ttar clef-$version-$rid.tar ./src/Datalust.ClefTool/bin/Release/$tfm/$rid/clef-$version-$rid/
if($LASTEXITCODE -ne 0) { exit 5 }
Expand All @@ -53,6 +58,13 @@ function Publish-Archives($version)
}
}

function Publish-DotNetTool($version)
{
# Tool packages have to target a single non-platform-specific TFM; doing this here is cleaner than attempting it in the CSPROJ directly
& dotnet pack ./src/Datalust.ClefTool/Datalust.ClefTool.csproj -c Release --output ./artifacts /p:VersionPrefix=$version /p:TargetFrameworks=$framework
if($LASTEXITCODE -ne 0) { exit 7 }
}

Push-Location $PSScriptRoot

$version = @{ $true = $env:APPVEYOR_BUILD_VERSION; $false = "99.99.99" }[$env:APPVEYOR_BUILD_VERSION -ne $NULL];
Expand All @@ -62,6 +74,7 @@ Clean-Output
Create-ArtifactDir
Restore-Packages
Publish-Archives($version)
Publish-DotNetTool($version)
Execute-Tests

Pop-Location
56 changes: 41 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,53 @@ The `clef` command-line tool reads and processes the newline-delimited JSON stre

### What does CLEF look like?

CLEF is a very simple, compact JSON event format with standardized fields for timestamps, messages, levels and so-on.
[CLEF](https://clef-json.org) is a very simple, compact JSON event format with standardized fields for timestamps, messages, levels and so-on.

```json
{"@t":"2017-05-09T01:23:45.67890Z","@mt":"Starting up","MachineName":"web-53a889fe"}
{"@t":"2022-05-09T01:23:45.67890Z","@mt":"Starting up","MachineName":"web-53a889fe"}
```

### Getting started

[Binary releases](https://github.com/datalust/clef-tool/releases) can be downloaded directly from this project.

Or, if you have `dotnet` installed, `clef` can be installed as a global tool using:

```
dotnet tool install --global Datalust.ClefTool
```

And run with:

```
dotnet clef --help
```

### Reading CLEF files

The default action, given a CLEF file, will be to pretty-print it in text format to the console.

```
> clef -i log-20170509.clef
[2017-05-09T01:23:45.67890Z INF] Starting up
[2017-05-09T01:23:45.96950Z INF] Checking for updates to version 123.4
> clef -i log-20220509.clef
[2022-05-09T01:23:45.67890Z INF] Starting up
[2022-05-09T01:23:45.96950Z INF] Checking for updates to version 123.4
...
```

The tool also accepts events on STDIN:

```
> cat log-20170509.clef | clef
> cat log-20220509.clef | clef
...
```

### Filtering

Expressions using the [_Serilog.Filters.Expressions_](https://github.com/serilog/serilog-filters-expressions) syntax can be specified to filter the stream:
Expressions using the [_Serilog.Expressions_](https://github.com/serilog/serilog-expressions) syntax can be specified to filter the stream:

```
> clef -i log-20170509.clef --filter="Version > 100"
[2017-05-09T01:23:45.96950Z INF] Checking for updates to version 123.4
> clef -i log-20220509.clef --filter="Version > 100"
[2022-05-09T01:23:45.96950Z INF] Checking for updates to version 123.4
```

### Formats
Expand All @@ -44,15 +60,15 @@ Output will be plain text unless another format is specified.
Write the output in JSON format using `--format-json`:

```
> clef -i log-20170509.clef --format-json
{"@t":"2017-05-09T01:23:45.67890Z","@mt":"Starting up"}
> clef -i log-20220509.clef --format-json
{"@t":"2022-05-09T01:23:45.67890Z","@mt":"Starting up"}
...
```

Control the output text format using `--format-template`:

```
> clef -i log-20170509.clef --format-template="{Message}{NewLine}"
> clef -i log-20220509.clef --format-template="{@m}{NewLine()}"
Starting up
...
```
Expand All @@ -64,20 +80,30 @@ Output will be written to STDOUT unless another destination is specified.
Write output to a file with `-o`:

```
> clef -i log-20170509.clef -o log-20170509.txt
> clef -i log-20220509.clef -o log-20220509.txt
```

Send the output to [Seq](https://getseq.net) by specifying a server URL and optional API key:

```
> clef -i log-20170509.clef --out-seq="https://seq.example.com" --out-seq-apikey="1234567890"
> clef -i log-20220509.clef --out-seq="https://seq.example.com" --out-seq-apikey="1234567890"
```

### Enrichment

Events can be enriched with additional properties by specifying them using the `-p` switch:

```
> clef -i log-20170509.clef -p CustomerId=C123 -p Environment=Support [...]
> clef -i log-20220509.clef -p CustomerId=C123 -p Environment=Support [...]
```

### Filter and template syntax

The syntax supported in the `--filter` and `--format-template` arguments is documented in the
[_Serilog.Expressions_ language reference](https://github.com/serilog/serilog-expressions#language-reference).

The following functions are added:

| Function | Description |
|:------------|:----------------------------------------------------------------------------------------|
| `NewLine()` | Returns a platform-dependent newline character (supported in `--format-template` only). |
13 changes: 10 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
version: 1.1.{build}
version: 2.0.{build}
skip_tags: true
image: Visual Studio 2019
image: Visual Studio 2022
build_script:
- ps: ./Build.ps1
test: off
artifacts:
- path: artifacts/clef-*.zip
- path: artifacts/clef-*.tar.gz
- path: artifacts/clef.*.nupkg
- path: artifacts/Datalust.ClefTool.*.nupkg
deploy:
- provider: GitHub
auth_token:
secure: Bo3ypKpKFxinjR9ShkNekNvkob2iklHJU+UlYyfHtcFFIAa58SV2TkEd0xWxz633
tag: v$(appveyor_build_version)
on:
branch: main
- provider: NuGet
api_key:
secure: qtcwO3xYGEpN9X+BQNViwuuIJfGBEExqoctZoFFkPsnCz5/mY87S55M+gCDprrno
skip_symbols: true
artifact: /Datalust.ClefTool\..*\.nupkg/
on:
branch: main
7 changes: 1 addition & 6 deletions src/Datalust.ClefTool/Cli/CommandLineHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Autofac.Features.Metadata;

namespace Datalust.ClefTool.Cli
Expand All @@ -30,11 +28,8 @@ public CommandLineHost(IEnumerable<Meta<Lazy<Command>, CommandMetadata>> availab
_availableCommands = availableCommands.ToList();
}

public int Run(string[] args, TextWriter cout, TextWriter cerr)
public int Run(string[] args)
{
var ea = Assembly.GetEntryAssembly();
var name = ea.GetName().Name;

if (args.Length > 0)
{
var norm = args[0].ToLowerInvariant();
Expand Down
4 changes: 2 additions & 2 deletions src/Datalust.ClefTool/Cli/CommandMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Datalust.ClefTool.Cli
{
public class CommandMetadata : ICommandMetadata
{
public string Name { get; set; }
public string HelpText { get; set; }
public string Name { get; set; } = null!;
public string HelpText { get; set; } = null!;
}
}
2 changes: 1 addition & 1 deletion src/Datalust.ClefTool/Cli/Commands/HelpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected override int Run(string[] unrecognised)
{
// This is a little hacky; we always show the help for the (anonymous) "pipe" command.

var ea = Assembly.GetEntryAssembly();
var ea = Assembly.GetEntryAssembly()!;
var name = ea.GetName().Name;

var cmd = _availableCommands.SingleOrDefault(c => c.Metadata.Name == "pipe");
Expand Down
15 changes: 8 additions & 7 deletions src/Datalust.ClefTool/Cli/Commands/PipeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
using System.IO;
using Datalust.ClefTool.Cli.Features;
using Datalust.ClefTool.Pipe;
using Datalust.ClefTool.Syntax;
using Serilog;
using Serilog.Core;
using Serilog.Debugging;
using Serilog.Events;
using Serilog.Formatting.Compact;
using Serilog.Formatting.Compact.Reader;
using Serilog.Formatting.Display;
using Serilog.Templates;
using Serilog.Templates.Themes;

// ReSharper disable UnusedType.Global

Expand All @@ -27,7 +29,7 @@ class PipeCommand : Command
readonly SeqOutputFeature _seqOutputFeature;
readonly InvalidDataHandlingFeature _invalidDataHandlingFeature;

const string DefaultOutputTemplate = "[{Timestamp:o} {Level:u3}] {Message} {Properties}{NewLine}{Exception}";
static readonly string DefaultOutputTemplate = "[{@t:o} {@l:u3}] {@m:lj} {rest(true)}" + Environment.NewLine + "{@x}";

public PipeCommand()
{
Expand Down Expand Up @@ -91,14 +93,13 @@ protected override int Run()
var template = _templateFormatFeature.OutputTemplate ?? DefaultOutputTemplate;
if (_fileOutputFeature.OutputFilename != null)
{
// This will differ slightly from the console output until `{Message:l}` becomes available
configuration.AuditTo.File(
new MessageTemplateTextFormatter(template, CultureInfo.InvariantCulture),
_fileOutputFeature.OutputFilename);
var formatter = new ExpressionTemplate(template, CultureInfo.InvariantCulture, new ClefToolNameResolver());
configuration.AuditTo.File(formatter, _fileOutputFeature.OutputFilename);
}
else
{
configuration.WriteTo.Console(outputTemplate: template);
var formatter = new ExpressionTemplate(template, CultureInfo.InvariantCulture, new ClefToolNameResolver(), TemplateTheme.Literate);
configuration.WriteTo.Console(formatter);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Datalust.ClefTool/Cli/Commands/VersionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class VersionCommand : Command
{
protected override int Run()
{
var version = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
var version = Assembly.GetEntryAssembly()!.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion;
Console.WriteLine(version);
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Datalust.ClefTool/Cli/Features/EnrichFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ namespace Datalust.ClefTool.Cli.Features
{
class EnrichFeature : CommandFeature
{
readonly Dictionary<string, object> _properties = new Dictionary<string, object>();
readonly Dictionary<string, object?> _properties = new();

public Dictionary<string, object> Properties => _properties;
public Dictionary<string, object?> Properties => _properties;

public override void Enable(OptionSet options)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Datalust.ClefTool/Cli/Features/FileInputFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Datalust.ClefTool.Cli.Features
{
class FileInputFeature : CommandFeature
{
public string InputFilename { get; private set; }
public string? InputFilename { get; private set; }

public override void Enable(OptionSet options)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Datalust.ClefTool/Cli/Features/FileOutputFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Datalust.ClefTool.Cli.Features
{
class FileOutputFeature : CommandFeature
{
public string OutputFilename { get; private set; }
public string? OutputFilename { get; private set; }

public override void Enable(OptionSet options)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Datalust.ClefTool/Cli/Features/FilterFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Datalust.ClefTool.Cli.Features
{
class FilterFeature : CommandFeature
{
public string Filter { get; set; }
public string? Filter { get; set; }

public override void Enable(OptionSet options)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Datalust.ClefTool/Cli/Features/SeqOutputFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ namespace Datalust.ClefTool.Cli.Features
{
class SeqOutputFeature : CommandFeature
{
public string SeqUrl { get; private set; }
public string SeqApiKey { get; private set; }
public string? SeqUrl { get; private set; }
public string? SeqApiKey { get; private set; }
public int BatchPostingLimit { get; private set; } = 100;
public long? EventBodyLimitBytes { get; private set; } = 256 * 1000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Datalust.ClefTool.Cli.Features
{
class TemplateFormatFeature : CommandFeature
{
public string OutputTemplate { get; private set; }
public string? OutputTemplate { get; private set; }

public override void Enable(OptionSet options)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Datalust.ClefTool/Cli/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@
using System.Text;
using System.Text.RegularExpressions;

#nullable disable

#if LINQ
using System.Linq;
#endif
Expand Down
Loading

0 comments on commit 360c3c7

Please sign in to comment.