Skip to content

Commit

Permalink
use ASCII logger in NuGet loader
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidVollmers committed Jun 22, 2024
1 parent 6376056 commit ce99b46
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Doki.CommandLine/Commands/GenerateCommand.Outputs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal partial class GenerateCommand

var nugetFolder = Path.Combine(workingDirectory.FullName, ".doki", "nuget");

using var nugetLoader = new NuGetLoader(output.From);
using var nugetLoader = new NuGetLoader(_logger, output.From);

var assemblyPath =
await nugetLoader.LoadPackageAsync(output.Type, nugetFolder, allowPreview, cancellationToken);
Expand Down
7 changes: 4 additions & 3 deletions src/Doki.CommandLine/NuGet/NuGetLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ internal class NuGetLoader : IDisposable
{
private readonly SourceCacheContext _cacheContext = new();

//TODO use console logger (ASCII)
private readonly ILogger _logger = NullLogger.Instance;
private readonly NuGetLogger _logger;
private readonly SourceRepositoryProvider _sourceRepositoryProvider;

public NuGetLoader(string? source = null)
public NuGetLoader(Microsoft.Extensions.Logging.ILogger logger, string? source = null)
{
_logger = new NuGetLogger(logger);

var sources = new List<PackageSource>
{
new("https://api.nuget.org/v3/index.json")
Expand Down
85 changes: 85 additions & 0 deletions src/Doki.CommandLine/NuGet/NuGetLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using Microsoft.Extensions.Logging;
using NuGet.Common;
using ILogger = NuGet.Common.ILogger;
using LogLevel = NuGet.Common.LogLevel;

namespace Doki.CommandLine.NuGet;

internal class NuGetLogger(Microsoft.Extensions.Logging.ILogger logger) : ILogger
{
public void LogDebug(string data)
{
logger.LogDebug(data);
}

public void LogVerbose(string data)
{
logger.LogTrace(data);
}

public void LogInformation(string data)
{
logger.LogInformation(data);
}

public void LogMinimal(string data)
{
logger.LogInformation(data);
}

public void LogWarning(string data)
{
logger.LogWarning(data);
}

public void LogError(string data)
{
logger.LogError(data);
}

public void LogInformationSummary(string data)
{
logger.LogInformation(data);
}

public void Log(LogLevel level, string data)
{
switch (level)
{
case LogLevel.Debug:
LogDebug(data);
break;
case LogLevel.Verbose:
LogVerbose(data);
break;
case LogLevel.Information:
LogInformation(data);
break;
case LogLevel.Minimal:
LogMinimal(data);
break;
case LogLevel.Warning:
LogWarning(data);
break;
case LogLevel.Error:
LogError(data);
break;
}
}

public Task LogAsync(LogLevel level, string data)
{
Log(level, data);
return Task.CompletedTask;
}

public void Log(ILogMessage message)
{
Log(message.Level, message.Message);
}

public Task LogAsync(ILogMessage message)
{
return LogAsync(message.Level, message.Message);
}
}

0 comments on commit ce99b46

Please sign in to comment.