mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Merge branch 'win_log' of https://github.com/MovingtoMars/toxcore
This commit is contained in:
commit
bf12a4d1a6
|
@ -1,6 +1,6 @@
|
||||||
/* logger.c
|
/* logger.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013 Tox project All Rights Reserved.
|
* Copyright (C) 2013, 2015 Tox project All Rights Reserved.
|
||||||
*
|
*
|
||||||
* This file is part of Tox.
|
* This file is part of Tox.
|
||||||
*
|
*
|
||||||
|
@ -37,8 +37,10 @@
|
||||||
#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
|
#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
|
||||||
# define getpid() ((unsigned) GetCurrentProcessId())
|
# define getpid() ((unsigned) GetCurrentProcessId())
|
||||||
# define SFILE(FILE__M) (strrchr(FILE__M, '\\') ? strrchr(FILE__M, '\\') + 1 : FILE__M)
|
# define SFILE(FILE__M) (strrchr(FILE__M, '\\') ? strrchr(FILE__M, '\\') + 1 : FILE__M)
|
||||||
|
# define WIN_CR "\r"
|
||||||
#else
|
#else
|
||||||
# define SFILE(FILE__M) (strrchr(FILE__M, '/') ? strrchr(FILE__M, '/') + 1 : FILE__M)
|
# define SFILE(FILE__M) (strrchr(FILE__M, '/') ? strrchr(FILE__M, '/') + 1 : FILE__M)
|
||||||
|
# define WIN_CR ""
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -100,7 +102,7 @@ Logger *logger_new (const char *file_name, LOG_LEVEL level, const char *id)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(retu->log_file = fopen(file_name, "ab"))) {
|
if (!(retu->log_file = fopen(file_name, "ab"))) {
|
||||||
fprintf(stderr, "Error opening logger file: %s; info: %s\n", file_name, strerror(errno));
|
fprintf(stderr, "Error opening logger file: %s; info: %s" WIN_CR "\n", file_name, strerror(errno));
|
||||||
free(retu);
|
free(retu);
|
||||||
pthread_mutex_destroy(retu->mutex);
|
pthread_mutex_destroy(retu->mutex);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -126,13 +128,13 @@ Logger *logger_new (const char *file_name, LOG_LEVEL level, const char *id)
|
||||||
retu->level = level;
|
retu->level = level;
|
||||||
retu->start_time = current_time_monotonic();
|
retu->start_time = current_time_monotonic();
|
||||||
|
|
||||||
fprintf(retu->log_file, "Successfully created and running logger id: %s; time: %s\n",
|
fprintf(retu->log_file, "Successfully created and running logger id: %s; time: %s" WIN_CR "\n",
|
||||||
retu->id, strtime(retu->tstr, 16));
|
retu->id, strtime(retu->tstr, 16));
|
||||||
|
|
||||||
return retu;
|
return retu;
|
||||||
|
|
||||||
FAILURE:
|
FAILURE:
|
||||||
fprintf(stderr, "Failed to create logger!\n");
|
fprintf(stderr, "Failed to create logger!" WIN_CR "\n");
|
||||||
pthread_mutex_destroy(retu->mutex);
|
pthread_mutex_destroy(retu->mutex);
|
||||||
fclose(retu->log_file);
|
fclose(retu->log_file);
|
||||||
free(retu->tstr);
|
free(retu->tstr);
|
||||||
|
@ -204,7 +206,7 @@ void logger_write (Logger *log, LOG_LEVEL level, const char *file, int line, con
|
||||||
"%-5s " /* Logger lever string */
|
"%-5s " /* Logger lever string */
|
||||||
"%-20s " /* File:line string */
|
"%-20s " /* File:line string */
|
||||||
"- %s" /* Output message */
|
"- %s" /* Output message */
|
||||||
"\n"; /* Every new print new line */
|
WIN_CR "\n"; /* Every new print new line */
|
||||||
|
|
||||||
|
|
||||||
Logger *this_log = log ? log : global;
|
Logger *this_log = log ? log : global;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user