Skip to content

Commit

Permalink
Merge branch 'master' into typeinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
sungam3r committed Jan 22, 2024
2 parents 5ba2dbc + aae13dc commit 366f716
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 32 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ jobs:
run: dotnet build --no-restore -c Debug
- name: Test solution [Debug]
working-directory: src
run: dotnet test --no-restore -p:CollectCoverage=true
run: dotnet test --no-restore -p:CollectCoverage=true -p:CoverletOutputFormat=opencover -p:CoverletOutput=../.coverage/
- name: Upload coverage to codecov
if: ${{ startsWith(matrix.os, 'ubuntu') }}
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
files: .coverage/Destructurama.ByIgnoring.Tests/coverage.net8.opencover.xml
files: src/.coverage/*.opencover.xml

buildcheck:
needs:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![License](https://img.shields.io/github/license/destructurama/attributed)

[![codecov](https://codecov.io/gh/destructurama/attributed/branch/master/graph/badge.svg?token=0ZRHIUEQM4)](https://codecov.io/gh/destructurama/attributed)
[![codecov](https://codecov.io/gh/destructurama/attributed/graph/badge.svg?token=Ma2sUoqqb1)](https://codecov.io/gh/destructurama/attributed)
[![Nuget](https://img.shields.io/nuget/dt/Destructurama.Attributed)](https://www.nuget.org/packages/Destructurama.Attributed)
[![Nuget](https://img.shields.io/nuget/v/Destructurama.Attributed)](https://www.nuget.org/packages/Destructurama.Attributed)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="PublicApiGenerator" Version="11.1.0" />
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<!--<PackageReference Include="MarkdownSnippets.MsBuild" Version="24.5.1" PrivateAssets="all" />-->
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private CacheEntry CreateCacheEntry(Type type)
{
var classDestructurer = type.GetCustomAttribute<ITypeDestructuringAttribute>();
if (classDestructurer != null)
return new((o, f) => classDestructurer.CreateLogEventPropertyValue(o, f));
return new(classDestructurer.CreateLogEventPropertyValue);

var properties = type.GetPropertiesRecursive().ToList();
if (!_options.IgnoreNullProperties
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Serilog.Events;

namespace Destructurama.Attributed;

/// <summary>
Expand All @@ -6,9 +8,9 @@ namespace Destructurama.Attributed;
public class AttributedDestructuringPolicyOptions
{
/// <summary>
/// By setting IgnoreNullProperties to true no need to set [NotLoggedIfNull] for every logged property.
/// Custom types implementing IEnumerable, will be destructed as StructureValue and affected by IgnoreNullProperties
/// only in case at least one property (or the type itself) has Destructurama attribute applied.
/// By setting this property to <see langword="true"/> no need to set <see cref="NotLoggedIfNullAttribute"/>
/// for every logged property. Custom types implementing IEnumerable, will be destructed as <see cref="StructureValue"/>
/// and affected by this property only in case at least one property (or the type itself) has Destructurama attribute applied.
/// </summary>
public bool IgnoreNullProperties { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
namespace Destructurama.Attributed;

/// <summary>
/// Base interfaces for all <see cref="Attribute"/>s that override how a property is destructured.
/// Base interface for all Destructurama attributes that override how a property is destructured.
/// </summary>
public interface IPropertyDestructuringAttribute
{
/// <summary>
/// Attempt to create a replacement <see cref="LogEventProperty"/> for a property.
/// </summary>
/// <param name="name">The current property name.</param>
/// <param name="value">The current property value</param>
/// <param name="value">The current property value.</param>
/// <param name="propertyValueFactory">The current <see cref="ILogEventPropertyValueFactory"/>.</param>
/// <param name="property">The <see cref="LogEventProperty"/> to use as a replacement.</param>
/// <returns><code>true</code>If a replacement <see cref="LogEventProperty"/> has been derived.</returns>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2020 Destructurama Contributors, Serilog Contributors
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -15,16 +15,16 @@
namespace Destructurama.Attributed;

/// <summary>
/// Base interfaces for all <see cref="Attribute"/>s that determine should a property be ignored.
/// Base interface for all Destructurama attributes that determine should a property be ignored.
/// </summary>
public interface IPropertyOptionalIgnoreAttribute
{
/// <summary>
/// Determine should a property be ignored
/// </summary>
/// <param name="name">The current property name</param>
/// <param name="value">The current property value</param>
/// <param name="type">The current property type</param>
/// <param name="name">The current property name.</param>
/// <param name="value">The current property value.</param>
/// <param name="type">The current property type.</param>
/// <returns></returns>
bool ShouldPropertyBeIgnored(string name, object? value, Type type);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace Destructurama.Attributed;

/// <summary>
/// Base interfaces for all <see cref="Attribute"/>s that override how a property type type is destructured.
/// Base interface for all Destructurama attributes that override how a property type is destructured.
/// </summary>
public interface ITypeDestructuringAttribute
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ public class LogAsScalarAttribute : Attribute, ITypeDestructuringAttribute, IPro
/// <summary>
/// Construct a <see cref="LogAsScalarAttribute"/>.
/// </summary>
/// <param name="isMutable">Whether the scalar value should be converted into a string before
/// being passed down the (asynchronous) logging pipeline. For mutable types, specify
/// <code>true</code>, otherwise leave as false.</param>
/// <param name="isMutable">
/// Whether the scalar value should be converted into a string before
/// being passed down the (asynchronous) logging pipeline. For mutable
/// types, specify <code>true</code>, otherwise leave as false.
/// </param>
public LogAsScalarAttribute(bool isMutable = false)
{
_isMutable = isMutable;
Expand Down
3 changes: 3 additions & 0 deletions src/Destructurama.Attributed/Attributed/LogMaskedAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ public class LogMaskedAttribute : Attribute, IPropertyDestructuringAttribute
/// If set, the property value will be set to this text.
/// </summary>
public string Text { get; set; } = DEFAULT_MASK;

/// <summary>
/// Shows the first x characters in the property value.
/// </summary>
public int ShowFirst { get; set; }

/// <summary>
/// Shows the last x characters in the property value.
/// </summary>
public int ShowLast { get; set; }

/// <summary>
/// If set, it will swap out each character with the default value. Note that this
/// property will be ignored if <see cref="Text"/> has been set to custom value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
namespace Destructurama.Attributed;

/// <summary>
/// Apply to a property to use a replace the current value.
/// Apply to a property to replace the current value.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public class LogReplacedAttribute : Attribute, IPropertyDestructuringAttribute
Expand All @@ -29,7 +29,7 @@ public class LogReplacedAttribute : Attribute, IPropertyDestructuringAttribute
private readonly string _replacement;

/// <summary>
/// The RegexOptions that will be applied. Defaults to <see cref="RegexOptions.None"/>
/// The options that will be applied. Defaults to <see cref="RegexOptions.None"/>
/// </summary>
public RegexOptions Options { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2020 Destructurama Contributors, Serilog Contributors
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -15,7 +15,7 @@
namespace Destructurama.Attributed;

/// <summary>
/// Specified that a property with null value should not be included when destructuring an object for logging.
/// Specified that a property with <see langword="null"/> value should not be included when destructuring an object for logging.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public class NotLoggedIfNullAttribute : Attribute, IPropertyOptionalIgnoreAttribute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public static class LoggerConfigurationAppSettingsExtensions
public static LoggerConfiguration UsingAttributes(this LoggerDestructuringConfiguration configuration) =>
configuration.With<AttributedDestructuringPolicy>();


/// <summary>
/// Adds a custom <see cref="IDestructuringPolicy"/> to enable manipulation of how objects
/// are logged to Serilog using attributes.
/// </summary>
/// <param name="configuration">The logger configuration to apply configuration to.</param>
/// <param name="configure">Configure Destructurama options</param>
/// <param name="configure">Delegate to configure Destructurama options.</param>
/// <returns>An object allowing configuration to continue.</returns>
public static LoggerConfiguration UsingAttributes(this LoggerDestructuringConfiguration configuration,
Action<AttributedDestructuringPolicyOptions> configure)
public static LoggerConfiguration UsingAttributes(this LoggerDestructuringConfiguration configuration, Action<AttributedDestructuringPolicyOptions> configure)
{
var policy = new AttributedDestructuringPolicy(configure);
return configuration.With(policy);
Expand Down
4 changes: 2 additions & 2 deletions src/Destructurama.Attributed/Util/CacheEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ internal struct CacheEntry
public CacheEntry(Func<object, ILogEventPropertyValueFactory, LogEventPropertyValue> destructureFunc)
{
CanDestructure = true;
DestructureFunc = destructureFunc ?? throw new ArgumentNullException(nameof(destructureFunc));
DestructureFunc = destructureFunc;
}

private CacheEntry(bool canDestructure, Func<object, ILogEventPropertyValueFactory, LogEventPropertyValue?> destructureFunc)
{
CanDestructure = canDestructure;
DestructureFunc = destructureFunc ?? throw new ArgumentNullException(nameof(destructureFunc));
DestructureFunc = destructureFunc;
}

public bool CanDestructure { get; }
Expand Down

0 comments on commit 366f716

Please sign in to comment.