Add an option to overwrite logs

* Issue #5583
This commit is contained in:
Arlo Breault
2014-03-23 09:24:26 -07:00
committed by Nick Mathewson
parent 98541f2892
commit 15e170e01b
8 changed files with 52 additions and 9 deletions
+13 -2
View File
@@ -1010,12 +1010,16 @@ mark_logs_temp(void)
* logfile fails, -1 is returned and errno is set appropriately (by open(2)).
*/
int
add_file_log(const log_severity_list_t *severity, const char *filename)
add_file_log(const log_severity_list_t *severity, const char *filename,
const int truncate)
{
int fd;
logfile_t *lf;
fd = tor_open_cloexec(filename, O_WRONLY|O_CREAT|O_APPEND, 0644);
int open_flags = O_WRONLY|O_CREAT;
open_flags |= truncate ? O_TRUNC : O_APPEND;
fd = tor_open_cloexec(filename, open_flags, 0644);
if (fd<0)
return -1;
if (tor_fd_seekend(fd)<0) {
@@ -1297,3 +1301,10 @@ switch_logs_debug(void)
UNLOCK_LOGS();
}
/** Truncate all the log files. */
void
truncate_logs(void)
{
for (logfile_t *lf = logfiles; lf; lf = lf->next)
ftruncate(lf->fd, 0);
}
+3 -1
View File
@@ -130,7 +130,8 @@ void set_log_severity_config(int minSeverity, int maxSeverity,
log_severity_list_t *severity_out);
void add_stream_log(const log_severity_list_t *severity, const char *name,
int fd);
int add_file_log(const log_severity_list_t *severity, const char *filename);
int add_file_log(const log_severity_list_t *severity, const char *filename,
const int truncate);
#ifdef HAVE_SYSLOG_H
int add_syslog_log(const log_severity_list_t *severity);
#endif
@@ -148,6 +149,7 @@ void change_callback_log_severity(int loglevelMin, int loglevelMax,
void flush_pending_log_callbacks(void);
void log_set_application_name(const char *name);
void set_log_time_granularity(int granularity_msec);
void truncate_logs(void);
void tor_log(int severity, log_domain_mask_t domain, const char *format, ...)
CHECK_PRINTF(3,4);