Skip to content

Commit

Permalink
Merge pull request #4585 from microsoft/bugfix/empty-log-file
Browse files Browse the repository at this point in the history
- fixes empty log file issue
  • Loading branch information
baywet authored May 2, 2024
2 parents cf49c32 + ff534e5 commit 3ef4ec1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fixed a bug where the Microsoft Plugin Manifests would start with relative paths. [#4583](https://github.com/microsoft/kiota/issues/4583)
- Fixed a bug where TypeScript deserialization would fail on Uppercase properties.[#4479](https://github.com/microsoft/kiota/issues/4479)
- Fixed a bug where clients and plugins generation would leave empty log files. [#4584](https://github.com/microsoft/kiota/issues/4584)
- Changed URI template generation to reuse templates when required templates are absent across operations.
- Fixed path deduplication logic to avoid double `Id` suffixes in indexer names in scenarios where the `Id` suffix is already present.[#4519](https://github.com/microsoft/kiota/issues/4519)
- Updated reserved name providers for Java and Php so that "object" can be escaped.
Expand Down
12 changes: 10 additions & 2 deletions src/kiota/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ static async Task<int> Main(string[] args)
{
var rootCommand = KiotaHost.GetRootCommand();
var result = await rootCommand.InvokeAsync(args);
foreach (var subCommand in rootCommand.Subcommands.Select(static x => x.Handler).OfType<IDisposable>())
subCommand.Dispose();
DisposeSubCommands(rootCommand);
return result;
}
private static void DisposeSubCommands(this Command command)
{
if (command.Handler is IDisposable disposableHandler)
disposableHandler.Dispose();
foreach (var subCommand in command.Subcommands)
{
DisposeSubCommands(subCommand);
}
}
}
40 changes: 40 additions & 0 deletions tests/Kiota.Builder.Tests/Logging/FileLoggerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.IO;
using Kiota.Builder.Logging;
using Microsoft.Extensions.Logging;
using Xunit;

namespace Kiota.Builder.Tests.Logging;

public sealed class FileLoggerTests : IDisposable
{
private readonly string _logDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
public FileLoggerTests()
{
Directory.CreateDirectory(_logDirectory);
}
[Fact]
public void CleansUpFileWhenNoLogs()
{
using (var logger = new FileLogLogger(_logDirectory, LogLevel.Warning, "test"))
{ //using this format intentionally to ensure the dispose is called before the assert
logger.LogInformation("test");
}
Assert.False(File.Exists(Path.Combine(_logDirectory, FileLogLogger.LogFileName)));
}
[Fact]
public void KeepsLogFileWhenLogs()
{
using (var logger = new FileLogLogger(_logDirectory, LogLevel.Warning, "test"))
{ //using this format intentionally to ensure the dispose is called before the assert
logger.LogWarning("test");
}
Assert.True(File.Exists(Path.Combine(_logDirectory, FileLogLogger.LogFileName)));
}

public void Dispose()
{
if (Directory.Exists(_logDirectory))
Directory.Delete(_logDirectory, true);
}
}

0 comments on commit 3ef4ec1

Please sign in to comment.