Commit 0512d524 authored by Michael Smith's avatar Michael Smith

Allow logging to go to stderr instead of to a file, if the user so chooses

(example configs turn this off, to leave behaviour as it was).

svn path=/trunk/log/; revision=3008
parent 34c62036
......@@ -69,29 +69,45 @@ void log_initialize()
_initialized = 1;
}
int log_open(const char *filename)
int log_open_file(FILE *file)
{
int log_id;
int log_id;
if (filename == NULL) return LOG_EINSANE;
if (strcmp(filename, "") == 0) return LOG_EINSANE;
if(file == NULL) return LOG_EINSANE;
log_id = _get_log_id();
if (log_id < 0) return LOG_ENOMORELOGS;
loglist[log_id].logfile = fopen(filename, "a");
loglist[log_id].logfile = file;
if (loglist[log_id].logfile != NULL) {
loglist[log_id].filename = (char *)strdup(filename);
loglist[log_id].filename = NULL;
} else {
_release_log_id(log_id);
return LOG_ECANTOPEN;
}
setvbuf(loglist[log_id].logfile, NULL, _IOLBF, 0);
return log_id;
}
int log_open(const char *filename)
{
int ret;
FILE *file;
if (filename == NULL) return LOG_EINSANE;
if (strcmp(filename, "") == 0) return LOG_EINSANE;
file = fopen(filename, "a");
ret = log_open_file(file);
if(ret >= 0)
setvbuf(file, NULL, _IOLBF, 0);
return ret;
}
int log_open_with_buffer(const char *filename, int size)
{
/* not implemented */
......
#ifndef __LOG_H__
#define __LOG_H__
#include <stdio.h>
#define LOG_EINSANE -1
#define LOG_ENOMORELOGS -2
#define LOG_ECANTOPEN -3
......@@ -9,6 +11,7 @@
void log_initialize();
int log_open_file(FILE *file);
int log_open(const char *filename);
int log_open_with_buffer(const char *filename, int size);
void log_set_level(int log_id, int level);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment