nx_server_plugin_sdk 1.0 Server Plugin SDK

log.h
1 // Copyright 2018-present Network Optix, Inc. Licensed under MPL 2.0: www.mozilla.org/MPL/2.0/
2
3 #pragma once
4
5 #define TEST_PLUGIN_LOG
6
7 #if defined(TEST_PLUGIN_LOG)
8
9 #if defined(__linux__)
10 #include <pthread.h>
11 #include <stdio.h>
12
13 #include <sys/time.h>
14
15 #define LOG(...) \
16 do \
17 { \
18 char ___buf[4096]; \
19 struct timeval ___tval; \
20 gettimeofday(&___tval, NULL); \
21 strftime(___buf, sizeof(___buf), "%H:%M:%S", localtime(&___tval.tv_sec)); \
22 sprintf(___buf + strlen(___buf), ".%06ld\t", ___tval.tv_usec); \
23 sprintf(___buf + strlen(___buf), "%ld\t", pthread_self()); \
24 snprintf(___buf + strlen(___buf), 4096 - strlen(___buf), __VA_ARGS__); \
25 fprintf(stdout, "%s\n", ___buf); \
26 fflush(stdout); \
27 } while (0)
28 #elif defined (_WIN32) || defined(__APPLE__)
29 #define LOG(...)
30 #endif
31
32 #else
33 #define LOG(...)
34 #endif