From 863378d74efbf7e20791e4b9d006552e44691dae Mon Sep 17 00:00:00 2001 From: Kazuki Sakamoto Date: Wed, 9 Nov 2016 10:14:22 -0800 Subject: [PATCH] Sync Logger API Summary: - Sync Logger API with C implementation Reviewed By: emilsjolander Differential Revision: D4143019 fbshipit-source-id: f20203320bad5b8f4b9cce01a5b2e7c615a4d923 --- csharp/CSSLayout/CSSInterop.cpp | 7 ++----- csharp/CSSLayout/CSSInterop.h | 2 +- csharp/Facebook.CSSLayout/CSSLogLevel.cs | 20 ++++++++++++++++++++ csharp/Facebook.CSSLayout/CSSLogger.cs | 6 +++--- csharp/Facebook.CSSLayout/CSSNode.cs | 5 +++-- 5 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 csharp/Facebook.CSSLayout/CSSLogLevel.cs diff --git a/csharp/CSSLayout/CSSInterop.cpp b/csharp/CSSLayout/CSSInterop.cpp index 56c5597e..679d6544 100644 --- a/csharp/CSSLayout/CSSInterop.cpp +++ b/csharp/CSSLayout/CSSInterop.cpp @@ -11,15 +11,12 @@ static CSSInteropLoggerFunc gManagedFunc; -static int unmanagedLogger(const char *format, ...) { +static int unmanagedLogger(CSSLogLevel level, const char *format, va_list args) { int result = 0; if (gManagedFunc) { - va_list args; - va_start(args, format); char buffer[256]; result = vsnprintf(buffer, sizeof(buffer), format, args); - (*gManagedFunc)(buffer); - va_end(args); + (*gManagedFunc)(level, buffer); } return result; } diff --git a/csharp/CSSLayout/CSSInterop.h b/csharp/CSSLayout/CSSInterop.h index 7533cfd3..bbff6072 100644 --- a/csharp/CSSLayout/CSSInterop.h +++ b/csharp/CSSLayout/CSSInterop.h @@ -13,7 +13,7 @@ CSS_EXTERN_C_BEGIN -typedef void (*CSSInteropLoggerFunc)(const char *message); +typedef void (*CSSInteropLoggerFunc)(CSSLogLevel level, const char *message); WIN_EXPORT void CSSInteropSetLogger(CSSInteropLoggerFunc managedFunc); diff --git a/csharp/Facebook.CSSLayout/CSSLogLevel.cs b/csharp/Facebook.CSSLayout/CSSLogLevel.cs new file mode 100644 index 00000000..a0316b8d --- /dev/null +++ b/csharp/Facebook.CSSLayout/CSSLogLevel.cs @@ -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, + } +} diff --git a/csharp/Facebook.CSSLayout/CSSLogger.cs b/csharp/Facebook.CSSLayout/CSSLogger.cs index a5a95d0f..c6c4ae37 100644 --- a/csharp/Facebook.CSSLayout/CSSLogger.cs +++ b/csharp/Facebook.CSSLayout/CSSLogger.cs @@ -15,7 +15,7 @@ namespace Facebook.CSSLayout internal static class CSSLogger { [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void Func(string message); + public delegate void Func(CSSLogLevel level, string message); private static bool _initialized; private static Func _managedLogger = null; @@ -26,10 +26,10 @@ namespace Facebook.CSSLayout { if (!_initialized) { - _managedLogger = (message) => { + _managedLogger = (level, message) => { if (Logger != null) { - Logger(message); + Logger(level, message); } }; Native.CSSInteropSetLogger(_managedLogger); diff --git a/csharp/Facebook.CSSLayout/CSSNode.cs b/csharp/Facebook.CSSLayout/CSSNode.cs index b28114d5..6267001e 100644 --- a/csharp/Facebook.CSSLayout/CSSNode.cs +++ b/csharp/Facebook.CSSLayout/CSSNode.cs @@ -528,9 +528,10 @@ namespace Facebook.CSSLayout CSSPrintOptions.Layout|CSSPrintOptions.Style|CSSPrintOptions.Children) { 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); - CSSLogger.Logger = null; + CSSLogger.Logger = orig; return sb.ToString(); }