From b69304992f57845dfbb66eb8bf7740531284e5b3 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 3 Jun 2019 12:52:46 -0400 Subject: [PATCH] log service --- src/Android/Android.csproj | 1 + src/Android/MainApplication.cs | 1 + src/Android/Services/AndroidLogService.cs | 30 +++++++++++++++++++++++ src/Core/Abstractions/ILogService.cs | 10 ++++++++ src/Core/Services/ConsoleLogService.cs | 28 +++++++++++++++++++++ 5 files changed, 70 insertions(+) create mode 100644 src/Android/Services/AndroidLogService.cs create mode 100644 src/Core/Abstractions/ILogService.cs create mode 100644 src/Core/Services/ConsoleLogService.cs diff --git a/src/Android/Android.csproj b/src/Android/Android.csproj index b1bab252d..6b258c886 100644 --- a/src/Android/Android.csproj +++ b/src/Android/Android.csproj @@ -125,6 +125,7 @@ + diff --git a/src/Android/MainApplication.cs b/src/Android/MainApplication.cs index a25d66a5e..9bf4153a5 100644 --- a/src/Android/MainApplication.cs +++ b/src/Android/MainApplication.cs @@ -48,6 +48,7 @@ namespace Bit.Droid private void RegisterLocalServices() { + ServiceContainer.Register("logService", new AndroidLogService()); ServiceContainer.Register("settingsShim", new App.Migration.SettingsShim()); if(App.Migration.MigrationHelpers.NeedsMigration()) { diff --git a/src/Android/Services/AndroidLogService.cs b/src/Android/Services/AndroidLogService.cs new file mode 100644 index 000000000..ead61510d --- /dev/null +++ b/src/Android/Services/AndroidLogService.cs @@ -0,0 +1,30 @@ +using Bit.Core.Abstractions; +using System; + +namespace Bit.Core.Services +{ + public class AndroidLogService : ILogService + { + private static readonly string _tag = "BITWARDEN"; + + public void Debug(string message) + { + Android.Util.Log.WriteLine(Android.Util.LogPriority.Debug, _tag, message); + } + + public void Info(string message) + { + Android.Util.Log.WriteLine(Android.Util.LogPriority.Info, _tag, message); + } + + public void Warning(string message) + { + Android.Util.Log.WriteLine(Android.Util.LogPriority.Warn, _tag, message); + } + + public void Error(string message) + { + Android.Util.Log.WriteLine(Android.Util.LogPriority.Error, _tag, message); + } + } +} diff --git a/src/Core/Abstractions/ILogService.cs b/src/Core/Abstractions/ILogService.cs new file mode 100644 index 000000000..8af1a806a --- /dev/null +++ b/src/Core/Abstractions/ILogService.cs @@ -0,0 +1,10 @@ +namespace Bit.Core.Abstractions +{ + public interface ILogService + { + void Debug(string message); + void Error(string message); + void Info(string message); + void Warning(string message); + } +} \ No newline at end of file diff --git a/src/Core/Services/ConsoleLogService.cs b/src/Core/Services/ConsoleLogService.cs new file mode 100644 index 000000000..baa292f76 --- /dev/null +++ b/src/Core/Services/ConsoleLogService.cs @@ -0,0 +1,28 @@ +using Bit.Core.Abstractions; +using System; + +namespace Bit.Core.Services +{ + public class ConsoleLogService : ILogService + { + public void Debug(string message) + { + Console.WriteLine("DEBUG: {0}", message); + } + + public void Info(string message) + { + Console.WriteLine("INFO: {0}", message); + } + + public void Warning(string message) + { + Console.WriteLine("WARNING: {0}", message); + } + + public void Error(string message) + { + Console.WriteLine("ERROR: {0}", message); + } + } +}