From 44355b6fa5c92a00f0d2fb33ba627a25f052664b Mon Sep 17 00:00:00 2001
From: Sean Hall <r.sean.hall@gmail.com>
Date: Wed, 1 Jul 2020 21:27:43 +1000
Subject: Add BalLogArgs and BalLogErrorArgs.

---
 src/balutil/balutil.cpp   | 50 +++++++++++++++++++++++++++++++++++++++++++----
 src/balutil/inc/balutil.h | 20 +++++++++++++++++++
 2 files changed, 66 insertions(+), 4 deletions(-)

diff --git a/src/balutil/balutil.cpp b/src/balutil/balutil.cpp
index df254359..7567752c 100644
--- a/src/balutil/balutil.cpp
+++ b/src/balutil/balutil.cpp
@@ -251,6 +251,29 @@ DAPIV_(HRESULT) BalLog(
 {
     HRESULT hr = S_OK;
     va_list args;
+
+    if (!vpEngine)
+    {
+        hr = E_POINTER;
+        ExitOnRootFailure(hr, "BalInitialize() must be called first.");
+    }
+
+    va_start(args, szFormat);
+    hr = BalLogArgs(level, szFormat, args);
+    va_end(args);
+
+LExit:
+    return hr;
+}
+
+
+DAPI_(HRESULT) BalLogArgs(
+    __in BOOTSTRAPPER_LOG_LEVEL level,
+    __in_z __format_string LPCSTR szFormat,
+    __in va_list args
+    )
+{
+    HRESULT hr = S_OK;
     LPSTR sczFormattedAnsi = NULL;
     LPWSTR sczMessage = NULL;
 
@@ -260,9 +283,7 @@ DAPIV_(HRESULT) BalLog(
         ExitOnRootFailure(hr, "BalInitialize() must be called first.");
     }
 
-    va_start(args, szFormat);
     hr = StrAnsiAllocFormattedArgs(&sczFormattedAnsi, szFormat, args);
-    va_end(args);
     ExitOnFailure(hr, "Failed to format log string.");
 
     hr = StrAllocStringAnsi(&sczMessage, sczFormattedAnsi, 0, CP_UTF8);
@@ -285,6 +306,29 @@ DAPIV_(HRESULT) BalLogError(
 {
     HRESULT hr = S_OK;
     va_list args;
+
+    if (!vpEngine)
+    {
+        hr = E_POINTER;
+        ExitOnRootFailure(hr, "BalInitialize() must be called first.");
+    }
+
+    va_start(args, szFormat);
+    hr = BalLogErrorArgs(hrError, szFormat, args);
+    va_end(args);
+
+LExit:
+    return hr;
+}
+
+
+DAPI_(HRESULT) BalLogErrorArgs(
+    __in HRESULT hrError,
+    __in_z __format_string LPCSTR szFormat,
+    __in va_list args
+    )
+{
+    HRESULT hr = S_OK;
     LPSTR sczFormattedAnsi = NULL;
     LPWSTR sczMessage = NULL;
 
@@ -294,9 +338,7 @@ DAPIV_(HRESULT) BalLogError(
         ExitOnRootFailure(hr, "BalInitialize() must be called first.");
     }
 
-    va_start(args, szFormat);
     hr = StrAnsiAllocFormattedArgs(&sczFormattedAnsi, szFormat, args);
-    va_end(args);
     ExitOnFailure(hr, "Failed to format error log string.");
 
     hr = StrAllocFormatted(&sczMessage, L"Error 0x%08x: %S", hrError, sczFormattedAnsi);
diff --git a/src/balutil/inc/balutil.h b/src/balutil/inc/balutil.h
index 68ef5a4d..e0f5874c 100644
--- a/src/balutil/inc/balutil.h
+++ b/src/balutil/inc/balutil.h
@@ -144,6 +144,16 @@ DAPIV_(HRESULT) BalLog(
     ...
     );
 
+/*******************************************************************
+ BalLogArgs - logs a message with the engine.
+
+********************************************************************/
+DAPI_(HRESULT) BalLogArgs(
+    __in BOOTSTRAPPER_LOG_LEVEL level,
+    __in_z __format_string LPCSTR szFormat,
+    __in va_list args
+    );
+
 /*******************************************************************
  BalLogError - logs an error message with the engine.
 
@@ -154,6 +164,16 @@ DAPIV_(HRESULT) BalLogError(
     ...
     );
 
+/*******************************************************************
+ BalLogErrorArgs - logs an error message with the engine.
+
+********************************************************************/
+DAPI_(HRESULT) BalLogErrorArgs(
+    __in HRESULT hr,
+    __in_z __format_string LPCSTR szFormat,
+    __in va_list args
+    );
+
 /*******************************************************************
 BalLogId - logs a message with the engine with a string embedded in a 
            MESSAGETABLE resource.
-- 
cgit v1.2.3-55-g6feb