1
0
mirror of https://github.com/bitwarden/server.git synced 2025-02-22 02:51:33 +01:00

log filters

This commit is contained in:
Kyle Spearrin 2018-03-30 08:38:15 -04:00
parent 1e0dc92627
commit 0e143a78e5
4 changed files with 49 additions and 9 deletions

View File

@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Documents.Client;
using Microsoft.Azure.Documents.Linq;
using Serilog.Events;
namespace Bit.Admin.Controllers
{
@ -25,7 +26,8 @@ namespace Bit.Admin.Controllers
_globalSettings = globalSettings;
}
public async Task<IActionResult> Index(string cursor = null, int count = 50)
public async Task<IActionResult> Index(string cursor = null, int count = 50,
LogEventLevel? level = null, string project = null)
{
var collectionLink = UriFactory.CreateDocumentCollectionUri(Database, Collection);
using(var client = new DocumentClient(new Uri(_globalSettings.DocumentDb.Uri),
@ -37,12 +39,23 @@ namespace Bit.Admin.Controllers
RequestContinuation = cursor
};
var query = client.CreateDocumentQuery(collectionLink, options)
.OrderByDescending(l => l.Timestamp).AsDocumentQuery();
var response = await query.ExecuteNextAsync<LogModel>();
return View(new CursorPagedModel<LogModel>
var query = client.CreateDocumentQuery<LogModel>(collectionLink, options).AsQueryable();
if(level.HasValue)
{
query = query.Where(l => l.Level == level.Value.ToString());
}
if(!string.IsNullOrWhiteSpace(project))
{
query = query.Where(l => l.Properties != null && l.Properties["Project"] == (object)project);
}
var docQuery = query.OrderByDescending(l => l.Timestamp).AsDocumentQuery();
var response = await docQuery.ExecuteNextAsync<LogModel>();
return View(new LogsModel
{
Level = level,
Project = project,
Items = response.ToList(),
Count = count,
Cursor = cursor,

View File

@ -10,7 +10,7 @@ namespace Bit.Admin.Models
public class LogModel : Resource
{
public long EventIdHash { get; set; }
public LogEventLevel Level { get; set; }
public string Level { get; set; }
public string Message { get; set; }
public string MessageTruncated => Message.Length > 200 ? $"{Message.Substring(0, 200)}..." : Message;
public string MessageTemplate { get; set; }

View File

@ -0,0 +1,10 @@
using Serilog.Events;
namespace Bit.Admin.Models
{
public class LogsModel : CursorPagedModel<LogModel>
{
public LogEventLevel? Level { get; set; }
public string Project { get; set; }
}
}

View File

@ -1,4 +1,4 @@
@model CursorPagedModel<LogModel>
@model LogsModel
@{
ViewData["Title"] = "Logs";
}
@ -7,6 +7,22 @@
<p>Current UTC time: @DateTime.UtcNow.ToString()</p>
<form class="form-inline mb-2" method="get">
<label class="sr-only" asp-for="Level">Level</label>
<select class="form-control mb-2 mr-2" asp-for="Level" name="level"
asp-items="Html.GetEnumSelectList<Serilog.Events.LogEventLevel>()">
<option value="">-- Level --</option>
</select>
<label class="sr-only" asp-for="Project">Project</label>
<select class="form-control mb-2 mr-2" asp-for="Project" name="project">
<option asp-selected="string.IsNullOrWhiteSpace(Model.Project)" value="">-- Project --</option>
<option asp-selected="@(Model.Project == "Admin")" value="Admin">Admin</option>
<option asp-selected="@(Model.Project == "Api")" value="Api">Api</option>
<option asp-selected="@(Model.Project == "Identity")" value="Identity">Identity</option>
</select>
<button type="submit" class="btn btn-primary mb-2" title="Search"><i class="fa fa-search"></i> Search</button>
</form>
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
@ -58,7 +74,8 @@
{
<li class="page-item">
<a class="page-link" asp-action="Index" asp-route-cursor="@Model.NextCursor"
asp-route-count="@Model.Count">Next</a>
asp-route-count="@Model.Count" asp-route-project="@Model.Project"
asp-route-level="@Model.Level">Next</a>
</li>
}
</ul>