nx_storage_sdk  1.0
Storage 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 <sys/time.h>
11  #include <stdio.h>
12  #include <pthread.h>
13 
14  #define LOG(...) \
15  do { \
16  char ___buf[4096]; \
17  struct timeval ___tval; \
18  gettimeofday(&___tval, NULL); \
19  strftime(___buf, sizeof(___buf), "%H:%M:%S", localtime(&___tval.tv_sec)); \
20  sprintf(___buf + strlen(___buf), ".%06ld\t", ___tval.tv_usec); \
21  sprintf(___buf + strlen(___buf), "%ld\t", pthread_self()); \
22  snprintf(___buf + strlen(___buf), 4096 - strlen(___buf), __VA_ARGS__); \
23  fprintf(stdout, "%s\n", ___buf); \
24  fflush(stdout); \
25  } while (0)
26  #elif defined (_WIN32) || defined(__APPLE__)
27  #define LOG(...)
28  #endif
29 
30 #else
31  #define LOG(...)
32 #endif