From dd7fdd8acee09d23e84cea927de0c754bb3f1516 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Wed, 4 Jan 2017 17:56:29 -0800 Subject: [PATCH] Disable Sentry Reporting based on analytics flag --- src/NzbDrone.Api/TinyIoCNancyBootstrapper.cs | 2 +- .../Composition/ContainerBuilderBase.cs | 1 - .../Instrumentation/NzbDroneLogger.cs | 13 ++++++++----- .../DatabaseTargetFixture.cs | 2 +- src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 3 ++- .../Configuration/ConfigFileProvider.cs | 10 ++++++++-- src/NzbDrone.Update/UpdateApp.cs | 6 +++--- 7 files changed, 23 insertions(+), 14 deletions(-) rename src/NzbDrone.Core.Test/{InstrumentationTests => Instrumentation}/DatabaseTargetFixture.cs (98%) diff --git a/src/NzbDrone.Api/TinyIoCNancyBootstrapper.cs b/src/NzbDrone.Api/TinyIoCNancyBootstrapper.cs index 5be766761..d938b0c6e 100644 --- a/src/NzbDrone.Api/TinyIoCNancyBootstrapper.cs +++ b/src/NzbDrone.Api/TinyIoCNancyBootstrapper.cs @@ -22,7 +22,7 @@ namespace NzbDrone.Api /// public static IEnumerable> DefaultAutoRegisterIgnoredAssemblies = new Func[] { - asm => !asm.FullName.StartsWith("Nancy.", StringComparison.InvariantCulture), + asm => !asm.FullName.StartsWith("Nancy.", StringComparison.InvariantCulture) }; /// diff --git a/src/NzbDrone.Common/Composition/ContainerBuilderBase.cs b/src/NzbDrone.Common/Composition/ContainerBuilderBase.cs index ac33941ea..a4174a26f 100644 --- a/src/NzbDrone.Common/Composition/ContainerBuilderBase.cs +++ b/src/NzbDrone.Common/Composition/ContainerBuilderBase.cs @@ -6,7 +6,6 @@ using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Messaging; using TinyIoC; - namespace NzbDrone.Common.Composition { public abstract class ContainerBuilderBase diff --git a/src/NzbDrone.Common/Instrumentation/NzbDroneLogger.cs b/src/NzbDrone.Common/Instrumentation/NzbDroneLogger.cs index 55a7071ae..75b9c8739 100644 --- a/src/NzbDrone.Common/Instrumentation/NzbDroneLogger.cs +++ b/src/NzbDrone.Common/Instrumentation/NzbDroneLogger.cs @@ -59,6 +59,12 @@ namespace NzbDrone.Common.Instrumentation LogManager.ReconfigExistingLoggers(); } + public static void UnRegisterRemoteLoggers() + { + LogManager.Configuration.RemoveTarget("sentryTarget"); + LogManager.ReconfigExistingLoggers(); + } + private static void RegisterLogEntries() { var target = new LogentriesTarget(); @@ -112,7 +118,6 @@ namespace NzbDrone.Common.Instrumentation LogManager.Configuration.LoggingRules.Add(loggingRule); } - private static void RegisterConsole() { var level = LogLevel.Trace; @@ -128,7 +133,7 @@ namespace NzbDrone.Common.Instrumentation LogManager.Configuration.LoggingRules.Add(loggingRule); } - const string FILE_LOG_LAYOUT = @"${date:format=yy-M-d HH\:mm\:ss.f}|${level}|${logger}|${message}${onexception:inner=${newline}${newline}[v${assembly-version}] ${exception:format=ToString}${newline}}"; + private const string FILE_LOG_LAYOUT = @"${date:format=yy-M-d HH\:mm\:ss.f}|${level}|${logger}|${message}${onexception:inner=${newline}${newline}[v${assembly-version}] ${exception:format=ToString}${newline}}"; private static void RegisterAppFile(IAppFolderInfo appFolderInfo) { @@ -137,7 +142,7 @@ namespace NzbDrone.Common.Instrumentation RegisterAppFile(appFolderInfo, "appFileTrace", "sonarr.trace.txt", 50, LogLevel.Off); } - private static LoggingRule RegisterAppFile(IAppFolderInfo appFolderInfo, string name, string fileName, int maxArchiveFiles, LogLevel minLogLevel) + private static void RegisterAppFile(IAppFolderInfo appFolderInfo, string name, string fileName, int maxArchiveFiles, LogLevel minLogLevel) { var fileTarget = new NzbDroneFileTarget(); @@ -158,8 +163,6 @@ namespace NzbDrone.Common.Instrumentation LogManager.Configuration.AddTarget(name, fileTarget); LogManager.Configuration.LoggingRules.Add(loggingRule); - - return loggingRule; } private static void RegisterUpdateFile(IAppFolderInfo appFolderInfo) diff --git a/src/NzbDrone.Core.Test/InstrumentationTests/DatabaseTargetFixture.cs b/src/NzbDrone.Core.Test/Instrumentation/DatabaseTargetFixture.cs similarity index 98% rename from src/NzbDrone.Core.Test/InstrumentationTests/DatabaseTargetFixture.cs rename to src/NzbDrone.Core.Test/Instrumentation/DatabaseTargetFixture.cs index ad614e646..716b5c042 100644 --- a/src/NzbDrone.Core.Test/InstrumentationTests/DatabaseTargetFixture.cs +++ b/src/NzbDrone.Core.Test/Instrumentation/DatabaseTargetFixture.cs @@ -12,7 +12,7 @@ using NzbDrone.Core.Test.Framework; using NzbDrone.Test.Common; using NzbDrone.Test.Common.Categories; -namespace NzbDrone.Core.Test.InstrumentationTests +namespace NzbDrone.Core.Test.Instrumentation { [TestFixture] public class DatabaseTargetFixture : DbTest diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index c3bb4ca6b..907bb7b08 100644 --- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -265,7 +265,7 @@ - + @@ -570,6 +570,7 @@ + diff --git a/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs b/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs index fa6d8a914..73ce4ab4e 100644 --- a/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs +++ b/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs @@ -9,6 +9,7 @@ using NzbDrone.Common.Cache; using NzbDrone.Common.Disk; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Extensions; +using NzbDrone.Common.Instrumentation; using NzbDrone.Core.Authentication; using NzbDrone.Core.Configuration.Events; using NzbDrone.Core.Lifecycle; @@ -154,7 +155,7 @@ namespace NzbDrone.Core.Configuration SetValue("AuthenticationMethod", AuthenticationType.Basic); return AuthenticationType.Basic; } - + return GetValueEnum("AuthenticationMethod", AuthenticationType.None); } } @@ -188,7 +189,7 @@ namespace NzbDrone.Core.Configuration public UpdateMechanism UpdateMechanism => GetValueEnum("UpdateMechanism", UpdateMechanism.BuiltIn, false); - public string UpdateScriptPath => GetValue("UpdateScriptPath", "", false ); + public string UpdateScriptPath => GetValue("UpdateScriptPath", "", false); public int GetValueInt(string key, int defaultValue) { @@ -344,6 +345,11 @@ namespace NzbDrone.Core.Configuration { EnsureDefaultConfigFile(); DeleteOldValues(); + + if (!AnalyticsEnabled) + { + NzbDroneLogger.UnRegisterRemoteLoggers(); + } } public void Execute(ResetApiKeyCommand message) diff --git a/src/NzbDrone.Update/UpdateApp.cs b/src/NzbDrone.Update/UpdateApp.cs index bad208032..98e259c9d 100644 --- a/src/NzbDrone.Update/UpdateApp.cs +++ b/src/NzbDrone.Update/UpdateApp.cs @@ -33,12 +33,12 @@ namespace NzbDrone.Update SecurityProtocolPolicy.Register(); X509CertificateValidationPolicy.Register(); - var startupArgument = new StartupContext(args); - NzbDroneLogger.Register(startupArgument, true, true); + var startupContext = new StartupContext(args); + NzbDroneLogger.Register(startupContext, true, true); Logger.Info("Starting Sonarr Update Client"); - _container = UpdateContainerBuilder.Build(startupArgument); + _container = UpdateContainerBuilder.Build(startupContext); _container.Resolve().Start(args);