odyssey/sources/logger.h

98 lines
2.4 KiB
C
Raw Normal View History

#ifndef ODYSSEY_LOGGER_H
#define ODYSSEY_LOGGER_H
2017-07-26 14:05:29 +00:00
/*
2018-03-12 14:03:15 +00:00
* Odyssey.
2017-07-26 14:05:29 +00:00
*
2018-04-04 13:19:58 +00:00
* Scalable PostgreSQL connection pooler.
*/
2017-07-26 14:05:29 +00:00
2021-02-18 22:26:40 +00:00
#define OD_LOGLINE_MAXLEN 1024
2017-07-26 14:05:29 +00:00
typedef struct od_logger od_logger_t;
typedef enum { OD_LOG, OD_ERROR, OD_DEBUG, OD_FATAL } od_logger_level_t;
2017-07-27 12:24:38 +00:00
struct od_logger {
od_pid_t *pid;
int log_debug;
int log_stdout;
int log_syslog;
char *format;
int format_len;
2021-02-18 22:26:40 +00:00
int fd;
2021-02-18 22:26:40 +00:00
int loaded;
int64_t machine;
/* makes sence only with use_asynclog option on */
machine_channel_t *task_channel;
2017-07-26 14:05:29 +00:00
};
2021-02-18 22:26:40 +00:00
extern od_retcode_t od_logger_init(od_logger_t *, od_pid_t *);
extern od_retcode_t od_logger_load(od_logger_t *logger);
2017-07-26 14:05:29 +00:00
static inline void od_logger_set_debug(od_logger_t *logger, int enable)
2017-07-26 14:05:29 +00:00
{
logger->log_debug = enable;
2017-07-26 14:05:29 +00:00
}
static inline void od_logger_set_stdout(od_logger_t *logger, int enable)
2017-07-26 14:05:29 +00:00
{
logger->log_stdout = enable;
2017-07-26 14:05:29 +00:00
}
static inline void od_logger_set_format(od_logger_t *logger, char *format)
2017-07-26 14:05:29 +00:00
{
logger->format = format;
logger->format_len = strlen(format);
2017-07-26 14:05:29 +00:00
}
2021-02-18 22:26:40 +00:00
extern int od_logger_open(od_logger_t *, char *);
extern int od_logger_reopen(od_logger_t *, char *);
extern int od_logger_open_syslog(od_logger_t *, char *, char *);
extern void od_logger_close(od_logger_t *);
extern void od_logger_write(od_logger_t *, od_logger_level_t, char *, void *,
void *, char *, va_list);
Enabled writing stats in Prometheus format. (#346) * Early implementation * Added description for gauges * Added prometheus lib finding to Cmake * Fixed FindProm comments * Small changes * free to prom_free * Moved metrics to separate file * Refactored & added new methods to prom_metrics * Refactored cron.c to use prom_metrics.h * Refactored CMake & odyssey.h * Added new metrics * Small refactoring * Small method renaming * Small fix in init * Added methods for use in od_cron_stats_cb * Small fixes * Refactored metrics to use separate collectors * Small fix * Passing metrics to od_cron_stat_cb now. * Removed unused imports * Removed old od_log calls * Removed TODO * Revert "Removed old od_log calls" This reverts commit 60000c8321e313e39bf5c63cf4715adc51401b89. * Uncommented od_log calls * Added processed clients field to metrics * Refactored metrics init * Fixed write_stat * Added method for worker stats * Added method for worker stat to metrics header file * Refactored worker stat method * Reverted changes in odyssey.h * Added writing metrics to od_worker * Added new method to logger Method provides writing big strings to log without formatting. * Fixed prometheus log writing * More fixes * Fixed log writing * Fixed log calls * Added TODO * Added assertion whether prom.h found * Fixed no format logger method Now logs follow log format * Fixed logger * Added log_stats_prom option to config * Renamed od_logger_write_no_fmt to od_logger_write_plain * Formatted * More ifdefs * Added memory deallocating in od_cron_stop * Updated configuration.md * Removed outdated TODO * Changed label * Formatted
2021-08-17 12:07:16 +00:00
extern void od_logger_write_plain(od_logger_t *, od_logger_level_t, char *,
void *, void *, char *);
2017-07-26 14:05:29 +00:00
static inline void od_log(od_logger_t *logger, char *context, void *client,
void *server, char *fmt, ...)
2017-07-26 14:05:29 +00:00
{
va_list args;
va_start(args, fmt);
od_logger_write(logger, OD_LOG, context, client, server, fmt, args);
2017-07-26 14:05:29 +00:00
va_end(args);
}
static inline void od_debug(od_logger_t *logger, char *context, void *client,
void *server, char *fmt, ...)
2017-07-26 14:05:29 +00:00
{
va_list args;
va_start(args, fmt);
od_logger_write(logger, OD_DEBUG, context, client, server, fmt, args);
2017-07-26 14:05:29 +00:00
va_end(args);
}
static inline void od_error(od_logger_t *logger, char *context, void *client,
void *server, char *fmt, ...)
2017-07-26 14:05:29 +00:00
{
va_list args;
va_start(args, fmt);
od_logger_write(logger, OD_ERROR, context, client, server, fmt, args);
2017-07-26 14:05:29 +00:00
va_end(args);
}
static inline void od_fatal(od_logger_t *logger, char *context, void *client,
void *server, char *fmt, ...)
2017-07-26 14:05:29 +00:00
{
va_list args;
va_start(args, fmt);
od_logger_write(logger, OD_FATAL, context, client, server, fmt, args);
2017-07-26 14:05:29 +00:00
va_end(args);
exit(1);
2017-07-26 14:05:29 +00:00
}
#endif /* ODYSSEY_LOGGER_H */