Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add file log #138

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Joba.IBM.RPA.Cli/BuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ public BuildCommand() : base(CommandName, "Builds projects and bots.")
AddOption(name);
AddOption(output);
this.SetHandler(HandleAsync, name, output,
Bind.FromLogger<RobotCommand>(),
Bind.FromLogger<BuildCommand>(),
Bind.FromServiceProvider<IProject>(),
Bind.FromServiceProvider<ICompiler>(),
Bind.FromServiceProvider<InvocationContext>());
}

private async Task HandleAsync(WalFileName? name, DirectoryInfo? outputDirectory, ILogger<RobotCommand> logger, IProject project, ICompiler compiler, InvocationContext context)
private async Task HandleAsync(WalFileName? name, DirectoryInfo? outputDirectory, ILogger<BuildCommand> logger, IProject project, ICompiler compiler, InvocationContext context)
{
var cancellation = context.GetCancellationToken();

Expand Down
11 changes: 9 additions & 2 deletions src/Joba.IBM.RPA.Cli/Framework/CommandLineBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using OpenTelemetry;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
using System;
using System.CommandLine.Builder;
using System.CommandLine.Parsing;
using System.Diagnostics;
Expand Down Expand Up @@ -50,13 +49,21 @@ static void CreateTracer(CommandLineBuilder builder)
}
}

internal static CommandLineBuilder RegisterLoggerFactory(this CommandLineBuilder builder)
internal static CommandLineBuilder ConfigureLoggers(this CommandLineBuilder builder)
{
return builder.AddMiddleware(async (context, next) =>
{
var verbosity = context.ParseResult.GetValueForOption(RpaCommand.VerbosityOption);
var loggerFactory = LoggerFactory.Create(builder =>
{
//configuring simple logging to file
builder.AddFile($"{RpaCommand.ServiceName}.log", options => //TODO: use the '.rpa' hidden dir
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

address this TODO comment.

{
options.MinLevel = verbosity.ToLogLevel();
options.UseUtcTimestamp = true;
options.FileSizeLimitBytes = 1000000; //1mb
});

builder.AddOpenTelemetry(o =>
{
o.IncludeFormattedMessage = true;
Expand Down
1 change: 1 addition & 0 deletions src/Joba.IBM.RPA.Cli/Joba.IBM.RPA.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="7.0.12" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageReference Include="NReco.Logging.File" Version="1.1.7" />
<PackageReference Include="OpenTelemetry.Extensions" Version="1.0.0-beta2.88" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.0.0-rc9.14" />
<PackageReference Include="Polly.Contrib.WaitAndRetry" Version="1.1.1" />
Expand Down
8 changes: 4 additions & 4 deletions src/Joba.IBM.RPA.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static Task<int> Main(string[] args)
{
var parser = new CommandLineBuilder(new RpaCommand())
.AddInstrumentation()
.RegisterLoggerFactory()
.ConfigureLoggers()
.TrackUsage()
.UseHelp()
.UseVersionOption()
Expand Down Expand Up @@ -83,18 +83,18 @@ private static async Task Middleware(InvocationContext context, Func<InvocationC
{
var loggerFactory = context.BindingContext.GetRequiredService<ILoggerFactory>();
context.BindingContext.AddService<ISecretProvider>(s => new DefaultSecretProvider());
context.BindingContext.AddService<IRpaHttpClientFactory>(s => new RpaHttpClientFactory(loggerFactory.CreateLogger<ILogger<RpaClientFactory>>()));
context.BindingContext.AddService<IRpaHttpClientFactory>(s => new RpaHttpClientFactory(loggerFactory.CreateLogger<RpaClientFactory>()));
context.BindingContext.AddService<IAccountAuthenticatorFactory>(s => new AccountAuthenticatorFactory(
s.GetRequiredService<IRpaClientFactory>(), s.GetRequiredService<IRpaHttpClientFactory>()));
context.BindingContext.AddService<IRpaClientFactory>(s => new RpaClientFactory(
context.Console, s.GetRequiredService<IRpaHttpClientFactory>()));
context.BindingContext.AddService<IDeployService>(s => new DeployService(
loggerFactory.CreateLogger<ILogger<DeployService>>(),
loggerFactory.CreateLogger<DeployService>(),
s.GetRequiredService<IRpaClientFactory>(),
s.GetRequiredService<ICompiler>()));
context.BindingContext.AddService<IPackageManagerFactory>(s => new PackageManagerFactory(s.GetRequiredService<IRpaClientFactory>()));
context.BindingContext.AddService<ICompiler>(s => new Bluewasher(
loggerFactory.CreateLogger<ILogger<Bluewasher>>(),
loggerFactory.CreateLogger<Bluewasher>(),
s.GetRequiredService<IPackageManagerFactory>()));

if (context.ParseResult.CommandResult != context.ParseResult.RootCommandResult &&
Expand Down
Loading