-
Notifications
You must be signed in to change notification settings - Fork 165
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
RNET-1161: Implement support for using a log level for a specific log category #3634
Changes from all commits
a4bf132
0f65081
7dfb380
b33aba1
a2fbca7
c0d9aa4
596e7f5
f4c9574
5f8cbf4
7e909c2
84535af
e728ff2
dc7af0a
dedf349
cc68acb
69bd809
2919b03
84e8733
5232577
d1977ee
c2dfcfa
b4dcaad
61f05a3
a86513c
461e090
b19f081
8fafa12
f09ae91
28455dd
7c91e71
e5a6a8e
40195c3
4eb128a
55f074d
66cdff5
b4efe05
c66bdf1
5307414
e7de88a
f2a938d
a3e3deb
db579ee
cf65350
c0b98fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
nirinchev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
@@ -48,6 +49,17 @@ internal class SharedRealmHandle : StandaloneHandle | |
|
||
private static class NativeMethods | ||
{ | ||
// This is a wrapper struct around MarshaledVector since P/Invoke doesn't like it | ||
// when the MarshaledVector is returned as the top-level return value from a native | ||
// function. This only manifests in .NET Framework and is not an issue with Mono/.NET. | ||
// The native return value is MarshaledVector without the wrapper because they are binary | ||
// compatible. | ||
[StructLayout(LayoutKind.Sequential)] | ||
public struct CategoryNamesContainer | ||
{ | ||
public MarshaledVector<StringValue> CategoryNames; | ||
} | ||
|
||
#pragma warning disable IDE0049 // Use built-in type alias | ||
#pragma warning disable SA1121 // Use built-in type alias | ||
|
||
|
@@ -64,7 +76,7 @@ private static class NativeMethods | |
public delegate void DisposeGCHandleCallback(IntPtr handle); | ||
|
||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | ||
public delegate void LogMessageCallback(StringValue message, LogLevel level); | ||
public delegate void LogMessageCallback(LogLevel level, StringValue categoryName, StringValue message); | ||
|
||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | ||
public delegate void HandleTaskCompletionCallback(IntPtr tcs_ptr, [MarshalAs(UnmanagedType.U1)] bool invoke_async, NativeException ex); | ||
|
@@ -223,8 +235,14 @@ public static extern void rename_property(SharedRealmHandle sharedRealm, | |
[DllImport(InteropConfig.DLL_NAME, EntryPoint = "shared_realm_refresh_async", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern bool refresh_async(SharedRealmHandle realm, IntPtr tcs_handle, out NativeException ex); | ||
|
||
[DllImport(InteropConfig.DLL_NAME, EntryPoint = "shared_realm_get_log_level", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern LogLevel get_log_level([MarshalAs(UnmanagedType.LPWStr)] string category_name, IntPtr category_name_len); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we're trying to go with using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My understanding here was that |
||
|
||
[DllImport(InteropConfig.DLL_NAME, EntryPoint = "shared_realm_set_log_level", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern bool set_log_level(LogLevel level); | ||
public static extern void set_log_level(LogLevel level, [MarshalAs(UnmanagedType.LPWStr)] string category_name, IntPtr category_name_len); | ||
|
||
[DllImport(InteropConfig.DLL_NAME, EntryPoint = "shared_realm_get_log_category_names", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern CategoryNamesContainer get_log_category_names(); | ||
|
||
[DllImport(InteropConfig.DLL_NAME, EntryPoint = "shared_realm_get_operating_system", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern IntPtr get_operating_system(IntPtr buffer, IntPtr buffer_length); | ||
|
@@ -271,7 +289,15 @@ public static unsafe void Initialize() | |
notifyObject, notifyDictionary, onMigration, shouldCompact, handleTaskCompletion, onInitialization); | ||
} | ||
|
||
public static void SetLogLevel(LogLevel level) => NativeMethods.set_log_level(level); | ||
public static LogLevel GetLogLevel(LogCategory category) => NativeMethods.get_log_level(category.Name, (IntPtr)category.Name.Length); | ||
|
||
public static void SetLogLevel(LogLevel level, LogCategory category) => NativeMethods.set_log_level(level, category.Name, (IntPtr)category.Name.Length); | ||
|
||
public static string[] GetLogCategoryNames() => NativeMethods.get_log_category_names() | ||
.CategoryNames | ||
.ToEnumerable() | ||
.Select(name => name.ToDotnetString()!) | ||
.ToArray(); | ||
|
||
[Preserve] | ||
protected SharedRealmHandle(IntPtr handle) : base(handle) | ||
|
@@ -822,9 +848,9 @@ private static void OnDisposeGCHandle(IntPtr handle) | |
} | ||
|
||
[MonoPInvokeCallback(typeof(NativeMethods.LogMessageCallback))] | ||
private static void LogMessage(StringValue message, LogLevel level) | ||
private static void LogMessage(LogLevel level, StringValue categoryName, StringValue message) | ||
{ | ||
Logger.LogDefault(level, message!); | ||
RealmLogger.Default.LogAnyLevel(level, LogCategory.FromName(categoryName!), message!); | ||
} | ||
|
||
[MonoPInvokeCallback(typeof(NativeMethods.MigrationCallback))] | ||
|
Check notice
Code scanning / CodeQL
Missing a summary in documentation comment Note