Ziti C SDK
Loading...
Searching...
No Matches
ziti_log.h
Go to the documentation of this file.
1// Copyright (c) 2022-2023. NetFoundry Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//
16// Created by eugene on 4/15/2020.
17//
18
19#ifndef ZITI_SDK_ZITI_LOG_H
20#define ZITI_SDK_ZITI_LOG_H
21
22#include <uv.h>
23
24#include "externs.h"
25
26#ifdef SOURCE_PATH_SIZE
27#define __FILENAME__ (&__FILE__[SOURCE_PATH_SIZE])
28#else
29#define __FILENAME__ __FILE__
30#endif
31
32#ifndef ZITI_LOG_PREFIX
33#define ZITI_LOG_PREFIX
34#endif
35
36#define _to_str(x) #x
37#define to_str(x) _to_str(x)
38// for windows compilation NOGDI needs to be set:
39// right click ziti -> properties -> C/C++ -> Preprocessor - ensure NOGDI is in the list of preprocessor definitions
40// if it's not present check the CMakeLists.txt file
41#define DEBUG_LEVELS(XX) \
42 XX(NONE) \
43 XX(ERROR) /*WINDOWS - see comment above wrt NOGDI*/ \
44 XX(WARN) \
45 XX(INFO) \
46 XX(DEBUG) \
47 XX(VERBOSE) \
48 XX(TRACE)
49
51#define _level(n) n,
53#undef _level
54};
55
56#ifndef ZITI_LOG_MODULE
57#define ZITI_LOG_MODULE NULL
58#endif
59
60#define ZITI_LOG(level, fmt, ...) do { \
61if (level <= ziti_log_level(ZITI_LOG_MODULE, __FILENAME__)) { ziti_logger(level, ZITI_LOG_MODULE, __FILENAME__, __LINE__, __func__, fmt, ##__VA_ARGS__); }\
62} while(0)
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68#if _MSC_VER >= 1400
69# include <sal.h>
70# if _MSC_VER > 1400
71# define FORMAT_STRING(p) _Printf_format_string_ p
72# else
73# define FORMAT_STRING(p) __format_string p
74# endif /* FORMAT_STRING */
75#else
76# define FORMAT_STRING(p) p
77#endif /* _MSC_VER */
78
79#ifdef __GNUC__
80#define ziti_printf_args(a, b) __attribute__((__format__ (printf,a,b)))
81#else
82#define ziti_printf_args(a,b)
83#endif
84
85#define ZITI_LOG_DEFAULT_LEVEL (-1)
86
87typedef void (*log_writer)(int level, const char *loc, const char *msg, size_t msglen);
88
89ZITI_FUNC extern void
90ziti_logger(int level, const char *module, const char *file, unsigned int line, const char *func,
91 FORMAT_STRING(const char *fmt), ...)
93
94// call once
95// use ZITI_LOG_DEFAULT_LEVEL to use default(INFO)/ZITI_LOG env var
96// pass logger = NULL to use default output
97ZITI_FUNC extern void ziti_log_init(uv_loop_t *loop, int level, log_writer logger);
98
100
101// use ZITI_LOG_DEFAULT_LEVEL to reset to default(INFO) or ZITI_LOG env var
102ZITI_FUNC extern void ziti_log_set_level(int level, const char *marker);
103
104// don't use directly
105ZITI_FUNC extern int ziti_log_level(const char *module, const char *file);
106
107ZITI_FUNC extern void ziti_log_set_level_by_label(const char *log_level);
108
109ZITI_FUNC extern const char *ziti_log_level_label();
110
115ZITI_FUNC void tlsuv_logger(int level, const char *file, unsigned int line, const char *msg);
116
117#ifdef __cplusplus
118}
119#endif
120#endif //ZITI_SDK_ZITI_LOG_H
#define ZITI_FUNC
Definition externs.h:38
void ziti_log_set_level(int level, const char *marker)
#define _level(n)
Definition ziti_log.h:51
#define FORMAT_STRING(p)
Definition ziti_log.h:76
void ziti_log_init(uv_loop_t *loop, int level, log_writer logger)
void ziti_logger(int level, const char *module, const char *file, unsigned int line, const char *func, const char *fmt,...)
#define DEBUG_LEVELS(XX)
Definition ziti_log.h:41
void tlsuv_logger(int level, const char *file, unsigned int line, const char *msg)
can be used to turn on logging of uv-mbed library and send log messages into the ziti_log Usage: uv_m...
void ziti_log_set_logger(log_writer logger)
const char * ziti_log_level_label()
#define ziti_printf_args(a, b)
Definition ziti_log.h:82
void ziti_log_set_level_by_label(const char *log_level)
DebugLevel
Definition ziti_log.h:50
void(* log_writer)(int level, const char *loc, const char *msg, size_t msglen)
Definition ziti_log.h:87
int ziti_log_level(const char *module, const char *file)