mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
committed by
Nick Mathewson
parent
98541f2892
commit
15e170e01b
+13
-2
@@ -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
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user