Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow to get just errors from the log

  • Loading branch information...
commit 6b22d10ea9282b46966094d900d59c7e050f08dc 1 parent 1679b6e
Ayende Rahien ayende authored
15 Raven.Database/Server/Responders/Logs.cs
View
@@ -1,4 +1,6 @@
using System;
+using System.Collections.Generic;
+using NLog;
using Raven.Database.Server.Abstractions;
using System.Linq;
using Raven.Database.Util;
@@ -20,7 +22,7 @@ public override string[] SupportedVerbs
public override void Respond(IHttpContext context)
{
- var boundedMemoryTarget = NLog.LogManager.Configuration.AllTargets.OfType<BoundedMemoryTarget>().FirstOrDefault();
+ var boundedMemoryTarget = LogManager.Configuration.AllTargets.OfType<BoundedMemoryTarget>().FirstOrDefault();
if(boundedMemoryTarget == null)
{
context.SetStatusToNotFound();
@@ -30,8 +32,17 @@ public override void Respond(IHttpContext context)
});
return;
}
+ IEnumerable<LogEventInfo> log = boundedMemoryTarget.GeneralLog;
- context.WriteJson(boundedMemoryTarget.GetSnapshot().Select(x => new
+ switch (context.Request.QueryString["type"])
+ {
+ case "error":
+ case "warn":
+ log = boundedMemoryTarget.WarnLog;
+ break;
+ }
+
+ context.WriteJson(log.Select(x => new
{
x.TimeStamp,
Message = x.FormattedMessage,
25 Raven.Database/Util/BoundedMemoryTarget.cs
View
@@ -12,21 +12,34 @@ namespace Raven.Database.Util
{
public class BoundedMemoryTarget : Target
{
- private readonly ConcurrentQueue<LogEventInfo> items = new ConcurrentQueue<LogEventInfo>();
+ private readonly ConcurrentQueue<LogEventInfo> generalLog = new ConcurrentQueue<LogEventInfo>();
+ private readonly ConcurrentQueue<LogEventInfo> warnLog = new ConcurrentQueue<LogEventInfo>();
protected override void Write(LogEventInfo logEvent)
{
- items.Enqueue(logEvent);
- if (items.Count <= 500)
+ AddToQueue(logEvent, generalLog);
+ if(logEvent.Level>=LogLevel.Warn)
+ AddToQueue(logEvent, warnLog);
+ }
+
+ private void AddToQueue(LogEventInfo logEvent, ConcurrentQueue<LogEventInfo> logEventInfos)
+ {
+ logEventInfos.Enqueue(logEvent);
+ if (logEventInfos.Count <= 500)
return;
LogEventInfo _;
- items.TryDequeue(out _);
+ logEventInfos.TryDequeue(out _);
+ }
+
+ public IEnumerable<LogEventInfo> GeneralLog
+ {
+ get { return generalLog; }
}
- public IEnumerable<LogEventInfo> GetSnapshot()
+ public IEnumerable<LogEventInfo> WarnLog
{
- return items;
+ get { return warnLog; }
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.