Browse Source

Even better logs.

pull/860/head
Sebastian 4 years ago
parent
commit
0ebcf32608
  1. 23
      backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/StringLogger.cs
  2. 12
      backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/TemplateCommandMiddleware.cs

23
backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/StringLogger.cs

@ -6,23 +6,25 @@
// ==========================================================================
using System.Globalization;
using Microsoft.Extensions.Logging;
using Squidex.CLI.Commands.Implementation;
using Squidex.Infrastructure;
using ILog = Microsoft.Extensions.Logging.ILogger;
using Squidex.Log;
namespace Squidex.Domain.Apps.Entities.Apps.Templates
{
public sealed class StringLogger : CLI.Commands.Implementation.ILogger, ILogLine
public sealed class StringLogger : ILogger, ILogLine
{
private const int MaxActionLength = 40;
private readonly ILog log;
private readonly ISemanticLog log;
private readonly string template;
private readonly List<string> lines = new List<string>();
private readonly List<string> errors = new List<string>();
private string startedLine = string.Empty;
public StringLogger(ILog log)
public StringLogger(string template, ISemanticLog log)
{
this.template = template;
this.log = log;
}
@ -30,7 +32,16 @@ namespace Squidex.Domain.Apps.Entities.Apps.Templates
{
var mesage = string.Join('\n', lines);
log.LogInformation("CLI executed with full logs {steps}.", mesage);
log.LogInformation(w => w
.WriteProperty("message", $"CLI executed or template {template}.")
.WriteProperty("template", template)
.WriteArray("steps", a =>
{
foreach (var line in lines)
{
a.WriteValue(line);
}
}));
if (errors.Count > 0)
{

12
backend/src/Squidex.Domain.Apps.Entities/Apps/Templates/TemplateCommandMiddleware.cs

@ -21,6 +21,7 @@ using Squidex.ClientLibrary.Configuration;
using Squidex.Domain.Apps.Core;
using Squidex.Domain.Apps.Entities.Apps.Commands;
using Squidex.Infrastructure.Commands;
using Squidex.Log;
namespace Squidex.Domain.Apps.Entities.Apps.Templates
{
@ -28,13 +29,14 @@ namespace Squidex.Domain.Apps.Entities.Apps.Templates
{
private readonly TemplatesClient templatesClient;
private readonly IUrlGenerator urlGenerator;
private readonly ILogger<TemplateCommandMiddleware> log;
private readonly ISemanticLog log;
public TemplateCommandMiddleware(TemplatesClient templatesClient, IUrlGenerator urlGenerator,
ILogger<TemplateCommandMiddleware> log)
ISemanticLog log)
{
this.templatesClient = templatesClient;
this.urlGenerator = urlGenerator;
this.log = log;
}
@ -59,11 +61,13 @@ namespace Squidex.Domain.Apps.Entities.Apps.Templates
if (string.IsNullOrEmpty(repository))
{
log.LogWarning("Cannot find template {template}.", template);
log.LogWarning(w => w
.WriteProperty("message", "Template not found.")
.WriteProperty("template", template));
return;
}
using (var cliLog = new StringLogger(log))
using (var cliLog = new StringLogger(template, log))
{
var session = CreateSession(app);

Loading…
Cancel
Save