Skip to content

Commit

Permalink
Merge pull request #141 from TheTribe/release/3.10
Browse files Browse the repository at this point in the history
Release/3.10
  • Loading branch information
jbatte47 committed Dec 12, 2013
2 parents ba9a87e + 7b60dca commit 02fc7ce
Show file tree
Hide file tree
Showing 25 changed files with 298 additions and 86 deletions.
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

The following log details the outward-facing changes made to code-patterns since its first migration to GitHub.

## 3.10 ##

- Provided greater flexibility in `LoggingInterceptor` by making the argument and return value formatter injectable ([issue 139](https://github.com/TheTribe/code-patterns/issues/139))
- introduced new interface: `ILogValueFormatter`
- new base type for value formatters: `LogValueFormatterBase`
- new formatter type: `JsonLogValueFormatter`
- updated tests and modules to include the new types

## 3.10-beta.5 ##

- Dropped reference to Reactive Extensions ([issue 123](https://github.com/TheTribe/code-patterns/issues/123))
Expand Down
1 change: 1 addition & 0 deletions src/.nuget/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NuGetPowerTools" version="0.29" />
<package id="Pickles" version="0.13.0.0" />
</packages>
1 change: 1 addition & 0 deletions src/Patterns.Autofac/Logging/LoggingModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ protected override void Load(ContainerBuilder builder)
throw ErrorBuilder.BuildContainerException(registrationError, ConfigurationResources.MissingConfigSourceErrorHint);
}
}).As<ILoggingConfig>();
builder.RegisterInstance(new JsonLogValueFormatter()).As<ILogValueFormatter>();
builder.RegisterType<LoggingInterceptor>();
}

Expand Down
6 changes: 0 additions & 6 deletions src/Patterns.Autofac/Patterns.Autofac.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,6 @@
<LastGenOutput>ContainerResources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Content Include="..\packages\AutoMapper.3.1.0\lib\net40\AutoMapper.Net4.dll">
<Link>AutoMapper.Net4.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
2 changes: 1 addition & 1 deletion src/Patterns.Autofac/Patterns.Autofac.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<version>$version$</version>
<authors>$author$</authors>
<owners>$author$</owners>
<projectUrl>https://github.com/jbatte47/code-patterns</projectUrl>
<projectUrl>https://github.com/TheTribe/code-patterns</projectUrl>
<dependencies>
<dependency id="Patterns" version="$version$" />
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion src/Patterns.Autofac/Patterns.Autofac.tt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ output extension=".nuspec" #><?xml version="1.0"?>
<version>$version$</version>
<authors>$author$</authors>
<owners>$author$</owners>
<projectUrl>https://github.com/jbatte47/code-patterns</projectUrl>
<projectUrl>https://github.com/TheTribe/code-patterns</projectUrl>
<dependencies>
<dependency id="Patterns" version="$version$" />
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<version>$version$</version>
<authors>$author$</authors>
<owners>$author$</owners>
<projectUrl>https://github.com/jbatte47/code-patterns</projectUrl>
<projectUrl>https://github.com/TheTribe/code-patterns</projectUrl>
<dependencies>
<dependency id="Patterns" version="$version$" />
<dependency id="Patterns.Autofac" version="$version$" />
Expand Down
2 changes: 1 addition & 1 deletion src/Patterns.Testing.Autofac/Patterns.Testing.Autofac.tt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ output extension=".nuspec" #><?xml version="1.0"?>
<version>$version$</version>
<authors>$author$</authors>
<owners>$author$</owners>
<projectUrl>https://github.com/jbatte47/code-patterns</projectUrl>
<projectUrl>https://github.com/TheTribe/code-patterns</projectUrl>
<dependencies>
<dependency id="Patterns" version="$version$" />
<dependency id="Patterns.Autofac" version="$version$" />
Expand Down
6 changes: 0 additions & 6 deletions src/Patterns.Testing/Patterns.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<ItemGroup>
<Content Include="..\packages\AutoMapper.3.1.0\lib\net40\AutoMapper.Net4.dll">
<Link>AutoMapper.Net4.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
2 changes: 1 addition & 1 deletion src/Patterns.Testing/Patterns.Testing.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<version>$version$</version>
<authors>$author$</authors>
<owners>$author$</owners>
<projectUrl>https://github.com/jbatte47/code-patterns</projectUrl>
<projectUrl>https://github.com/TheTribe/code-patterns</projectUrl>
<dependencies>
<dependency id="Patterns" version="$version$" />
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion src/Patterns.Testing/Patterns.Testing.tt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ output extension=".nuspec" #><?xml version="1.0"?>
<version>$version$</version>
<authors>$author$</authors>
<owners>$author$</owners>
<projectUrl>https://github.com/jbatte47/code-patterns</projectUrl>
<projectUrl>https://github.com/TheTribe/code-patterns</projectUrl>
<dependencies>
<dependency id="Patterns" version="$version$" />
</dependencies>
Expand Down
45 changes: 45 additions & 0 deletions src/Patterns/Logging/ILogValueFormatter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#region FreeBSD

// Copyright (c) 2013, The Tribe
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that
// the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this list of conditions and the
// following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
// following disclaimer in the documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#endregion

namespace Patterns.Logging
{
/// <summary>
/// Defines a formatter for log values.
/// </summary>
public interface ILogValueFormatter
{
/// <summary>
/// Formats the specified value.
/// </summary>
/// <param name="value">The value.</param>
string Format(object value);

/// <summary>
/// Formats the specified values.
/// </summary>
/// <param name="values">The values.</param>
string Format(object[] values);
}
}
78 changes: 78 additions & 0 deletions src/Patterns/Logging/JsonLogValueFormatter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#region FreeBSD

// Copyright (c) 2013, The Tribe
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that
// the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this list of conditions and the
// following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
// following disclaimer in the documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#endregion

using System;
using System.Web.Script.Serialization;

namespace Patterns.Logging
{
/// <summary>
/// Provides a JSON formatter for log values.
/// </summary>
public class JsonLogValueFormatter : LogValueFormatterBase
{
/// <summary>
/// The default recursion limit.
/// </summary>
public const int DefaultRecursionLimit = 50;

private readonly JavaScriptSerializer _jsonSerializer;

/// <summary>
/// Initializes a new instance of the <see cref="JsonLogValueFormatter" /> class.
/// </summary>
/// <param name="maxLength">The maximum length.</param>
/// <param name="recursionLimit">The recursion limit.</param>
public JsonLogValueFormatter(int maxLength = int.MaxValue, int recursionLimit = DefaultRecursionLimit)
{
_jsonSerializer = new JavaScriptSerializer
{
MaxJsonLength = maxLength,
RecursionLimit = recursionLimit
};
}

/// <summary>
/// Formats the specified value.
/// </summary>
/// <param name="value">The value.</param>
public override string Format(object value)
{
return base.Format(value) ?? SerializeValue(value);
}

private string SerializeValue(object value)
{
try
{
return _jsonSerializer.Serialize(value);
}
catch (InvalidOperationException)
{
return string.Format(SpecialValueFormat, LoggingResources.ILogValueFormatter_ValueTooLarge);
}
}
}
}
97 changes: 97 additions & 0 deletions src/Patterns/Logging/LogValueFormatterBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#region FreeBSD

// Copyright (c) 2013, The Tribe
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that
// the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this list of conditions and the
// following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
// following disclaimer in the documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#endregion

using System;
using System.Linq;

using Patterns.Collections.Strategies;

namespace Patterns.Logging
{
/// <summary>
/// Provides a base class for log value formatters.
/// </summary>
public abstract class LogValueFormatterBase : ILogValueFormatter
{
/// <summary>
/// The special value format.
/// </summary>
protected const string SpecialValueFormat = "[{0}]";

/// <summary>
/// The argument list format.
/// </summary>
protected const string ArgumentListFormat = "({0})";

/// <summary>
/// The argument list separator.
/// </summary>
protected const string ArgumentListSeparator = ",";

/// <summary>
/// The string display format.
/// </summary>
protected const string StringDisplayFormat = @"""{0}""";

private static readonly FuncStrategies<Type, object, object> _displayStrategies
= new FuncStrategies<Type, object, object>
{
{typeof (string), value => string.Format(StringDisplayFormat, value)}
};

/// <summary>
/// Formats the specified value.
/// </summary>
/// <param name="value">The value.</param>
public virtual string Format(object value)
{
object valueForDisplay = ConvertValueForDisplay(value);
return valueForDisplay != null ? valueForDisplay.ToString() : null;
}

/// <summary>
/// Formats the specified values.
/// </summary>
/// <param name="values">The values.</param>
public virtual string Format(object[] values)
{
string[] convertedValues = values.Select(Format).ToArray();
return string.Format(ArgumentListFormat, string.Join(ArgumentListSeparator, convertedValues));
}

/// <summary>
/// Converts the value for display.
/// </summary>
/// <param name="value">The value.</param>
protected virtual object ConvertValueForDisplay(object value)
{
if (value == null) return string.Format(SpecialValueFormat, LoggingResources.ILogValueFormatter_NullValue);

Type valueType = value.GetType();

return _displayStrategies.Execute(valueType, value);
}
}
}
Loading

0 comments on commit 02fc7ce

Please sign in to comment.