Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 53 lines (42 sloc) 1.32 kb
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
/*
* moxi logging API
* mtaneja@zynga.com
*/

#ifndef _LOG_H_
#define _LOG_H_

#include <errno.h>
#include <string.h>

/*
* define the log levels
*/
#define MOXI_LOG_CRIT 1
#define MOXI_LOG_ERR 5
#define MOXI_LOG_INFO 10
#define MOXI_LOG_DEBUG 15

#define ERRORLOG_STDERR 0x1
#define ERRORLOG_FILE 0x2
#define ERRORLOG_SYSLOG 0x4

struct moxi_log {
    int fd; /* log fd */
    int log_level; /* logging level. default 5 */
    int log_mode; /* syslog, log file, stderr */
    char *log_ident; /* syslog identifier */
    char *log_file; /* if log file is specified */
    int use_syslog; /* set if syslog is being used */
    time_t cur_ts; /* current timestamp */
    time_t last_generated_debug_ts;
};

typedef struct moxi_log moxi_log;

int log_error_open(moxi_log *);
int log_error_close(moxi_log *);
int log_error_write(moxi_log *, const char *filename, unsigned int line, const char *fmt, ...);
int log_error_cycle(moxi_log *);

#ifndef MAIN_CHECK
extern moxi_log *ml;
#define moxi_log_write(...) log_error_write(ml, __FILE__, __LINE__, __VA_ARGS__)
#else
#define moxi_log_write(...) fprintf(stderr, __VA_ARGS__)
#endif

#undef perror
#define perror(str) log_error_write(ml, __FILE__, __LINE__, str, ": %s", strerror(errno));

#endif
Something went wrong with that request. Please try again.