2012-01-23 05:24:16 +03:00
|
|
|
using System;
|
2012-02-09 20:41:51 +03:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq.Dynamic;
|
2012-01-23 05:24:16 +03:00
|
|
|
using System.Text;
|
|
|
|
using System.Web.Mvc;
|
2012-04-23 09:31:11 +03:00
|
|
|
using DataTables.Mvc.Core;
|
2012-04-21 08:02:18 +03:00
|
|
|
using DataTables.Mvc.Core.Models;
|
2012-01-23 05:24:16 +03:00
|
|
|
using NzbDrone.Common;
|
2010-10-24 10:46:58 +03:00
|
|
|
using NzbDrone.Core.Instrumentation;
|
2011-08-22 04:00:12 +03:00
|
|
|
using NzbDrone.Web.Models;
|
2010-10-24 10:46:58 +03:00
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
{
|
|
|
|
public class LogController : Controller
|
|
|
|
{
|
2011-04-10 03:14:51 +03:00
|
|
|
private readonly LogProvider _logProvider;
|
2012-03-07 05:59:43 +03:00
|
|
|
private readonly EnvironmentProvider _environmentProvider;
|
2012-01-23 05:24:16 +03:00
|
|
|
private readonly DiskProvider _diskProvider;
|
2010-10-24 10:46:58 +03:00
|
|
|
|
2012-04-21 11:16:15 +03:00
|
|
|
public LogController(LogProvider logProvider, EnvironmentProvider environmentProvider,
|
2012-04-23 09:31:11 +03:00
|
|
|
DiskProvider diskProvider)
|
2010-10-24 10:46:58 +03:00
|
|
|
{
|
|
|
|
_logProvider = logProvider;
|
2012-03-07 05:59:43 +03:00
|
|
|
_environmentProvider = environmentProvider;
|
2012-01-23 05:24:16 +03:00
|
|
|
_diskProvider = diskProvider;
|
2010-10-24 10:46:58 +03:00
|
|
|
}
|
|
|
|
|
2012-01-23 05:24:16 +03:00
|
|
|
public FileContentResult File()
|
|
|
|
{
|
|
|
|
string log = string.Empty;
|
|
|
|
|
2012-03-07 05:59:43 +03:00
|
|
|
if (_diskProvider.FileExists(_environmentProvider.GetArchivedLogFileName()))
|
2012-01-23 05:24:16 +03:00
|
|
|
{
|
2012-03-07 05:59:43 +03:00
|
|
|
log = _diskProvider.ReadAllText(_environmentProvider.GetArchivedLogFileName());
|
2012-01-23 05:24:16 +03:00
|
|
|
}
|
|
|
|
|
2012-03-07 05:59:43 +03:00
|
|
|
log += _diskProvider.ReadAllText(_environmentProvider.GetLogFileName());
|
2012-01-23 05:24:16 +03:00
|
|
|
|
|
|
|
return new FileContentResult(Encoding.ASCII.GetBytes(log), "text/plain");
|
|
|
|
}
|
|
|
|
|
2011-08-06 05:04:35 +03:00
|
|
|
public JsonResult Clear()
|
2010-10-24 10:46:58 +03:00
|
|
|
{
|
|
|
|
_logProvider.DeleteAll();
|
2011-08-06 05:04:35 +03:00
|
|
|
|
2012-01-19 08:01:47 +03:00
|
|
|
return JsonNotificationResult.Info("Logs Cleared");
|
2011-09-05 22:59:39 +03:00
|
|
|
}
|
|
|
|
|
2012-07-28 09:37:47 +03:00
|
|
|
public ActionResult AjaxBinding(DataTablesPageRequest pageRequest)
|
2012-02-09 20:41:51 +03:00
|
|
|
{
|
2013-01-08 11:57:38 +03:00
|
|
|
var pageResult = _logProvider.GetPagedItems(pageRequest);
|
|
|
|
var totalItems = _logProvider.Count();
|
2012-02-09 20:41:51 +03:00
|
|
|
|
2013-01-08 11:57:38 +03:00
|
|
|
var items = pageResult.Items.Select(l => new LogModel
|
2012-02-09 20:41:51 +03:00
|
|
|
{
|
2013-01-08 11:57:38 +03:00
|
|
|
Time = l.Time.ToString(),
|
|
|
|
Level = l.Level,
|
|
|
|
Source = l.Logger,
|
|
|
|
Message = l.Message,
|
|
|
|
Method = l.Method,
|
|
|
|
ExceptionType = l.ExceptionType,
|
|
|
|
Exception = l.Exception
|
|
|
|
});
|
2012-02-09 20:41:51 +03:00
|
|
|
|
|
|
|
return Json(new
|
|
|
|
{
|
2012-07-28 09:37:47 +03:00
|
|
|
sEcho = pageRequest.Echo,
|
2013-01-08 11:57:38 +03:00
|
|
|
iTotalRecords = totalItems,
|
|
|
|
iTotalDisplayRecords = pageResult.TotalItems,
|
|
|
|
aaData = items
|
2012-02-09 20:41:51 +03:00
|
|
|
},
|
|
|
|
JsonRequestBehavior.AllowGet);
|
|
|
|
}
|
2010-10-24 10:46:58 +03:00
|
|
|
}
|
2011-04-10 05:44:01 +03:00
|
|
|
}
|