mirror of
https://github.com/bitwarden/mobile
synced 2026-01-06 10:34:07 +00:00
BEEEP: Abstract and Centralize Logging (#1663)
* Abstracted App Center Logging into its own component, so that we can have it centralized in one place and we avoid checking for FDroid on all the places we want to use it * Implemented the new logger where Crashes.TrackError was being used except on some specific cases * Improved logging, added a debug logger and removed AppCenter to be used on DEBUG
This commit is contained in:
committed by
GitHub
parent
34d0ecf64b
commit
db7ca3b93e
50
src/Core/Services/Logging/DebugLogger.cs
Normal file
50
src/Core/Services/Logging/DebugLogger.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
#if !FDROID
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Bit.Core.Abstractions;
|
||||
|
||||
namespace Bit.Core.Services
|
||||
{
|
||||
public class DebugLogger : ILogger
|
||||
{
|
||||
static ILogger _instance;
|
||||
public static ILogger Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance is null)
|
||||
{
|
||||
_instance = new DebugLogger();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
protected DebugLogger()
|
||||
{
|
||||
}
|
||||
|
||||
public void Error(string message, IDictionary<string, string> extraData = null, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
|
||||
{
|
||||
var classAndMethod = $"{Path.GetFileNameWithoutExtension(sourceFilePath)}.{memberName}";
|
||||
var filePathAndLineNumber = $"{Path.GetFileName(sourceFilePath)}:{sourceLineNumber}";
|
||||
|
||||
if (string.IsNullOrEmpty(message))
|
||||
{
|
||||
Debug.WriteLine($"Error found in: {classAndMethod})");
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.WriteLine($"File: {filePathAndLineNumber}");
|
||||
Debug.WriteLine($"Method: {memberName}");
|
||||
Debug.WriteLine($"Message: {message}");
|
||||
|
||||
}
|
||||
|
||||
public void Exception(Exception ex) => Debug.WriteLine(ex);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user