kinetic-c  v0.12.0
Seagate Kinetic Protocol Client Library for C
kinetic_logger.h
Go to the documentation of this file.
1 /*
2 * kinetic-c
3 * Copyright (C) 2015 Seagate Technology.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20 
21 #ifndef _KINETIC_LOGGER_H
22 #define _KINETIC_LOGGER_H
23 
24 #include "kinetic_types_internal.h"
25 #include "kinetic.pb-c.h"
26 #include <stdarg.h>
27 
28 #define KINETIC_LOGGER_DISABLED false
29 #define KINETIC_LOGGER_FLUSH_THREAD_ENABLED false
30 #define KINETIC_LOGGER_LOG_SEQUENCE_ID true
31 #define KINETIC_LOG_FILE "kinetic.log"
32 
33 void KineticLogger_Init(const char* logFile, int log_level);
34 void KineticLogger_Close(void);
35 void KineticLogger_Log(int log_level, const char* message);
36 void KineticLogger_LogPrintf(int log_level, const char* format, ...);
37 void KineticLogger_LogLocation(const char* filename, int line, const char * message);
38 void KineticLogger_LogHeader(int log_level, const KineticPDUHeader* header);
39 void KineticLogger_LogProtobuf(int log_level, const Com__Seagate__Kinetic__Proto__Message* msg);
40 void KineticLogger_LogStatus(int log_level, Com__Seagate__Kinetic__Proto__Command__Status* status);
41 void KineticLogger_LogByteArray(int log_level, const char* title, ByteArray bytes);
42 void KineticLogger_LogByteBuffer(int log_level, const char* title, ByteBuffer buffer);
43 
44 int KineticLogger_ByteArraySliceToCString(char* p_buf, const ByteArray bytes, const int start, const int count);
45 #define BYTES_TO_CSTRING(_buf_start, _array, _array_start, _count) { \
46  ByteArray __array = {.data = _array.data, .len = (_array).len}; \
47  KineticLogger_ByteArraySliceToCString((char*)(_buf_start), (__array), (_array_start), (_count)); \
48 }
49 
50 // #define LOG(message) KineticLogger_Log(2, message)
51 #if !KINETIC_LOGGER_DISABLED
52 
53 #define LOG0(message) KineticLogger_Log(0, message)
54 #define LOG1(message) KineticLogger_Log(1, message)
55 #define LOG2(message) KineticLogger_Log(2, message)
56 #define LOG3(message) KineticLogger_Log(3, message)
57 #define LOGF0(message, ...) KineticLogger_LogPrintf(0, message, __VA_ARGS__)
58 #define LOGF1(message, ...) KineticLogger_LogPrintf(1, message, __VA_ARGS__)
59 #define LOGF2(message, ...) KineticLogger_LogPrintf(2, message, __VA_ARGS__)
60 #define LOGF3(message, ...) KineticLogger_LogPrintf(3, message, __VA_ARGS__)
61 #define LOG_LOCATION KineticLogger_LogLocation(__FILE__, __LINE__, __func__);
62 #define KINETIC_ASSERT(cond) { \
63  if(!(cond)) \
64  { \
65  LOGF0("ASSERT FAILURE at %s:%d in %s: assert(" #cond ")", \
66  __FILE__, (int)__LINE__, __func__); \
67  assert(cond); \
68  } \
69  }
70 
71 #else
72 
73 #define LOG0(message)
74 #define LOG1(message)
75 #define LOG2(message)
76 #define LOG3(message)
77 #define LOGF0(message, ...)
78 #define LOGF1(message, ...)
79 #define LOGF2(message, ...)
80 #define LOGF3(message, ...)
81 #define LOG_LOCATION
82 #define KINETIC_ASSERT(cond)
83 
84 #endif
85 
86 #endif // _KINETIC_LOGGER_H
Structure for handling generic arrays of bytes.
Definition: byte_array.h:34
Structure for an embedded ByteArray as a buffer.
Definition: byte_array.h:53
void KineticLogger_Log(int log_level, const char *message)
void KineticLogger_LogByteBuffer(int log_level, const char *title, ByteBuffer buffer)
void KineticLogger_Close(void)
void KineticLogger_Init(const char *logFile, int log_level)
void KineticLogger_LogLocation(const char *filename, int line, const char *message)
int KineticLogger_ByteArraySliceToCString(char *p_buf, const ByteArray bytes, const int start, const int count)
void KineticLogger_LogByteArray(int log_level, const char *title, ByteArray bytes)
void KineticLogger_LogProtobuf(int log_level, const Com__Seagate__Kinetic__Proto__Message *msg)
void KineticLogger_LogHeader(int log_level, const KineticPDUHeader *header)
void KineticLogger_LogStatus(int log_level, Com__Seagate__Kinetic__Proto__Command__Status *status)
void KineticLogger_LogPrintf(int log_level, const char *format,...)