Skip to content

Commit f535ef0

Browse files
author
Rob Walker
authored
add LogV (project-chip#944)
* add LogV * fixup * fixup
1 parent 7fafb68 commit f535ef0

File tree

8 files changed

+66
-32
lines changed

8 files changed

+66
-32
lines changed

src/crypto/tests/CHIPCryptoPALTest.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -784,11 +784,16 @@ static void TestECDH_SampleInputVectors(nlTestSuite * inSuite, void * inContext)
784784

785785
namespace chip {
786786
namespace Logging {
787+
void LogV(uint8_t module, uint8_t category, const char * format, va_list argptr)
788+
{
789+
(void) module, (void) category;
790+
vfprintf(stderr, format, argptr);
791+
}
787792
void Log(uint8_t module, uint8_t category, const char * format, ...)
788793
{
789794
va_list argptr;
790795
va_start(argptr, format);
791-
vfprintf(stderr, format, argptr);
796+
LogV(module, category, format, argptr);
792797
va_end(argptr);
793798
}
794799
} // namespace Logging

src/lib/core/tests/TestCHIPSecureChannel.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,16 @@ int TestCHIPSecureChannel()
236236

237237
namespace chip {
238238
namespace Logging {
239+
void LogV(uint8_t module, uint8_t category, const char * format, va_list argptr)
240+
{
241+
(void) module, (void) category;
242+
vfprintf(stderr, format, argptr);
243+
}
239244
void Log(uint8_t module, uint8_t category, const char * format, ...)
240245
{
241246
va_list argptr;
242247
va_start(argptr, format);
243-
vfprintf(stderr, format, argptr);
248+
LogV(module, category, format, argptr);
244249
va_end(argptr);
245250
}
246251
} // namespace Logging

src/lib/support/logging/CHIPLogging.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,8 @@ uint8_t gLogFilter = kLogCategory_Max;
190190
#define __CHIP_LOGGING_LINK_ATTRIBUTE
191191
#endif
192192

193-
DLL_EXPORT __CHIP_LOGGING_LINK_ATTRIBUTE void Log(uint8_t module, uint8_t category, const char * msg, ...)
193+
DLL_EXPORT __CHIP_LOGGING_LINK_ATTRIBUTE void LogV(uint8_t module, uint8_t category, const char * msg, va_list v)
194194
{
195-
va_list v;
196-
197-
va_start(v, msg);
198-
199195
if (IsCategoryEnabled(category))
200196
{
201197

@@ -220,6 +216,15 @@ DLL_EXPORT __CHIP_LOGGING_LINK_ATTRIBUTE void Log(uint8_t module, uint8_t catego
220216

221217
#endif /* CHIP_LOGGING_STYLE_ANDROID */
222218
}
219+
}
220+
221+
DLL_EXPORT __CHIP_LOGGING_LINK_ATTRIBUTE void Log(uint8_t module, uint8_t category, const char * msg, ...)
222+
{
223+
va_list v;
224+
225+
va_start(v, msg);
226+
227+
LogV(module, category, msg, v);
223228

224229
va_end(v);
225230
}

src/lib/support/logging/CHIPLogging.h

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
#include <core/CHIPConfig.h>
3939

40+
#include <stdarg.h>
4041
#include <stdint.h>
4142

4243
/**
@@ -106,6 +107,7 @@ enum LogModule
106107
kLogModule_EventLogging,
107108
kLogModule_Support,
108109
kLogModule_chipTool,
110+
kLogModule_Zcl,
109111

110112
kLogModule_Max
111113
};
@@ -184,6 +186,7 @@ enum LogCategory
184186
kLogCategory_Max = kLogCategory_Retain
185187
};
186188

189+
extern void LogV(uint8_t module, uint8_t category, const char * msg, va_list args);
187190
extern void Log(uint8_t module, uint8_t category, const char * msg, ...);
188191
extern uint8_t GetLogFilter(void);
189192
extern void SetLogFilter(uint8_t category);

src/platform/EFR32/Logging.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,10 @@ namespace chip {
161161
namespace Logging {
162162

163163
/**
164-
* CHIP log output function.
164+
* CHIP log output functions.
165165
*/
166-
void Log(uint8_t module, uint8_t category, const char * aFormat, ...)
166+
void LogV(uint8_t module, uint8_t category, const char * aFormat, va_list v)
167167
{
168-
va_list v;
169-
170-
va_start(v, aFormat);
171168
#if EFR32_LOG_ENABLED && _CHIP_USE_LOGGING
172169
if (IsCategoryEnabled(category))
173170
{
@@ -214,6 +211,14 @@ void Log(uint8_t module, uint8_t category, const char * aFormat, ...)
214211
// Let the application know that a log message has been emitted.
215212
DeviceLayer::OnLogOutput();
216213
#endif // EFR32_LOG_ENABLED && _CHIP_USE_LOGGING
214+
}
215+
216+
void Log(uint8_t module, uint8_t category, const char * aFormat, ...)
217+
{
218+
va_list v;
219+
220+
va_start(v, aFormat);
221+
LogV(module, category, aFormat, v);
217222
va_end(v);
218223
}
219224

src/platform/ESP32/Logging.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,8 @@ void GetModuleName(char * buf, uint8_t module)
5151
namespace chip {
5252
namespace Logging {
5353

54-
void Log(uint8_t module, uint8_t category, const char * msg, ...)
54+
void LogV(uint8_t module, uint8_t category, const char * msg, va_list v)
5555
{
56-
va_list v;
57-
58-
va_start(v, msg);
59-
6056
if (IsCategoryEnabled(category))
6157
{
6258
enum
@@ -91,9 +87,17 @@ void Log(uint8_t module, uint8_t category, const char * msg, ...)
9187
break;
9288
}
9389
}
90+
}
9491

92+
void Log(uint8_t module, uint8_t category, const char * msg, ...)
93+
{
94+
va_list v;
95+
96+
va_start(v, msg);
97+
LogV(module, category, msg, v);
9598
va_end(v);
9699
}
97100

98101
} // namespace Logging
102+
99103
} // namespace chip

src/platform/Linux/Logging.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,23 @@ namespace chip {
5555
namespace Logging {
5656

5757
/**
58-
* CHIP log output function.
58+
* CHIP log output functions.
5959
*/
60-
void Log(uint8_t module, uint8_t category, const char * msg, ...)
60+
void LogV(uint8_t module, uint8_t category, const char * msg, va_list v)
6161
{
62-
va_list v;
63-
va_start(v, msg);
64-
6562
if (IsCategoryEnabled(category))
6663
{
6764
vsyslog(LOG_INFO, msg, v);
6865

6966
// Let the application know that a log message has been emitted.
7067
DeviceLayer::OnLogOutput();
7168
}
72-
69+
}
70+
void Log(uint8_t module, uint8_t category, const char * msg, ...)
71+
{
72+
va_list v;
73+
va_start(v, msg);
74+
LogV(module, category, msg, v);
7375
va_end(v);
7476
}
7577

src/platform/nRF5/Logging.cpp

+14-9
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,11 @@ NRF_LOG_MODULE_REGISTER();
7878
namespace chip {
7979
namespace Logging {
8080

81-
/**
82-
* Openchip log output function.
83-
*/
84-
void Log(uint8_t module, uint8_t category, const char * msg, ...)
81+
void LogV(uint8_t module, uint8_t category, const char * msg, va_list v)
8582
{
86-
va_list v;
87-
8883
(void) module;
8984
(void) category;
9085

91-
va_start(v, msg);
92-
9386
#if NRF_LOG_ENABLED
9487

9588
if (IsCategoryEnabled(category))
@@ -131,9 +124,21 @@ void Log(uint8_t module, uint8_t category, const char * msg, ...)
131124
// Let the application know that a log message has been emitted.
132125
DeviceLayer::OnLogOutput();
133126
}
134-
127+
#else // NRF_LOG_ENABLED
128+
(void) msg;
129+
(void) v;
135130
#endif // NRF_LOG_ENABLED
131+
}
136132

133+
/**
134+
* Openchip log output function.
135+
*/
136+
void Log(uint8_t module, uint8_t category, const char * msg, ...)
137+
{
138+
va_list v;
139+
140+
va_start(v, msg);
141+
LogV(module, category, msg, v);
137142
va_end(v);
138143
}
139144

0 commit comments

Comments
 (0)