Skip to content

Commit 70dd370

Browse files
authored
Merge pull request #15 from serilog/dev
3.0.1 Release
2 parents aea8738 + 928cb12 commit 70dd370

File tree

14 files changed

+120
-59
lines changed

14 files changed

+120
-59
lines changed

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: csharp
2+
3+
matrix:
4+
include:
5+
- os: linux # Ubuntu 14.04
6+
dist: trusty
7+
sudo: required
8+
dotnet: 1.0.4
9+
group: edge
10+
11+
script:
12+
- ./build.sh

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,12 @@ To achieve output identical to version 2 of this sink, specify a formatter and o
143143

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

146+
### Detailed build status
147+
148+
Branch | AppVeyor | Travis
149+
------------- | ------------- |-------------
150+
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)
151+
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)
152+
153+
146154
_Copyright © 2017 Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html)._

build.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
set -e
4+
dotnet --info
5+
dotnet restore
6+
7+
for path in src/**/*.csproj; do
8+
dotnet build -f netstandard1.3 -c Release ${path}
9+
dotnet build -f netcoreapp1.1 -c Release ${path}
10+
done
11+
12+
for path in test/*.Tests/*.csproj; do
13+
dotnet test -f netcoreapp1.1 -c Release ${path}
14+
done
15+
16+
for path in sample/ConsoleDemo/*.csproj; do
17+
dotnet build -f netcoreapp1.1 -c Release ${path}
18+
dotnet run -f netcoreapp1.1 --project ${path}
19+
done

src/Serilog.Sinks.Console/Serilog.Sinks.Console.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>A Serilog sink that writes log events to the console/terminal.</Description>
5-
<VersionPrefix>3.0.0</VersionPrefix>
5+
<VersionPrefix>3.0.1</VersionPrefix>
66
<Authors>Serilog Contributors</Authors>
77
<TargetFrameworks>net45;netstandard1.3;netcoreapp1.1</TargetFrameworks>
88
<AssemblyName>Serilog.Sinks.Console</AssemblyName>

src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedDisplayValueFormatter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ value is decimal || value is byte || value is sbyte || value is short ||
184184

185185
if (value is char ch)
186186
{
187-
using (ApplyStyle(output, ConsoleThemeStyle.String, ref count))
187+
using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count))
188188
{
189189
output.Write('\'');
190190
output.Write(ch);
@@ -194,7 +194,7 @@ value is decimal || value is byte || value is sbyte || value is short ||
194194
}
195195
}
196196

197-
using (ApplyStyle(output, ConsoleThemeStyle.Object, ref count))
197+
using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count))
198198
scalar.Render(output, format, _formatProvider);
199199

200200
return count;

src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedJsonValueFormatter.cs

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ protected override int VisitScalarValue(ThemedValueFormatterState state, ScalarV
4242
{
4343
if (scalar == null)
4444
throw new ArgumentNullException(nameof(scalar));
45-
return FormatLiteralValue(scalar, state.Output, state.Format);
45+
46+
// At the top level, for scalar values, use "display" rendering.
47+
if (state.IsTopLevel)
48+
return _displayFormatter.FormatLiteralValue(scalar, state.Output, state.Format);
49+
50+
return FormatLiteralValue(scalar, state.Output);
4651
}
4752

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

6570
delim = ", ";
66-
Visit(state, sequence.Elements[index]);
71+
Visit(state.Nest(), sequence.Elements[index]);
6772
}
6873

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

99-
count += Visit(state, property.Value);
104+
count += Visit(state.Nest(), property.Value);
100105
}
106+
101107
if (structure.TypeTag != null)
102108
{
103109
using (ApplyStyle(state.Output, ConsoleThemeStyle.TertiaryText, ref count))
@@ -121,7 +127,7 @@ protected override int VisitStructureValue(ThemedValueFormatterState state, Stru
121127

122128
protected override int VisitDictionaryValue(ThemedValueFormatterState state, DictionaryValue dictionary)
123129
{
124-
int count = 0;
130+
var count = 0;
125131

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

136142
delim = ", ";
137143

138-
using (ApplyStyle(state.Output, ConsoleThemeStyle.String, ref count))
144+
var style = element.Key.Value == null
145+
? ConsoleThemeStyle.Null
146+
: element.Key.Value is string
147+
? ConsoleThemeStyle.String
148+
: ConsoleThemeStyle.Scalar;
149+
150+
using (ApplyStyle(state.Output, style, ref count))
139151
JsonValueFormatter.WriteQuotedJsonString((element.Key.Value ?? "null").ToString(), state.Output);
140152

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

144-
count += Visit(state, element.Value);
156+
count += Visit(state.Nest(), element.Value);
145157
}
146158

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

153-
int FormatLiteralValue(ScalarValue scalar, TextWriter output, string format)
165+
int FormatLiteralValue(ScalarValue scalar, TextWriter output)
154166
{
155-
// At the top level, if a format string is specified, non-JSON rendering is used.
156-
if (format != null)
157-
return _displayFormatter.FormatLiteralValue(scalar, output, format);
158-
159167
var value = scalar.Value;
160168
var count = 0;
161169

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

176184
if (value is ValueType)
177185
{
178-
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)
186+
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)
179187
{
180188
using (ApplyStyle(output, ConsoleThemeStyle.Number, ref count))
181189
output.Write(((IFormattable)value).ToString(null, CultureInfo.InvariantCulture));
@@ -184,23 +192,25 @@ int FormatLiteralValue(ScalarValue scalar, TextWriter output, string format)
184192

185193
if (value is double d)
186194
{
187-
if (double.IsNaN(d) || double.IsInfinity(d))
188-
using (ApplyStyle(output, ConsoleThemeStyle.String, ref count))
195+
using (ApplyStyle(output, ConsoleThemeStyle.Number, ref count))
196+
{
197+
if (double.IsNaN(d) || double.IsInfinity(d))
189198
JsonValueFormatter.WriteQuotedJsonString(d.ToString(CultureInfo.InvariantCulture), output);
190-
else
191-
using (ApplyStyle(output, ConsoleThemeStyle.Number, ref count))
199+
else
192200
output.Write(d.ToString("R", CultureInfo.InvariantCulture));
201+
}
193202
return count;
194203
}
195204

196205
if (value is float f)
197206
{
198-
if (double.IsNaN(f) || double.IsInfinity(f))
199-
using (ApplyStyle(output, ConsoleThemeStyle.String, ref count))
207+
using (ApplyStyle(output, ConsoleThemeStyle.Number, ref count))
208+
{
209+
if (double.IsNaN(f) || double.IsInfinity(f))
200210
JsonValueFormatter.WriteQuotedJsonString(f.ToString(CultureInfo.InvariantCulture), output);
201-
else
202-
using (ApplyStyle(output, ConsoleThemeStyle.Number, ref count))
211+
else
203212
output.Write(f.ToString("R", CultureInfo.InvariantCulture));
213+
}
204214
return count;
205215
}
206216

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

215225
if (value is char ch)
216226
{
217-
using (ApplyStyle(output, ConsoleThemeStyle.String, ref count))
227+
using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count))
218228
JsonValueFormatter.WriteQuotedJsonString(ch.ToString(), output);
219229
return count;
220230
}
221231

222232
if (value is DateTime || value is DateTimeOffset)
223233
{
224-
using (ApplyStyle(output, ConsoleThemeStyle.String, ref count))
234+
using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count))
225235
{
226236
output.Write('"');
227237
output.Write(((IFormattable)value).ToString("O", CultureInfo.InvariantCulture));
@@ -231,7 +241,7 @@ int FormatLiteralValue(ScalarValue scalar, TextWriter output, string format)
231241
}
232242
}
233243

234-
using (ApplyStyle(output, ConsoleThemeStyle.String, ref count))
244+
using (ApplyStyle(output, ConsoleThemeStyle.Scalar, ref count))
235245
JsonValueFormatter.WriteQuotedJsonString(value.ToString(), output);
236246

237247
return count;

src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedValueFormatter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ protected StyleReset ApplyStyle(TextWriter output, ConsoleThemeStyle style, ref
3434
return _theme.Apply(output, style, ref invisibleCharacterCount);
3535
}
3636

37-
public int Format(LogEventPropertyValue value, TextWriter output, string format)
37+
public int Format(LogEventPropertyValue value, TextWriter output, string format, bool literalTopLevel = false)
3838
{
39-
return Visit(new ThemedValueFormatterState { Output = output, Format = format }, value);
39+
return Visit(new ThemedValueFormatterState { Output = output, Format = format, IsTopLevel = literalTopLevel }, value);
4040
}
4141

4242
public abstract ThemedValueFormatter SwitchTheme(ConsoleTheme theme);

src/Serilog.Sinks.Console/Sinks/SystemConsole/Formatting/ThemedValueFormatterState.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct ThemedValueFormatterState
2020
{
2121
public TextWriter Output;
2222
public string Format;
23+
public bool IsTopLevel;
2324

2425
public ThemedValueFormatterState Nest()
2526
{

src/Serilog.Sinks.Console/Sinks/SystemConsole/Rendering/ThemedMessageTemplateRenderer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,15 @@ int RenderAlignedPropertyTokenUnbuffered(PropertyToken pt, TextWriter output, Lo
126126

127127
int RenderValue(ConsoleTheme theme, ThemedValueFormatter valueFormatter, LogEventPropertyValue propertyValue, TextWriter output, string format)
128128
{
129-
if (_isLiteral && propertyValue is ScalarValue sv && (sv.Value is string str || sv.Value is char ch))
129+
if (_isLiteral && propertyValue is ScalarValue sv && sv.Value is string)
130130
{
131131
var count = 0;
132132
using (theme.Apply(output, ConsoleThemeStyle.String, ref count))
133133
output.Write(sv.Value);
134134
return count;
135135
}
136136

137-
return valueFormatter.Format(propertyValue, output, format);
137+
return valueFormatter.Format(propertyValue, output, format, _isLiteral);
138138
}
139139
}
140140
}

src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ static class AnsiConsoleThemes
2121
public static AnsiConsoleTheme Literate { get; } = new AnsiConsoleTheme(
2222
new Dictionary<ConsoleThemeStyle, string>
2323
{
24-
[ConsoleThemeStyle.Text] = "\x1b[37;1m",
25-
[ConsoleThemeStyle.SecondaryText] = "\x1b[37m",
26-
[ConsoleThemeStyle.TertiaryText] = "\x1b[30;1m",
27-
[ConsoleThemeStyle.Invalid] = "\x1b[33;1m",
28-
[ConsoleThemeStyle.Null] = "\x1b[34;1m",
29-
[ConsoleThemeStyle.Name] = "\x1b[37m",
30-
[ConsoleThemeStyle.String] = "\x1b[36;1m",
31-
[ConsoleThemeStyle.Number] = "\x1b[35;1m",
32-
[ConsoleThemeStyle.Boolean] = "\x1b[34;1m",
33-
[ConsoleThemeStyle.Object] = "\x1b[32;1m",
34-
[ConsoleThemeStyle.LevelVerbose] = "\x1b[37m",
35-
[ConsoleThemeStyle.LevelDebug] = "\x1b[37m",
36-
[ConsoleThemeStyle.LevelInformation] = "\x1b[37;1m",
37-
[ConsoleThemeStyle.LevelWarning] = "\x1b[33;1m",
38-
[ConsoleThemeStyle.LevelError] = "\x1b[37;1m\x1b[41;1m",
39-
[ConsoleThemeStyle.LevelFatal] = "\x1b[37;1m\x1b[41;1m"
24+
[ConsoleThemeStyle.Text] = "\x1b[38;5;0015m",
25+
[ConsoleThemeStyle.SecondaryText] = "\x1b[38;5;0007m",
26+
[ConsoleThemeStyle.TertiaryText] = "\x1b[38;5;0008m",
27+
[ConsoleThemeStyle.Invalid] = "\x1b[38;5;0011m",
28+
[ConsoleThemeStyle.Null] = "\x1b[38;5;0027m",
29+
[ConsoleThemeStyle.Name] = "\x1b[38;5;0007m",
30+
[ConsoleThemeStyle.String] = "\x1b[38;5;0045m",
31+
[ConsoleThemeStyle.Number] = "\x1b[38;5;0200m",
32+
[ConsoleThemeStyle.Boolean] = "\x1b[38;5;0027m",
33+
[ConsoleThemeStyle.Scalar] = "\x1b[38;5;0085m",
34+
[ConsoleThemeStyle.LevelVerbose] = "\x1b[38;5;0007m",
35+
[ConsoleThemeStyle.LevelDebug] = "\x1b[38;5;0007m",
36+
[ConsoleThemeStyle.LevelInformation] = "\x1b[38;5;0015m",
37+
[ConsoleThemeStyle.LevelWarning] = "\x1b[38;5;0011m",
38+
[ConsoleThemeStyle.LevelError] = "\x1b[38;5;0015m\x1b[48;5;0196m",
39+
[ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0015m\x1b[48;5;0196m"
4040
});
4141

4242
public static AnsiConsoleTheme Grayscale { get; } = new AnsiConsoleTheme(
@@ -51,7 +51,7 @@ static class AnsiConsoleThemes
5151
[ConsoleThemeStyle.String] = "\x1b[1m\x1b[37;1m",
5252
[ConsoleThemeStyle.Number] = "\x1b[1m\x1b[37;1m",
5353
[ConsoleThemeStyle.Boolean] = "\x1b[1m\x1b[37;1m",
54-
[ConsoleThemeStyle.Object] = "\x1b[1m\x1b[37;1m",
54+
[ConsoleThemeStyle.Scalar] = "\x1b[1m\x1b[37;1m",
5555
[ConsoleThemeStyle.LevelVerbose] = "\x1b[30;1m",
5656
[ConsoleThemeStyle.LevelDebug] = "\x1b[30;1m",
5757
[ConsoleThemeStyle.LevelInformation] ="\x1b[37;1m",
@@ -72,7 +72,7 @@ static class AnsiConsoleThemes
7272
[ConsoleThemeStyle.String] = "\x1b[38;5;0216m",
7373
[ConsoleThemeStyle.Number] = "\x1b[38;5;151m",
7474
[ConsoleThemeStyle.Boolean] = "\x1b[38;5;0038m",
75-
[ConsoleThemeStyle.Object] = "\x1b[38;5;0079m",
75+
[ConsoleThemeStyle.Scalar] = "\x1b[38;5;0079m",
7676
[ConsoleThemeStyle.LevelVerbose] = "\x1b[37m",
7777
[ConsoleThemeStyle.LevelDebug] = "\x1b[37m",
7878
[ConsoleThemeStyle.LevelInformation] = "\x1b[37;1m",

0 commit comments

Comments
 (0)