Make time optional when logging to file, set to false for STDERR.

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@2775 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
1997-08-08 02:23:06 +00:00
parent a2fb5946f1
commit 4ed0dc72f5

View File

@@ -203,6 +203,7 @@ struct file_data{
char *filename; char *filename;
char *mode; char *mode;
FILE *fd; FILE *fd;
int log_time;
int keep_open; int keep_open;
}; };
@@ -214,7 +215,10 @@ log_file(const char *time,
struct file_data *f = data; struct file_data *f = data;
if(f->keep_open == 0) if(f->keep_open == 0)
f->fd = fopen(f->filename, f->mode); f->fd = fopen(f->filename, f->mode);
if(f->log_time)
fprintf(f->fd, "%s %s\n", time, msg); fprintf(f->fd, "%s %s\n", time, msg);
else
fprintf(f->fd, "%s\n", msg);
if(f->keep_open == 0) if(f->keep_open == 0)
fclose(f->fd); fclose(f->fd);
} }
@@ -230,7 +234,7 @@ close_file(void *data)
static krb5_error_code static krb5_error_code
open_file(krb5_context context, krb5_log_facility *fac, int min, int max, open_file(krb5_context context, krb5_log_facility *fac, int min, int max,
char *filename, char *mode, FILE *f, int keep_open) char *filename, char *mode, FILE *f, int log_time, int keep_open)
{ {
struct file_data *fd = malloc(sizeof(*fd)); struct file_data *fd = malloc(sizeof(*fd));
if(fd == NULL) if(fd == NULL)
@@ -238,6 +242,7 @@ open_file(krb5_context context, krb5_log_facility *fac, int min, int max,
fd->filename = filename; fd->filename = filename;
fd->mode = mode; fd->mode = mode;
fd->fd = f; fd->fd = f;
fd->log_time = log_time;
fd->keep_open = keep_open; fd->keep_open = keep_open;
return krb5_addlog_func(context, fac, min, max, log_file, close_file, fd); return krb5_addlog_func(context, fac, min, max, log_file, close_file, fd);
@@ -267,9 +272,9 @@ krb5_addlog_dest(krb5_context context, krb5_log_facility *f, const char *p)
p++; p++;
} }
if(strcmp(p, "STDERR") == 0){ if(strcmp(p, "STDERR") == 0){
ret = open_file(context, f, min, max, NULL, NULL, stderr, 1); ret = open_file(context, f, min, max, NULL, NULL, stderr, 0, 1);
}else if(strcmp(p, "CONSOLE") == 0){ }else if(strcmp(p, "CONSOLE") == 0){
ret = open_file(context, f, min, max, "/dev/console", "w", NULL, 0); ret = open_file(context, f, min, max, "/dev/console", "w", NULL, 1, 0);
}else if(strncmp(p, "FILE:", 4) == 0 && (p[4] == ':' || p[4] == '=')){ }else if(strncmp(p, "FILE:", 4) == 0 && (p[4] == ':' || p[4] == '=')){
char *fn; char *fn;
FILE *file = NULL; FILE *file = NULL;
@@ -289,9 +294,9 @@ krb5_addlog_dest(krb5_context context, krb5_log_facility *f, const char *p)
} }
keep_open = 1; keep_open = 1;
} }
ret = open_file(context, f, min, max, fn, "a", file, keep_open); ret = open_file(context, f, min, max, fn, "a", file, 1, keep_open);
}else if(strncmp(p, "DEVICE=", 6) == 0){ }else if(strncmp(p, "DEVICE=", 6) == 0){
ret = open_file(context, f, min, max, strdup(p + 7), "w", NULL, 0); ret = open_file(context, f, min, max, strdup(p + 7), "w", NULL, 1, 0);
}else if(strncmp(p, "SYSLOG", 6) == 0){ }else if(strncmp(p, "SYSLOG", 6) == 0){
char *severity; char *severity;
char *facility; char *facility;
@@ -355,7 +360,6 @@ krb5_closelog(krb5_context context,
return 0; return 0;
} }
krb5_error_code krb5_error_code
krb5_vlog_msg(krb5_context context, krb5_vlog_msg(krb5_context context,
krb5_log_facility *fac, krb5_log_facility *fac,