62 static void (*
hook_func)(int,
const char *,
void *) = NULL;
67 #define TIMEFORMAT_LEN 50
81 #define MAX_MASK_NAMES 35
130 #if YAZ_POSIX_THREADS
133 env = getenv(
"YAZ_LOG");
198 for (i = 0; i<9; i++)
200 char fname_str[FILENAME_MAX];
201 struct stat stat_buf;
203 yaz_snprintf(fname_str,
sizeof(fname_str),
"%s.%d", cur_fname, i);
204 if (stat(fname_str, &stat_buf) != 0)
209 char fname_str[2][FILENAME_MAX];
213 "%s.%d", cur_fname, i-1);
218 "%s.%d", cur_fname, i);
220 MoveFileEx(fname_str[0], fname_str[1], MOVEFILE_REPLACE_EXISTING);
222 rename(fname_str[0], fname_str[1]);
241 const char *bittype =
"Static ";
250 for (i = 0; i < sz; i++)
265 if (prefix && *prefix)
274 if (prefix && *prefix)
318 char new_filename[512];
319 static char cur_filename[512] =
"";
331 strftime(new_filename,
sizeof(new_filename)-1,
yaz_log_info.l_fname,
333 if (strcmp(new_filename, cur_filename))
335 strcpy(cur_filename, new_filename);
349 if (force && *cur_filename)
355 if (!strncmp(cur_filename,
"fd=", 3))
356 new_file = fdopen(atoi(cur_filename + 3), filemode);
358 new_file = fopen(cur_filename, filemode);
374 time_t cur_time = time(0);
376 struct tm tm0, *tm = &tm0;
383 localtime_r(&cur_time, tm);
385 tm = localtime(&cur_time);
407 const char *fmt,
const struct tm *tm)
409 strftime(dst, sz, fmt, tm);
413 const char *error_cp)
418 struct tm tm0, *tm = &tm0;
425 localtime_r(&ti, tm);
475 fprintf(file,
"%s%s%s%s %s", tbuf,
yaz_log_info.l_prefix,
477 vfprintf(file, fmt, ap);
479 fprintf(file,
" [%s]", error_cp);
492 char *error_cp = 0, error_buf[128];
497 error_cp = error_buf;
510 if (strlen(buf) >=
sizeof(buf)-31)
511 strcat(buf,
" [rest of output omitted]");
536 if (0==strcmp(fmt,
"old"))
548 static char *
clean_name(
const char *
name,
size_t len,
char *namebuf,
size_t buflen)
551 char *start = namebuf;
554 strncpy(namebuf,
name, len);
556 while ((p = strchr(start,
'/')))
558 if ((p = strrchr(start,
'.')))
621 for (p = str; *p && *p !=
','; p++)
635 char *n =
clean_name(str, (
size_t) (p - str), clean,
sizeof(clean));
void yaz_strerror(char *buf, size_t bufsz)
returns system error description string
Header for errno utilities.
void yaz_init_globals(void)
void yaz_log_set_handler(void(*func)(int, const char *, void *), void *info)
sets custom log handler
static void yaz_log_to_file(int level, const char *fmt, va_list ap, const char *error_cp)
FILE * yaz_log_file(void)
returns FILE handle for log or NULL if no file is in use
static void(* end_hook_func)(int, const char *, void *)
void yaz_log_init_prefix(const char *prefix)
sets log message prefix
void yaz_log_init_globals(void)
static unsigned int next_log_bit
static struct @4 mask_names[MAX_MASK_NAMES]
int yaz_log_mask_str(const char *str)
converts log level string to log level (integer)
void yaz_log_init_max_size(int mx)
sets limit in bytes for size for log file
void log_event_start(void(*func)(int, const char *, void *), void *info)
void yaz_log_init_prefix2(const char *prefix)
sets second log message prefix
static void(* start_hook_func)(int, const char *, void *)
void yaz_log_init_level(int level)
sets log level
static void yaz_strftime(char *dst, size_t sz, const char *fmt, const struct tm *tm)
static void * end_hook_info
static char l_custom_format[TIMEFORMAT_LEN]
void yaz_log_reopen()
reopen current log file (unless disabled or stderr)
void yaz_log_init(int level, const char *prefix, const char *fname)
sets level, prefix and filename for logging
static char * l_actual_format
static YAZ_MUTEX log_mutex
void yaz_log_deinit_globals(void)
static char * clean_name(const char *name, size_t len, char *namebuf, size_t buflen)
static int yaz_log_reopen_flag
static char l_old_default_format[]
static int define_module_bit(const char *name)
static void(* hook_func)(int, const char *, void *)
static void * start_hook_info
static void yaz_log_do_reopen(const char *filemode)
void yaz_log_lock(void)
Lock for YAZ log writes.
void yaz_log_time_format(const char *fmt)
sets time format for log mesages
static void yaz_log_open_check(struct tm *tm, int force, const char *filemode)
void yaz_log(int level, const char *fmt,...)
Writes log message.
static void rotate_log(const char *cur_fname)
void yaz_log_init_file(const char *fname)
sets log file
void yaz_log_trunc()
Truncate the log file.
void yaz_log_unlock(void)
Unlock for YAZ log writes.
int yaz_log_mask_str_x(const char *str, int level)
converts log level string to log level with "start" level
static char l_new_default_format[]
int yaz_log_module_level(const char *name)
returns level for module
static void yaz_log_open(void)
void log_event_end(void(*func)(int, const char *, void *), void *info)
#define YLOG_APP2
log level: application 2
#define YLOG_WARN
log level: warning
#define YLOG_FATAL
log level: fatal
#define YLOG_MALLOC
log level: malloc debug
#define YLOG_ERRNO
log level: append system error message
#define YLOG_FLUSH
log level: flush
#define YLOG_DEFAULT_LEVEL
default log level
#define YLOG_DEBUG
log level: debugging
#define YLOG_APP
log level: application
#define YLOG_NOTIME
log level: do not output date and time
#define YLOG_TID
log level: append thread Id
#define YLOG_LOGLVL
dynamic log level start
#define YLOG_LOG
log level: log (regular)
#define YLOG_APP3
log level: application 3
#define YLOG_LAST_BIT
last bit for regular log bits . Rest are dynamic
void yaz_mutex_leave(YAZ_MUTEX p)
leave critical section / AKA unlock
void yaz_mutex_enter(YAZ_MUTEX p)
enter critical section / AKA lock
void yaz_mutex_create(YAZ_MUTEX *p)
create MUTEX
void yaz_mutex_destroy(YAZ_MUTEX *p)
destroy MUTEX
Header for Mutex functions.
void yaz_vsnprintf(char *buf, size_t size, const char *fmt, va_list ap)
void yaz_snprintf(char *buf, size_t size, const char *fmt,...)
Header for config file reading utilities.
void yaz_thread_id_cstr(char *buf, size_t buf_max)
format current thread as printable C-string
Header for Mutex functions.
Header for memory handling functions.
Header for YAZ iconv interface.
Header with fundamental macros.