2012-01-23 02:24:16 +00:00
|
|
|
|
using System;
|
2012-02-09 17:41:51 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Linq.Dynamic;
|
2012-01-23 02:24:16 +00:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Web.Mvc;
|
2012-04-23 06:31:11 +00:00
|
|
|
|
using DataTables.Mvc.Core;
|
2012-04-21 05:02:18 +00:00
|
|
|
|
using DataTables.Mvc.Core.Models;
|
2012-01-23 02:24:16 +00:00
|
|
|
|
using NzbDrone.Common;
|
2010-10-24 07:46:58 +00:00
|
|
|
|
using NzbDrone.Core.Instrumentation;
|
2011-08-22 01:00:12 +00:00
|
|
|
|
using NzbDrone.Web.Models;
|
2010-10-24 07:46:58 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class LogController : Controller
|
|
|
|
|
{
|
2011-04-10 00:14:51 +00:00
|
|
|
|
private readonly LogProvider _logProvider;
|
2012-03-07 02:59:43 +00:00
|
|
|
|
private readonly EnvironmentProvider _environmentProvider;
|
2012-01-23 02:24:16 +00:00
|
|
|
|
private readonly DiskProvider _diskProvider;
|
2010-10-24 07:46:58 +00:00
|
|
|
|
|
2012-04-21 08:16:15 +00:00
|
|
|
|
public LogController(LogProvider logProvider, EnvironmentProvider environmentProvider,
|
2012-04-23 06:31:11 +00:00
|
|
|
|
DiskProvider diskProvider)
|
2010-10-24 07:46:58 +00:00
|
|
|
|
{
|
|
|
|
|
_logProvider = logProvider;
|
2012-03-07 02:59:43 +00:00
|
|
|
|
_environmentProvider = environmentProvider;
|
2012-01-23 02:24:16 +00:00
|
|
|
|
_diskProvider = diskProvider;
|
2010-10-24 07:46:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-23 02:24:16 +00:00
|
|
|
|
public FileContentResult File()
|
|
|
|
|
{
|
|
|
|
|
string log = string.Empty;
|
|
|
|
|
|
2012-03-07 02:59:43 +00:00
|
|
|
|
if (_diskProvider.FileExists(_environmentProvider.GetArchivedLogFileName()))
|
2012-01-23 02:24:16 +00:00
|
|
|
|
{
|
2012-03-07 02:59:43 +00:00
|
|
|
|
log = _diskProvider.ReadAllText(_environmentProvider.GetArchivedLogFileName());
|
2012-01-23 02:24:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-07 02:59:43 +00:00
|
|
|
|
log += _diskProvider.ReadAllText(_environmentProvider.GetLogFileName());
|
2012-01-23 02:24:16 +00:00
|
|
|
|
|
|
|
|
|
return new FileContentResult(Encoding.ASCII.GetBytes(log), "text/plain");
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-06 02:04:35 +00:00
|
|
|
|
public JsonResult Clear()
|
2010-10-24 07:46:58 +00:00
|
|
|
|
{
|
|
|
|
|
_logProvider.DeleteAll();
|
2011-08-06 02:04:35 +00:00
|
|
|
|
|
2012-01-19 05:01:47 +00:00
|
|
|
|
return JsonNotificationResult.Info("Logs Cleared");
|
2011-09-05 19:59:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-28 06:37:47 +00:00
|
|
|
|
public ActionResult AjaxBinding(DataTablesPageRequest pageRequest)
|
2012-02-09 17:41:51 +00:00
|
|
|
|
{
|
|
|
|
|
var logs = _logProvider.GetAllLogs();
|
|
|
|
|
var totalCount = logs.Count();
|
|
|
|
|
|
|
|
|
|
IQueryable<Log> q = logs;
|
2012-07-28 06:37:47 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(pageRequest.Search))
|
2012-02-09 17:41:51 +00:00
|
|
|
|
{
|
2012-07-28 06:37:47 +00:00
|
|
|
|
q = q.Where(b => b.Logger.Contains(pageRequest.Search)
|
|
|
|
|
|| b.Exception.Contains(pageRequest.Search)
|
|
|
|
|
|| b.Message.Contains(pageRequest.Search));
|
2012-02-09 17:41:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int filteredCount = q.Count();
|
|
|
|
|
|
2012-02-25 23:14:48 +00:00
|
|
|
|
IQueryable<Log> sorted = q;
|
2012-02-09 17:41:51 +00:00
|
|
|
|
|
2012-07-28 06:37:47 +00:00
|
|
|
|
for (int i = 0; i < pageRequest.SortingCols; i++)
|
2012-02-25 23:14:48 +00:00
|
|
|
|
{
|
2012-07-28 06:37:47 +00:00
|
|
|
|
int sortCol = pageRequest.SortCol[i];
|
2012-02-25 23:14:48 +00:00
|
|
|
|
var sortColName = sortCol == 0 ? "Time" : sortCol == 1 ? "Level" : "Logger";
|
2012-07-28 06:37:47 +00:00
|
|
|
|
var sortExpression = String.Format("{0} {1}", sortColName, pageRequest.SortDir[i]);
|
2012-02-25 23:14:48 +00:00
|
|
|
|
|
|
|
|
|
sorted = sorted.OrderBy(sortExpression);
|
|
|
|
|
}
|
2012-02-09 17:41:51 +00:00
|
|
|
|
|
|
|
|
|
IQueryable<Log> filteredAndSorted = sorted;
|
2012-07-28 06:37:47 +00:00
|
|
|
|
if (filteredCount > pageRequest.DisplayLength)
|
2012-02-09 17:41:51 +00:00
|
|
|
|
{
|
2012-07-28 06:37:47 +00:00
|
|
|
|
filteredAndSorted = sorted.Skip(pageRequest.DisplayStart).Take(pageRequest.DisplayLength);
|
2012-02-09 17:41:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var logModels = filteredAndSorted.ToList().Select(s => new LogModel
|
|
|
|
|
{
|
|
|
|
|
Time = s.Time.ToString(),
|
|
|
|
|
Level = s.Level,
|
|
|
|
|
Source = s.Logger,
|
|
|
|
|
Message = s.Message,
|
|
|
|
|
Method = s.Method,
|
|
|
|
|
ExceptionType = s.ExceptionType,
|
|
|
|
|
Exception = s.Exception
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return Json(new
|
|
|
|
|
{
|
2012-07-28 06:37:47 +00:00
|
|
|
|
sEcho = pageRequest.Echo,
|
2012-02-09 17:41:51 +00:00
|
|
|
|
iTotalRecords = totalCount,
|
|
|
|
|
iTotalDisplayRecords = filteredCount,
|
|
|
|
|
aaData = logModels
|
|
|
|
|
},
|
|
|
|
|
JsonRequestBehavior.AllowGet);
|
|
|
|
|
}
|
2010-10-24 07:46:58 +00:00
|
|
|
|
}
|
2011-04-10 02:44:01 +00:00
|
|
|
|
}
|