Skip to content

Commit

Permalink
Merge pull request #55 from Abc-Arbitrage/date-time-only
Browse files Browse the repository at this point in the history
Add support for `DateOnly`/`TimeOnly`
  • Loading branch information
ltrzesniewski authored Jun 1, 2022
2 parents 5434daf + e83b697 commit 8f0cf3a
Show file tree
Hide file tree
Showing 12 changed files with 1,467 additions and 23 deletions.
2 changes: 2 additions & 0 deletions src/ZeroLog.Impl.Base/ArgumentType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ internal enum ArgumentType : byte
Guid,
DateTime,
TimeSpan,
DateOnly,
TimeOnly,
StringSpan,
Utf8StringSpan,
Enum,
Expand Down
408 changes: 408 additions & 0 deletions src/ZeroLog.Impl.Base/Log.Generated.cs

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions src/ZeroLog.Impl.Base/Log.Generated.tt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ partial class Log
<#
foreach (var type in _valueTypes)
{
#>
<#
if (type.isNetCoreOnly)
{
#>
#if NETCOREAPP

<#
}
#>
/// <summary>
/// Appends a value of type <c><#= type.name #></c> to the handler.
Expand Down Expand Up @@ -173,6 +182,14 @@ partial class Log
public void AppendFormatted(<#= type.name #>? value, string format)
=> Message.InternalAppendValueType(value, format, ArgumentType.<#= type.argType #>);

<#
}

if (type.isNetCoreOnly)
{
#>
#endif

<#
}
}
Expand Down
206 changes: 205 additions & 1 deletion src/ZeroLog.Impl.Base/LogMessage.Generated.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// </auto-generated>
Expand Down Expand Up @@ -1122,6 +1122,142 @@ public LogMessage AppendKeyValue(string key, TimeSpan? value)
return this;
}

#if NETCOREAPP

/// <summary>
/// Appends a value of type <c>DateOnly</c> to the message.
/// </summary>
/// <param name="value">The value to append.</param>
public LogMessage Append(DateOnly value)
{
InternalAppendValueType(value, ArgumentType.DateOnly);
return this;
}

/// <summary>
/// Appends a value of type <c>DateOnly?</c> to the message.
/// </summary>
/// <param name="value">The value to append.</param>
public LogMessage Append(DateOnly? value)
{
InternalAppendValueType(value, ArgumentType.DateOnly);
return this;
}

/// <summary>
/// Appends a value of type <c>DateOnly</c> to the message.
/// </summary>
/// <param name="value">The value to append.</param>
/// <param name="format">The format string.</param>
public LogMessage Append(DateOnly value, string format)
{
InternalAppendValueType(value, format, ArgumentType.DateOnly);
return this;
}

/// <summary>
/// Appends a value of type <c>DateOnly?</c> to the message.
/// </summary>
/// <param name="value">The value to append.</param>
/// <param name="format">The format string.</param>
public LogMessage Append(DateOnly? value, string format)
{
InternalAppendValueType(value, format, ArgumentType.DateOnly);
return this;
}

/// <summary>
/// Appends a value of type <c>DateOnly</c> to the message metadata.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
public LogMessage AppendKeyValue(string key, DateOnly value)
{
InternalAppendKeyValue(key, value, ArgumentType.DateOnly);
return this;
}

/// <summary>
/// Appends a value of type <c>DateOnly?</c> to the message metadata.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
public LogMessage AppendKeyValue(string key, DateOnly? value)
{
InternalAppendKeyValue(key, value, ArgumentType.DateOnly);
return this;
}

#endif

#if NETCOREAPP

/// <summary>
/// Appends a value of type <c>TimeOnly</c> to the message.
/// </summary>
/// <param name="value">The value to append.</param>
public LogMessage Append(TimeOnly value)
{
InternalAppendValueType(value, ArgumentType.TimeOnly);
return this;
}

/// <summary>
/// Appends a value of type <c>TimeOnly?</c> to the message.
/// </summary>
/// <param name="value">The value to append.</param>
public LogMessage Append(TimeOnly? value)
{
InternalAppendValueType(value, ArgumentType.TimeOnly);
return this;
}

/// <summary>
/// Appends a value of type <c>TimeOnly</c> to the message.
/// </summary>
/// <param name="value">The value to append.</param>
/// <param name="format">The format string.</param>
public LogMessage Append(TimeOnly value, string format)
{
InternalAppendValueType(value, format, ArgumentType.TimeOnly);
return this;
}

/// <summary>
/// Appends a value of type <c>TimeOnly?</c> to the message.
/// </summary>
/// <param name="value">The value to append.</param>
/// <param name="format">The format string.</param>
public LogMessage Append(TimeOnly? value, string format)
{
InternalAppendValueType(value, format, ArgumentType.TimeOnly);
return this;
}

/// <summary>
/// Appends a value of type <c>TimeOnly</c> to the message metadata.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
public LogMessage AppendKeyValue(string key, TimeOnly value)
{
InternalAppendKeyValue(key, value, ArgumentType.TimeOnly);
return this;
}

/// <summary>
/// Appends a value of type <c>TimeOnly?</c> to the message metadata.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
public LogMessage AppendKeyValue(string key, TimeOnly? value)
{
InternalAppendKeyValue(key, value, ArgumentType.TimeOnly);
return this;
}

#endif

/// <summary>
/// Appends an interpolated string to the message.
/// </summary>
Expand Down Expand Up @@ -1639,5 +1775,73 @@ public void AppendFormatted(TimeSpan value, string format)
public void AppendFormatted(TimeSpan? value, string format)
=> _message.InternalAppendValueType(value, format, ArgumentType.TimeSpan);

#if NETCOREAPP

/// <summary>
/// Appends a value of type <c>DateOnly</c> to the handler.
/// </summary>
/// <param name="value">The value to append.</param>
public void AppendFormatted(DateOnly value)
=> _message.InternalAppendValueType(value, ArgumentType.DateOnly);

/// <summary>
/// Appends a value of type <c>DateOnly?</c> to the handler.
/// </summary>
/// <param name="value">The value to append.</param>
public void AppendFormatted(DateOnly? value)
=> _message.InternalAppendValueType(value, ArgumentType.DateOnly);

/// <summary>
/// Appends a value of type <c>DateOnly</c> to the handler.
/// </summary>
/// <param name="value">The value to append.</param>
/// <param name="format">The format string.</param>
public void AppendFormatted(DateOnly value, string format)
=> _message.InternalAppendValueType(value, format, ArgumentType.DateOnly);

/// <summary>
/// Appends a value of type <c>DateOnly?</c> to the handler.
/// </summary>
/// <param name="value">The value to append.</param>
/// <param name="format">The format string.</param>
public void AppendFormatted(DateOnly? value, string format)
=> _message.InternalAppendValueType(value, format, ArgumentType.DateOnly);

#endif

#if NETCOREAPP

/// <summary>
/// Appends a value of type <c>TimeOnly</c> to the handler.
/// </summary>
/// <param name="value">The value to append.</param>
public void AppendFormatted(TimeOnly value)
=> _message.InternalAppendValueType(value, ArgumentType.TimeOnly);

/// <summary>
/// Appends a value of type <c>TimeOnly?</c> to the handler.
/// </summary>
/// <param name="value">The value to append.</param>
public void AppendFormatted(TimeOnly? value)
=> _message.InternalAppendValueType(value, ArgumentType.TimeOnly);

/// <summary>
/// Appends a value of type <c>TimeOnly</c> to the handler.
/// </summary>
/// <param name="value">The value to append.</param>
/// <param name="format">The format string.</param>
public void AppendFormatted(TimeOnly value, string format)
=> _message.InternalAppendValueType(value, format, ArgumentType.TimeOnly);

/// <summary>
/// Appends a value of type <c>TimeOnly?</c> to the handler.
/// </summary>
/// <param name="value">The value to append.</param>
/// <param name="format">The format string.</param>
public void AppendFormatted(TimeOnly? value, string format)
=> _message.InternalAppendValueType(value, format, ArgumentType.TimeOnly);

#endif

}
}
31 changes: 31 additions & 0 deletions src/ZeroLog.Impl.Base/LogMessage.Generated.tt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ partial class LogMessage
<#
foreach (var type in _valueTypes)
{
#>
<#
if (type.isNetCoreOnly)
{
#>
#if NETCOREAPP

<#
}
#>
/// <summary>
/// Appends a value of type <c><#= type.name #></c> to the message.
Expand Down Expand Up @@ -92,6 +101,13 @@ partial class LogMessage
}

<#
if (type.isNetCoreOnly)
{
#>
#endif

<#
}
}
#>
/// <summary>
Expand All @@ -106,6 +122,13 @@ partial class LogMessage
<#
foreach (var type in _valueTypes)
{
if (type.isNetCoreOnly)
{
#>
#if NETCOREAPP

<#
}
#>
/// <summary>
/// Appends a value of type <c><#= type.name #></c> to the handler.
Expand Down Expand Up @@ -141,6 +164,14 @@ partial class LogMessage
public void AppendFormatted(<#= type.name #>? value, string format)
=> _message.InternalAppendValueType(value, format, ArgumentType.<#= type.argType #>);

<#
}

if (type.isNetCoreOnly)
{
#>
#endif

<#
}
}
Expand Down
40 changes: 21 additions & 19 deletions src/ZeroLog.Impl.Base/LogMetadata.ttinclude
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
<#+
private static readonly (string name, string argType, bool isFormattable)[] _valueTypes =
private static readonly (string name, string argType, bool isFormattable, bool isNetCoreOnly)[] _valueTypes =
{
("bool", "Boolean", false),
("byte", "Byte", true),
("sbyte", "SByte", true),
("char", "Char", false),
("short", "Int16", true),
("ushort", "UInt16", true),
("int", "Int32", true),
("uint", "UInt32", true),
("long", "Int64", true),
("ulong", "UInt64", true),
("nint", "IntPtr", true),
("nuint", "UIntPtr", true),
("float", "Single", true),
("double", "Double", true),
("decimal", "Decimal", true),
("Guid", "Guid", true),
("DateTime", "DateTime", true),
("TimeSpan", "TimeSpan", true),
("bool", "Boolean", false, false),
("byte", "Byte", true, false),
("sbyte", "SByte", true, false),
("char", "Char", false, false),
("short", "Int16", true, false),
("ushort", "UInt16", true, false),
("int", "Int32", true, false),
("uint", "UInt32", true, false),
("long", "Int64", true, false),
("ulong", "UInt64", true, false),
("nint", "IntPtr", true, false),
("nuint", "UIntPtr", true, false),
("float", "Single", true, false),
("double", "Double", true, false),
("decimal", "Decimal", true, false),
("Guid", "Guid", true, false),
("DateTime", "DateTime", true, false),
("TimeSpan", "TimeSpan", true, false),
("DateOnly", "DateOnly", true, true),
("TimeOnly", "TimeOnly", true, true),
};

private static readonly string[] _logLevels =
Expand Down
Loading

0 comments on commit 8f0cf3a

Please sign in to comment.