Skip to content
Open
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
5 changes: 3 additions & 2 deletions src/KinesisProducerNet/CertificateExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ public class CertificateExtractor
"ce5e74ef.0", "dd8e9d41.0", "de6d66f3.0", "e2799e36.0", "f081611a.0", "f387163d.0"
};

private readonly ILogger logger = Logging.CreateLogger<CertificateExtractor>();
private readonly ILogger logger;
public List<string> ExtractedCertificates { get; }

public CertificateExtractor()
public CertificateExtractor(LogLevel logLevel)
{
this.ExtractedCertificates = new List<string>();
this.logger = Logging.CreateLogger<CertificateExtractor>(logLevel);
}

public string ExtractCertificates(string tempDirectory)
Expand Down
8 changes: 4 additions & 4 deletions src/KinesisProducerNet/Daemon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public abstract class Daemon
protected CancellationTokenSource cancelTokenSource;
protected CancellationToken processCancellationToken;
protected byte[] receiveBuffer = new byte[8 * 1024 * 1024];
protected readonly ILogger logger = Logging.CreateLogger<Daemon>();
protected readonly ILogger logger;

protected readonly BlockingCollection<Message> outgoingMessages =
new BlockingCollection<Message>(new ConcurrentQueue<Message>());
Expand Down Expand Up @@ -63,7 +63,7 @@ public Daemon(
this.environmentVariables = environmentVariables;
this.cancelTokenSource = new CancellationTokenSource();
this.processCancellationToken = cancelTokenSource.Token;

this.logger = Logging.CreateLogger<Daemon>(config.LogLevel);
Task.Run(() =>
{
try
Expand Down Expand Up @@ -155,8 +155,8 @@ protected void StartChildProcess()
}
});

this.stdOutReader = new LogInputStreamReader(process.StandardOutput, "StdOut", (log, message) => { log.LogInformation(message); }, this.logger);
this.stdErrReader = new LogInputStreamReader(process.StandardError, "StdErr", (log, message) => { log.LogError(message); }, this.logger);
this.stdOutReader = new LogInputStreamReader(process.StandardOutput, "StdOut", (log, message) => { log.LogInformation(message); }, this.config.LogLevel);
this.stdErrReader = new LogInputStreamReader(process.StandardError, "StdErr", (log, message) => { log.LogError(message); }, this.config.LogLevel);

Task.Run(() => stdOutReader.Run(), processCancellationToken);
Task.Run(() => stdErrReader.Run(), processCancellationToken);
Expand Down
2 changes: 1 addition & 1 deletion src/KinesisProducerNet/FileAgeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class FileAgeManager

private readonly HashSet<string> watchedFiles;
private readonly Timer ticker;
private readonly ILogger logger = Logging.CreateLogger<FileAgeManager>();
private readonly ILogger logger = Logging.CreateLogger<FileAgeManager>(LogLevel.None);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

that is set on purpose cause of my project requirements


private FileAgeManager()
{
Expand Down
6 changes: 3 additions & 3 deletions src/KinesisProducerNet/KinesisProducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ public class KinesisProducer : IKinesisProducer
private static readonly BigInteger UINT_128_MAX = BigInteger.Pow(ulong.MaxValue, 2);

private readonly KinesisProducerConfiguration config;
private readonly ILogger logger = Logging.CreateLogger<KinesisProducer>();
private Daemon child;
private string pathToTmpDir;
private string pathToExecutable;
private string pathToLibDir;
private readonly Dictionary<string, string> envParams;
private long messageNumber = 1;

private readonly ILogger logger;
private readonly ConcurrentDictionary<long, FutureOperationResult> futureOperationResults =
new ConcurrentDictionary<long, FutureOperationResult>();

Expand All @@ -39,6 +38,7 @@ public class KinesisProducer : IKinesisProducer
public KinesisProducer(KinesisProducerConfiguration config)
{
this.config = config;
this.logger = Logging.CreateLogger<KinesisProducer>(config.LogLevel);
this.logger.LogInformation($"Platform: {RuntimeInformation.OSDescription}. Arch: {RuntimeInformation.OSArchitecture}");

var caDirectory = ExtractBinaries();
Expand Down Expand Up @@ -415,7 +415,7 @@ private string ExtractBinaries()
}
}

var certificateExtractor = new CertificateExtractor();
var certificateExtractor = new CertificateExtractor(config.LogLevel);
var caDirectory = certificateExtractor.ExtractCertificates(pathToTmpDir);

watchFiles.AddRange(certificateExtractor.ExtractedCertificates);
Expand Down
3 changes: 2 additions & 1 deletion src/KinesisProducerNet/KinesisProducerConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using Amazon.Runtime;
using KinesisProducerNet.Protobuf;
using Microsoft.Extensions.Logging;

namespace KinesisProducerNet
{
Expand Down Expand Up @@ -163,7 +164,7 @@ public class KinesisProducerConfiguration
/// Default: info
/// Expected pattern: info|warning|error
/// </summary>
public string LogLevel { get; set; } = "info";
public LogLevel LogLevel { get; set; } = LogLevel.Debug;

/// <summary>
/// Maximum number of connections to open to the backend. HTTP requests are sent in parallel over multiple connections.
Expand Down
7 changes: 4 additions & 3 deletions src/KinesisProducerNet/KinesisProducerNet.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PackageId>KinesisProducerNet</PackageId>
<Authors>Serhii Daletskyi</Authors>
<TargetFramework>netstandard1.3</TargetFramework>
<AssemblyVersion>0.12.8.0</AssemblyVersion>
<FileVersion>0.12.8.0</FileVersion>
<AssemblyVersion>2019.10.15.9</AssemblyVersion>
<FileVersion>2019.10.15.9</FileVersion>
<PackageProjectUrl>https://github.com/daletskyi/KinesisProducerNet</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/daletskyi/KinesisProducerNet/blob/master/LICENSE.md</PackageLicenseUrl>
<PackageTags>amazon kinesis producer netstandard</PackageTags>
<Version>0.12.8</Version>
<Title>KinesisProducerNet</Title>
<Description>Unofficial Amazon Kinesis Producer Library (KPL) for .NET. This is a core package which doesn't contain native executable, you also need to install separate package to run under specific platform (ex. KinesisProducerNet.Linux).</Description>
<PackageVersion>2019.10.15.9</PackageVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
7 changes: 3 additions & 4 deletions src/KinesisProducerNet/LogInputStreamReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace KinesisProducerNet
{
public class LogInputStreamReader
{
private readonly ILogger logger = Logging.CreateLogger<LogInputStreamReader>();

private static readonly Regex LevelRegex = new Regex(@"(?<level>trace|debug|info|warn(?:ing)?|error|fatal)",
RegexOptions.Multiline | RegexOptions.Compiled | RegexOptions.IgnoreCase);
Expand All @@ -32,17 +31,17 @@ public class LogInputStreamReader
private volatile bool shuttingDown = false;
private bool isReadingRecord;
private readonly LinkedList<string> messageData = new LinkedList<string>();

private readonly ILogger logger;
public LogInputStreamReader(
StreamReader reader,
string streamType,
Action<ILogger, string> logFunction,
ILogger logger)
LogLevel logLevel)
{
this.reader = reader;
this.streamType = streamType;
this.logFunction = logFunction;
this.logger = logger;
this.logger = Logging.CreateLogger<LogInputStreamReader>(logLevel);
}

public void Run()
Expand Down
4 changes: 2 additions & 2 deletions src/KinesisProducerNet/Logging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace KinesisProducerNet
{
public static class Logging
{
public static ILoggerFactory LoggerFactory { get; } = new LoggerFactory().AddConsole(LogLevel.Debug);
public static ILogger CreateLogger<T>() => LoggerFactory.CreateLogger<T>();
public static ILoggerFactory LoggerFactory(LogLevel logLevel) => new LoggerFactory().AddConsole(logLevel);
public static ILogger CreateLogger<T>(LogLevel loglevel) => LoggerFactory(loglevel).CreateLogger<T>();
}
}
12 changes: 7 additions & 5 deletions src/KinesisProducerNet/Protobuf/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Consider using 'partial classes' to extend these types
// Input: config.proto

using Microsoft.Extensions.Logging;

#pragma warning disable CS1591, CS0612, CS3021

namespace KinesisProducerNet.Protobuf
Expand Down Expand Up @@ -161,14 +163,14 @@ public ulong KinesisPort

[global::ProtoBuf.ProtoMember(13, Name = @"log_level")]
[global::System.ComponentModel.DefaultValue(@"info")]
public string LogLevel
public LogLevel LogLevel
{
get { return __pbn__LogLevel ?? @"info"; }
set { __pbn__LogLevel = value; }
get { return __pbn__LogLevel; }
set => __pbn__LogLevel = value;
}
public bool ShouldSerializeLogLevel() => __pbn__LogLevel != null;
public void ResetLogLevel() => __pbn__LogLevel = null;
private string __pbn__LogLevel;
public void ResetLogLevel() => __pbn__LogLevel = LogLevel.None;
private LogLevel __pbn__LogLevel;

[global::ProtoBuf.ProtoMember(14, Name = @"max_connections")]
[global::System.ComponentModel.DefaultValue(24)]
Expand Down