Skip to content

Commit

Permalink
Merge pull request #15 from serilog/dev
Browse files Browse the repository at this point in the history
3.0.1 Release
  • Loading branch information
nblumhardt authored Jun 23, 2017
2 parents aea8738 + 928cb12 commit 70dd370
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 59 deletions.
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: csharp

matrix:
include:
- os: linux # Ubuntu 14.04
dist: trusty
sudo: required
dotnet: 1.0.4
group: edge

script:
- ./build.sh
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,12 @@ To achieve output identical to version 2 of this sink, specify a formatter and o

This will bypass theming and use Serilog's built-in message template formatting.

### Detailed build status

Branch | AppVeyor | Travis
------------- | ------------- |-------------
dev | [![Build status](https://ci.appveyor.com/api/projects/status/w1w3m1wyk3in1c96/branch/dev?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-console/branch/dev) | [![Build Status](https://travis-ci.org/serilog/serilog-sinks-console.svg?branch=dev)](https://travis-ci.org/serilog/serilog-sinks-console)
master | [![Build status](https://ci.appveyor.com/api/projects/status/w1w3m1wyk3in1c96/branch/master?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-console/branch/master) | [![Build Status](https://travis-ci.org/serilog/serilog-sinks-console.svg?branch=master)](https://travis-ci.org/serilog/serilog-sinks-console)


_Copyright © 2017 Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html)._
19 changes: 19 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -e
dotnet --info
dotnet restore

for path in src/**/*.csproj; do
dotnet build -f netstandard1.3 -c Release ${path}
dotnet build -f netcoreapp1.1 -c Release ${path}
done

for path in test/*.Tests/*.csproj; do
dotnet test -f netcoreapp1.1 -c Release ${path}
done

for path in sample/ConsoleDemo/*.csproj; do
dotnet build -f netcoreapp1.1 -c Release ${path}
dotnet run -f netcoreapp1.1 --project ${path}
done
2 changes: 1 addition & 1 deletion src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Description>A Serilog sink that writes log events to the console/terminal.</Description>
<VersionPrefix>3.0.0</VersionPrefix>
<VersionPrefix>3.0.1</VersionPrefix>
<Authors>Serilog Contributors</Authors>
<TargetFrameworks>net45;netstandard1.3;netcoreapp1.1</TargetFrameworks>
<AssemblyName>Serilog.Sinks.Console</AssemblyName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ value is decimal || value is byte || value is sbyte || value is short ||

if (value is char ch)
{
using (ApplyStyle(output, ConsoleThemeStyle.String, ref count))
using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count))
{
output.Write('\'');
output.Write(ch);
Expand All @@ -194,7 +194,7 @@ value is decimal || value is byte || value is sbyte || value is short ||
}
}

using (ApplyStyle(output, ConsoleThemeStyle.Object, ref count))
using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count))
scalar.Render(output, format, _formatProvider);

return count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ protected override int VisitScalarValue(ThemedValueFormatterState state, ScalarV
{
if (scalar == null)
throw new ArgumentNullException(nameof(scalar));
return FormatLiteralValue(scalar, state.Output, state.Format);

// At the top level, for scalar values, use "display" rendering.
if (state.IsTopLevel)
return _displayFormatter.FormatLiteralValue(scalar, state.Output, state.Format);

return FormatLiteralValue(scalar, state.Output);
}

protected override int VisitSequenceValue(ThemedValueFormatterState state, SequenceValue sequence)
Expand All @@ -63,7 +68,7 @@ protected override int VisitSequenceValue(ThemedValueFormatterState state, Seque
state.Output.Write(delim);

delim = ", ";
Visit(state, sequence.Elements[index]);
Visit(state.Nest(), sequence.Elements[index]);
}

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
Expand Down Expand Up @@ -96,8 +101,9 @@ protected override int VisitStructureValue(ThemedValueFormatterState state, Stru
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
state.Output.Write(": ");

count += Visit(state, property.Value);
count += Visit(state.Nest(), property.Value);
}

if (structure.TypeTag != null)
{
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
Expand All @@ -121,7 +127,7 @@ protected override int VisitStructureValue(ThemedValueFormatterState state, Stru

protected override int VisitDictionaryValue(ThemedValueFormatterState state, DictionaryValue dictionary)
{
int count = 0;
var count = 0;

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
state.Output.Write('{');
Expand All @@ -135,13 +141,19 @@ protected override int VisitDictionaryValue(ThemedValueFormatterState state, Dic

delim = ", ";

using (ApplyStyle(state.Output, ConsoleThemeStyle.String, ref count))
var style = element.Key.Value == null
? ConsoleThemeStyle.Null
: element.Key.Value is string
? ConsoleThemeStyle.String
: ConsoleThemeStyle.Scalar;

using (ApplyStyle(state.Output, style, ref count))
JsonValueFormatter.WriteQuotedJsonString((element.Key.Value ?? "null").ToString(), state.Output);

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
state.Output.Write(": ");

count += Visit(state, element.Value);
count += Visit(state.Nest(), element.Value);
}

using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
Expand All @@ -150,12 +162,8 @@ protected override int VisitDictionaryValue(ThemedValueFormatterState state, Dic
return count;
}

int FormatLiteralValue(ScalarValue scalar, TextWriter output, string format)
int FormatLiteralValue(ScalarValue scalar, TextWriter output)
{
// At the top level, if a format string is specified, non-JSON rendering is used.
if (format != null)
return _displayFormatter.FormatLiteralValue(scalar, output, format);

var value = scalar.Value;
var count = 0;

Expand All @@ -175,7 +183,7 @@ int FormatLiteralValue(ScalarValue scalar, TextWriter output, string format)

if (value is ValueType)
{
if (value is int || value is uint || value is long || value is ulong || value is decimal || value is byte || (value is sbyte || value is short) || value is ushort)
if (value is int || value is uint || value is long || value is ulong || value is decimal || value is byte || value is sbyte || value is short || value is ushort)
{
using (ApplyStyle(output, ConsoleThemeStyle.Number, ref count))
output.Write(((IFormattable)value).ToString(null, CultureInfo.InvariantCulture));
Expand All @@ -184,23 +192,25 @@ int FormatLiteralValue(ScalarValue scalar, TextWriter output, string format)

if (value is double d)
{
if (double.IsNaN(d) || double.IsInfinity(d))
using (ApplyStyle(output, ConsoleThemeStyle.String, ref count))
using (ApplyStyle(output, ConsoleThemeStyle.Number, ref count))
{
if (double.IsNaN(d) || double.IsInfinity(d))
JsonValueFormatter.WriteQuotedJsonString(d.ToString(CultureInfo.InvariantCulture), output);
else
using (ApplyStyle(output, ConsoleThemeStyle.Number, ref count))
else
output.Write(d.ToString("R", CultureInfo.InvariantCulture));
}
return count;
}

if (value is float f)
{
if (double.IsNaN(f) || double.IsInfinity(f))
using (ApplyStyle(output, ConsoleThemeStyle.String, ref count))
using (ApplyStyle(output, ConsoleThemeStyle.Number, ref count))
{
if (double.IsNaN(f) || double.IsInfinity(f))
JsonValueFormatter.WriteQuotedJsonString(f.ToString(CultureInfo.InvariantCulture), output);
else
using (ApplyStyle(output, ConsoleThemeStyle.Number, ref count))
else
output.Write(f.ToString("R", CultureInfo.InvariantCulture));
}
return count;
}

Expand All @@ -214,14 +224,14 @@ int FormatLiteralValue(ScalarValue scalar, TextWriter output, string format)

if (value is char ch)
{
using (ApplyStyle(output, ConsoleThemeStyle.String, ref count))
using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count))
JsonValueFormatter.WriteQuotedJsonString(ch.ToString(), output);
return count;
}

if (value is DateTime || value is DateTimeOffset)
{
using (ApplyStyle(output, ConsoleThemeStyle.String, ref count))
using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count))
{
output.Write('"');
output.Write(((IFormattable)value).ToString("O", CultureInfo.InvariantCulture));
Expand All @@ -231,7 +241,7 @@ int FormatLiteralValue(ScalarValue scalar, TextWriter output, string format)
}
}

using (ApplyStyle(output, ConsoleThemeStyle.String, ref count))
using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count))
JsonValueFormatter.WriteQuotedJsonString(value.ToString(), output);

return count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ protected StyleReset ApplyStyle(TextWriter output, ConsoleThemeStyle style, ref
return _theme.Apply(output, style, ref invisibleCharacterCount);
}

public int Format(LogEventPropertyValue value, TextWriter output, string format)
public int Format(LogEventPropertyValue value, TextWriter output, string format, bool literalTopLevel = false)
{
return Visit(new ThemedValueFormatterState { Output = output, Format = format }, value);
return Visit(new ThemedValueFormatterState { Output = output, Format = format, IsTopLevel = literalTopLevel }, value);
}

public abstract ThemedValueFormatter SwitchTheme(ConsoleTheme theme);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct ThemedValueFormatterState
{
public TextWriter Output;
public string Format;
public bool IsTopLevel;

public ThemedValueFormatterState Nest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ int RenderAlignedPropertyTokenUnbuffered(PropertyToken pt, TextWriter output, Lo

int RenderValue(ConsoleTheme theme, ThemedValueFormatter valueFormatter, LogEventPropertyValue propertyValue, TextWriter output, string format)
{
if (_isLiteral && propertyValue is ScalarValue sv && (sv.Value is string str || sv.Value is char ch))
if (_isLiteral && propertyValue is ScalarValue sv && sv.Value is string)
{
var count = 0;
using (theme.Apply(output, ConsoleThemeStyle.String, ref count))
output.Write(sv.Value);
return count;
}

return valueFormatter.Format(propertyValue, output, format);
return valueFormatter.Format(propertyValue, output, format, _isLiteral);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ static class AnsiConsoleThemes
public static AnsiConsoleTheme Literate { get; } = new AnsiConsoleTheme(
new Dictionary<ConsoleThemeStyle, string>
{
[ConsoleThemeStyle.Text] = "\x1b[37;1m",
[ConsoleThemeStyle.SecondaryText] = "\x1b[37m",
[ConsoleThemeStyle.TertiaryText] = "\x1b[30;1m",
[ConsoleThemeStyle.Invalid] = "\x1b[33;1m",
[ConsoleThemeStyle.Null] = "\x1b[34;1m",
[ConsoleThemeStyle.Name] = "\x1b[37m",
[ConsoleThemeStyle.String] = "\x1b[36;1m",
[ConsoleThemeStyle.Number] = "\x1b[35;1m",
[ConsoleThemeStyle.Boolean] = "\x1b[34;1m",
[ConsoleThemeStyle.Object] = "\x1b[32;1m",
[ConsoleThemeStyle.LevelVerbose] = "\x1b[37m",
[ConsoleThemeStyle.LevelDebug] = "\x1b[37m",
[ConsoleThemeStyle.LevelInformation] = "\x1b[37;1m",
[ConsoleThemeStyle.LevelWarning] = "\x1b[33;1m",
[ConsoleThemeStyle.LevelError] = "\x1b[37;1m\x1b[41;1m",
[ConsoleThemeStyle.LevelFatal] = "\x1b[37;1m\x1b[41;1m"
[ConsoleThemeStyle.Text] = "\x1b[38;5;0015m",
[ConsoleThemeStyle.SecondaryText] = "\x1b[38;5;0007m",
[ConsoleThemeStyle.TertiaryText] = "\x1b[38;5;0008m",
[ConsoleThemeStyle.Invalid] = "\x1b[38;5;0011m",
[ConsoleThemeStyle.Null] = "\x1b[38;5;0027m",
[ConsoleThemeStyle.Name] = "\x1b[38;5;0007m",
[ConsoleThemeStyle.String] = "\x1b[38;5;0045m",
[ConsoleThemeStyle.Number] = "\x1b[38;5;0200m",
[ConsoleThemeStyle.Boolean] = "\x1b[38;5;0027m",
[ConsoleThemeStyle.Scalar] = "\x1b[38;5;0085m",
[ConsoleThemeStyle.LevelVerbose] = "\x1b[38;5;0007m",
[ConsoleThemeStyle.LevelDebug] = "\x1b[38;5;0007m",
[ConsoleThemeStyle.LevelInformation] = "\x1b[38;5;0015m",
[ConsoleThemeStyle.LevelWarning] = "\x1b[38;5;0011m",
[ConsoleThemeStyle.LevelError] = "\x1b[38;5;0015m\x1b[48;5;0196m",
[ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0015m\x1b[48;5;0196m"
});

public static AnsiConsoleTheme Grayscale { get; } = new AnsiConsoleTheme(
Expand All @@ -51,7 +51,7 @@ static class AnsiConsoleThemes
[ConsoleThemeStyle.String] = "\x1b[1m\x1b[37;1m",
[ConsoleThemeStyle.Number] = "\x1b[1m\x1b[37;1m",
[ConsoleThemeStyle.Boolean] = "\x1b[1m\x1b[37;1m",
[ConsoleThemeStyle.Object] = "\x1b[1m\x1b[37;1m",
[ConsoleThemeStyle.Scalar] = "\x1b[1m\x1b[37;1m",
[ConsoleThemeStyle.LevelVerbose] = "\x1b[30;1m",
[ConsoleThemeStyle.LevelDebug] = "\x1b[30;1m",
[ConsoleThemeStyle.LevelInformation] ="\x1b[37;1m",
Expand All @@ -72,7 +72,7 @@ static class AnsiConsoleThemes
[ConsoleThemeStyle.String] = "\x1b[38;5;0216m",
[ConsoleThemeStyle.Number] = "\x1b[38;5;151m",
[ConsoleThemeStyle.Boolean] = "\x1b[38;5;0038m",
[ConsoleThemeStyle.Object] = "\x1b[38;5;0079m",
[ConsoleThemeStyle.Scalar] = "\x1b[38;5;0079m",
[ConsoleThemeStyle.LevelVerbose] = "\x1b[37m",
[ConsoleThemeStyle.LevelDebug] = "\x1b[37m",
[ConsoleThemeStyle.LevelInformation] = "\x1b[37;1m",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.ComponentModel;

namespace Serilog.Sinks.SystemConsole.Themes
{
/// <summary>
Expand Down Expand Up @@ -66,10 +69,16 @@ public enum ConsoleThemeStyle
/// </summary>
Boolean,

/// <summary>
/// All other scalar values, e.g. <see cref="System.Guid"/> instances.
/// </summary>
Scalar,

/// <summary>
/// Unrecogized literal values, e.g. <see cref="System.Guid"/> instances.
/// </summary>
Object,
[Obsolete("Use ConsoleThemeStyle.Scalar instead"), EditorBrowsable(EditorBrowsableState.Never)]
Object = Scalar,

/// <summary>
/// Level indicator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static class SystemConsoleThemes
[ConsoleThemeStyle.String] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Cyan },
[ConsoleThemeStyle.Number] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Magenta },
[ConsoleThemeStyle.Boolean] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Blue },
[ConsoleThemeStyle.Object] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Green },
[ConsoleThemeStyle.Scalar] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Green },
[ConsoleThemeStyle.LevelVerbose] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Gray },
[ConsoleThemeStyle.LevelDebug] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.Gray },
[ConsoleThemeStyle.LevelInformation] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White },
Expand All @@ -52,7 +52,7 @@ static class SystemConsoleThemes
[ConsoleThemeStyle.String] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White },
[ConsoleThemeStyle.Number] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White },
[ConsoleThemeStyle.Boolean] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White },
[ConsoleThemeStyle.Object] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White },
[ConsoleThemeStyle.Scalar] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White },
[ConsoleThemeStyle.LevelVerbose] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.DarkGray },
[ConsoleThemeStyle.LevelDebug] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.DarkGray },
[ConsoleThemeStyle.LevelInformation] = new SystemConsoleThemeStyle { Foreground = ConsoleColor.White },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ public TestThemedJsonValueFormatter()
public string Format(object literal)
{
var output = new StringWriter();
Format(new ScalarValue(literal), output, null);
return output.ToString();
Format(new SequenceValue(new [] {new ScalarValue(literal)}), output, null);
var o = output.ToString();
return o.Substring(1, o.Length - 2);
}
}

Expand Down
Loading

0 comments on commit 70dd370

Please sign in to comment.