Skip to content

Commit cee2e01

Browse files
committed
[syncd] Start using MetadataLogger class
1 parent 22b6696 commit cee2e01

File tree

3 files changed

+6
-62
lines changed

3 files changed

+6
-62
lines changed

syncd/Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ endif
1616

1717
noinst_LIBRARIES = libsyncd.a
1818
libsyncd_a_SOURCES = \
19+
MetadataLogger.cpp \
1920
Workaround.cpp \
2021
Syncd.cpp \
2122
ServiceMethodTable.cpp \

syncd/Syncd.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919

2020
#define DEF_SAI_WARM_BOOT_DATA_FILE "/var/warmboot/sai-warmboot.bin"
2121

22-
// TODO mutex must be used in 3 places
22+
// TODO mutex must be used in 4 places
2323
// - notification processing
2424
// - main event loop processing
2525
// - syncd hard init when switches are created
2626
// (notifications could be sent during that)
27+
// - in case of exception when sending shutdown request
28+
// (other notifications can still arrive at this point)
2729

2830
#include "syncd.h" // TODO to be removed
2931

syncd/syncd.cpp

+2-61
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "Syncd.h"
1818
#include "RequestShutdown.h"
1919
#include "ComparisonLogic.h"
20+
#include "MetadataLogger.h"
2021

2122
#include "meta/sai_serialize.h"
2223

@@ -27,7 +28,6 @@
2728
#include "swss/table.h"
2829
#include "swss/redisapi.h"
2930

30-
3131
#include <inttypes.h>
3232
#include <limits.h>
3333

@@ -247,62 +247,6 @@ void set_sai_api_log_min_prio(const std::string &prioStr)
247247
}
248248
}
249249

250-
void sai_meta_log_syncd(
251-
_In_ sai_log_level_t log_level,
252-
_In_ const char *file,
253-
_In_ int line,
254-
_In_ const char *func,
255-
_In_ const char *format,
256-
...)
257-
__attribute__ ((format (printf, 5, 6)));
258-
259-
void sai_meta_log_syncd(
260-
_In_ sai_log_level_t log_level,
261-
_In_ const char *file,
262-
_In_ int line,
263-
_In_ const char *func,
264-
_In_ const char *format,
265-
...)
266-
{
267-
// SWSS_LOG_ENTER() is omitted since this is logging for metadata
268-
269-
char buffer[0x1000];
270-
271-
va_list ap;
272-
va_start(ap, format);
273-
vsnprintf(buffer, 0x1000, format, ap);
274-
va_end(ap);
275-
276-
swss::Logger::Priority p = swss::Logger::SWSS_NOTICE;
277-
278-
switch (log_level)
279-
{
280-
case SAI_LOG_LEVEL_DEBUG:
281-
p = swss::Logger::SWSS_DEBUG;
282-
break;
283-
case SAI_LOG_LEVEL_INFO:
284-
p = swss::Logger::SWSS_INFO;
285-
break;
286-
case SAI_LOG_LEVEL_ERROR:
287-
p = swss::Logger::SWSS_ERROR;
288-
fprintf(stderr, "ERROR: %s: %s", func, buffer);
289-
break;
290-
case SAI_LOG_LEVEL_WARN:
291-
p = swss::Logger::SWSS_WARN;
292-
fprintf(stderr, "WARN: %s: %s", func, buffer);
293-
break;
294-
case SAI_LOG_LEVEL_CRITICAL:
295-
p = swss::Logger::SWSS_CRIT;
296-
break;
297-
298-
default:
299-
p = swss::Logger::SWSS_NOTICE;
300-
break;
301-
}
302-
303-
swss::Logger::getInstance().write(p, ":- %s: %s", func, buffer);
304-
}
305-
306250
void timerWatchdogCallback(
307251
_In_ int64_t span)
308252
{
@@ -361,10 +305,7 @@ int syncd_main(int argc, char **argv)
361305

362306
g_handler->setSwitchNotifications(sn.getSwitchNotifications());
363307

364-
#pragma GCC diagnostic push
365-
#pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
366-
sai_metadata_log = &sai_meta_log_syncd;
367-
#pragma GCC diagnostic pop
308+
MetadataLogger::initialize();
368309

369310
// TODO move to syncd object
370311
g_commandLineOptions = CommandLineOptionsParser::parseCommandLine(argc, argv);

0 commit comments

Comments
 (0)