Sync Logger API
Summary: - Sync Logger API with C implementation Reviewed By: emilsjolander Differential Revision: D4143019 fbshipit-source-id: f20203320bad5b8f4b9cce01a5b2e7c615a4d923
This commit is contained in:
committed by
Facebook Github Bot
parent
f1fcd5e382
commit
863378d74e
@@ -11,15 +11,12 @@
|
|||||||
|
|
||||||
static CSSInteropLoggerFunc gManagedFunc;
|
static CSSInteropLoggerFunc gManagedFunc;
|
||||||
|
|
||||||
static int unmanagedLogger(const char *format, ...) {
|
static int unmanagedLogger(CSSLogLevel level, const char *format, va_list args) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
if (gManagedFunc) {
|
if (gManagedFunc) {
|
||||||
va_list args;
|
|
||||||
va_start(args, format);
|
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
result = vsnprintf(buffer, sizeof(buffer), format, args);
|
result = vsnprintf(buffer, sizeof(buffer), format, args);
|
||||||
(*gManagedFunc)(buffer);
|
(*gManagedFunc)(level, buffer);
|
||||||
va_end(args);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
CSS_EXTERN_C_BEGIN
|
CSS_EXTERN_C_BEGIN
|
||||||
|
|
||||||
typedef void (*CSSInteropLoggerFunc)(const char *message);
|
typedef void (*CSSInteropLoggerFunc)(CSSLogLevel level, const char *message);
|
||||||
|
|
||||||
WIN_EXPORT void CSSInteropSetLogger(CSSInteropLoggerFunc managedFunc);
|
WIN_EXPORT void CSSInteropSetLogger(CSSInteropLoggerFunc managedFunc);
|
||||||
|
|
||||||
|
20
csharp/Facebook.CSSLayout/CSSLogLevel.cs
Normal file
20
csharp/Facebook.CSSLayout/CSSLogLevel.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2014-present, Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Facebook.CSSLayout
|
||||||
|
{
|
||||||
|
public enum CSSLogLevel
|
||||||
|
{
|
||||||
|
Error,
|
||||||
|
Warn,
|
||||||
|
Info,
|
||||||
|
Debug,
|
||||||
|
Verbose,
|
||||||
|
}
|
||||||
|
}
|
@@ -15,7 +15,7 @@ namespace Facebook.CSSLayout
|
|||||||
internal static class CSSLogger
|
internal static class CSSLogger
|
||||||
{
|
{
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
public delegate void Func(string message);
|
public delegate void Func(CSSLogLevel level, string message);
|
||||||
|
|
||||||
private static bool _initialized;
|
private static bool _initialized;
|
||||||
private static Func _managedLogger = null;
|
private static Func _managedLogger = null;
|
||||||
@@ -26,10 +26,10 @@ namespace Facebook.CSSLayout
|
|||||||
{
|
{
|
||||||
if (!_initialized)
|
if (!_initialized)
|
||||||
{
|
{
|
||||||
_managedLogger = (message) => {
|
_managedLogger = (level, message) => {
|
||||||
if (Logger != null)
|
if (Logger != null)
|
||||||
{
|
{
|
||||||
Logger(message);
|
Logger(level, message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Native.CSSInteropSetLogger(_managedLogger);
|
Native.CSSInteropSetLogger(_managedLogger);
|
||||||
|
@@ -528,9 +528,10 @@ namespace Facebook.CSSLayout
|
|||||||
CSSPrintOptions.Layout|CSSPrintOptions.Style|CSSPrintOptions.Children)
|
CSSPrintOptions.Layout|CSSPrintOptions.Style|CSSPrintOptions.Children)
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
CSSLogger.Logger = (message) => {sb.Append(message);};
|
CSSLogger.Func orig = CSSLogger.Logger;
|
||||||
|
CSSLogger.Logger = (level, message) => {sb.Append(message);};
|
||||||
Native.CSSNodePrint(_cssNode, options);
|
Native.CSSNodePrint(_cssNode, options);
|
||||||
CSSLogger.Logger = null;
|
CSSLogger.Logger = orig;
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user