Skip to content

Commit

Permalink
implemented all the IExecutionLogger strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Aug 25, 2015
1 parent 84fdb8d commit 55b7995
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 35 deletions.
10 changes: 10 additions & 0 deletions src/FubuMVC.Core/Diagnostics/Instrumentation/ChainExecutionLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,15 @@ public void Trace(string description, Action action)
Duration = finish - start
});
}

public void RecordHeaders(IDictionary<string, object> env)
{
throw new NotImplementedException();
}

public void RecordBody(IDictionary<string, object> env)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;

namespace FubuMVC.Core.Diagnostics.Instrumentation
{
Expand All @@ -9,5 +10,7 @@ public interface IChainExecutionLog
void LogException(Exception ex);
void AddLog(object log);
void Trace(string description, Action action);
void RecordHeaders(IDictionary<string, object> env);
void RecordBody(IDictionary<string, object> env);
}
}
40 changes: 5 additions & 35 deletions src/FubuMVC.Core/Diagnostics/Instrumentation/IExecutionLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,21 @@ namespace FubuMVC.Core.Diagnostics.Instrumentation
{
public interface IExecutionLogger
{
void Record(ChainExecutionLog log, IDictionary<string, object> http);
void Record(IChainExecutionLog log, IDictionary<string, object> http);
}


public class NulloExecutionLogger : IExecutionLogger
{
public void Record(ChainExecutionLog log, IDictionary<string, object> http)
public void Record(IChainExecutionLog log, IDictionary<string, object> http)
{
// no-op
}
}

public class VerboseExecutionLogger : IExecutionLogger
{
private readonly IExecutionLogStorage _storage;

public VerboseExecutionLogger(IExecutionLogStorage storage)
{
_storage = storage;
}

public void Record(ChainExecutionLog log, IDictionary<string, object> http)
{
throw new NotImplementedException();
}
}

public class ProductionExecutionLogger : IExecutionLogger
{
private readonly IExecutionLogStorage _storage;

public ProductionExecutionLogger(IExecutionLogStorage storage)
{
_storage = storage;
}

public void Record(ChainExecutionLog log, IDictionary<string, object> http)
{
throw new NotImplementedException();
}
}

public interface IExecutionLogStorage
{
void Store(ChainExecutionLog log);
void Store(IChainExecutionLog log);
void Start();
}

Expand Down Expand Up @@ -90,9 +60,9 @@ public void Start()
_readingTask = Task.Factory.StartNew(record);
}

void IExecutionLogStorage.Store(ChainExecutionLog log)
void IExecutionLogStorage.Store(IChainExecutionLog log)
{
Enqueue(log);
Enqueue((ChainExecutionLog) log);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Collections.Generic;

namespace FubuMVC.Core.Diagnostics.Instrumentation
{
public class ProductionExecutionLogger : IExecutionLogger
{
private readonly IExecutionLogStorage _storage;

public ProductionExecutionLogger(IExecutionLogStorage storage)
{
_storage = storage;
}

public void Record(IChainExecutionLog log, IDictionary<string, object> http)
{
log.RecordHeaders(http);
_storage.Store(log);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;

namespace FubuMVC.Core.Diagnostics.Instrumentation
{
public class VerboseExecutionLogger : IExecutionLogger
{
private readonly IExecutionLogStorage _storage;

public VerboseExecutionLogger(IExecutionLogStorage storage)
{
_storage = storage;
}

public void Record(IChainExecutionLog log, IDictionary<string, object> http)
{
log.RecordHeaders(http);
log.RecordBody(http);

_storage.Store(log);
}
}
}
2 changes: 2 additions & 0 deletions src/FubuMVC.Core/FubuMVC.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@
<Compile Include="Diagnostics\Instrumentation\IRequestLog.cs" />
<Compile Include="Diagnostics\Instrumentation\ISubject.cs" />
<Compile Include="Diagnostics\Instrumentation\PerformanceHistory.cs" />
<Compile Include="Diagnostics\Instrumentation\ProductionExecutionLogger.cs" />
<Compile Include="Diagnostics\Instrumentation\RequestStep.cs" />
<Compile Include="Diagnostics\Instrumentation\Trace.cs" />
<Compile Include="Diagnostics\Instrumentation\VerboseExecutionLogger.cs" />
<Compile Include="FubuModeExtensions.cs" />
<Compile Include="Http\Compression\ApplyCompression.cs" />
<Compile Include="Http\Hosting\IHost.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Collections.Generic;
using FubuMVC.Core.Diagnostics.Instrumentation;
using FubuMVC.Tests.TestSupport;
using NUnit.Framework;
using Rhino.Mocks;

namespace FubuMVC.Tests.Diagnostics.Instrumentation
{
[TestFixture]
public class ProductionExecutionLoggerTester : InteractionContext<ProductionExecutionLogger>
{
[Test]
public void record()
{
var log = MockFor<IChainExecutionLog>();
var env = new Dictionary<string, object>();

ClassUnderTest.Record(log, env);

log.AssertWasCalled(x => x.RecordHeaders(env));
log.AssertWasNotCalled(x => x.RecordBody(env));

MockFor<IExecutionLogStorage>().AssertWasCalled(x => x.Store(log));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Collections.Generic;
using FubuMVC.Core.Diagnostics.Instrumentation;
using FubuMVC.Tests.TestSupport;
using NUnit.Framework;
using Rhino.Mocks;

namespace FubuMVC.Tests.Diagnostics.Instrumentation
{
[TestFixture]
public class VerboseExecutionLoggerTester : InteractionContext<VerboseExecutionLogger>
{
[Test]
public void record()
{
var log = MockFor<IChainExecutionLog>();
var env = new Dictionary<string, object>();

ClassUnderTest.Record(log, env);

log.AssertWasCalled(x => x.RecordHeaders(env));
log.AssertWasCalled(x => x.RecordBody(env));

MockFor<IExecutionLogStorage>().AssertWasCalled(x => x.Store(log));
}
}
}
2 changes: 2 additions & 0 deletions src/FubuMVC.Tests/FubuMVC.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@
<Compile Include="Diagnostics\Instrumentation\BehaviorTracerTester.cs" />
<Compile Include="Diagnostics\Instrumentation\ChainExecutionLogTester.cs" />
<Compile Include="Diagnostics\Instrumentation\PerformanceHistoryTester.cs" />
<Compile Include="Diagnostics\Instrumentation\ProductionExecutionLoggerTester.cs" />
<Compile Include="Diagnostics\Instrumentation\VerboseExecutionLoggerTester.cs" />
<Compile Include="Diagnostics\InteractionContextExtensions.cs" />
<Compile Include="Diagnostics\PerfTimerSmokeTester.cs" />
<Compile Include="Diagnostics\Routes\EndpointReportTester.cs" />
Expand Down

0 comments on commit 55b7995

Please sign in to comment.