-
Notifications
You must be signed in to change notification settings - Fork 160
/
molten_log.h
145 lines (121 loc) · 3.6 KB
/
molten_log.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* Copyright 2017 chuan-yun silkcutKs <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MOLTEN_LOG_H
#define MOLTEN_LOG_H
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdint.h>
#include <limits.h>
#include <string.h>
#include <libgen.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>
#include <fcntl.h>
#include <time.h>
#include <sys/types.h>
# if defined(__linux__)
#include <linux/limits.h>
# endif
#ifdef HAS_CURL
#include "curl/curl.h"
#include "curl/easy.h"
#endif
#ifdef HAS_KAFKA
#include "librdkafka/rdkafka.h"
#endif
#include "php.h"
#include "Zend/zend_llist.h"
#include "molten_log.h"
#include "molten_util.h"
#include "php7_wrapper.h"
#include "molten_slog.h"
#ifndef PATH_MAX
#define PATH_MAX 4096
#endif
#define ALLOC_LOG_SIZE 1024
#define DEFAULT_LOG_DIR "/var/wd/log/tracing/php/"
#define DEFAULT_PREFIX "tracing"
#define LOG_FORMAT "%Y%m%d"
#define SINK_NONE 0
#define SINK_LOG 1
#define SINK_STD 2
#define SINK_SYSLOG 8 /* only for unx domain udp syslog */
#ifdef HAS_CURL
#define SINK_HTTP 4
#endif
#ifdef HAS_KAFKA
#define SINK_KAFKA 16
#endif
#define SPANS_WRAP 1<<0
#define SPANS_BREAK 1<<1
/* http sink */
/* current use php_stream or libcurl, we can check */
/* not use union, there has other fields */
typedef struct {
uint8_t type;
char *post_uri;
/*
struct {
php_stream_context *c;
php_stream *s;
} stream;
*/
} mo_http_sink_t;
/* chain log */
typedef struct {
uint8_t sink_type; /* log sink type */
uint8_t output_type; /* sink output type */
uint16_t support_type; /* sink support type */
char *host_name; /* link to global host name */
/* sink log file */
char *path;
char real_path[128]; /* log real path */
int tm_yday; /* day in year, get by ctime */
int fd;
ino_t ino;
char *format;
/* sink syslog */
char *unix_socket; /* unix domain udp syslog */
int sfd; /* unix domain syslog fd */
struct sockaddr_un server; /* server addr */
/* sink http */
char *post_uri; /* post uri */
/* kafka */
char *brokers; /* brokers */
char *topic; /* topic */
char *buf;
uint64_t total_size;
uint64_t alloc_size;
zval *spans;
} mo_chain_log_t;
/* function */
void mo_chain_log_init(mo_chain_log_t *log);
void mo_chain_log_ctor(mo_chain_log_t *log, char *host_name, char *log_path, long sink_type, long output_type, char *post_uri, char *syslog_unix_socket);
int mo_chain_log_set_file_path(char *new_path);
void mo_chain_log_add(mo_chain_log_t *log, char *buf, size_t size);
void mo_chain_log_flush(mo_chain_log_t *log);
void mo_chain_log_dtor(mo_chain_log_t *log);
void mo_chain_add_span(mo_chain_log_t *log, zval *span);
void mo_log_write(mo_chain_log_t *log, char *bytes, int size);
#ifdef HAS_CURL
void send_data_by_http(char *post_uri, char *post_data);
#endif
#endif