unsigned int tdm_log_debug_level = TDM_LOG_LEVEL_INFO;
+static int stdout_fd = -1;
+
EXTERN void
tdm_log_enable_color(unsigned int enable)
{
EXTERN void
tdm_log_set_path(const char *path)
{
- char fd_name[TDM_PATH_LEN];
- int log_fd = -1;
- FILE *log_fl;
+ if (!path) {
+ if (stdout_fd != -1) {
+ fflush(stdout);
+ close(STDOUT_FILENO);
+ dup2(stdout_fd, STDOUT_FILENO);
+ close(stdout_fd);
+ stdout_fd = -1;
+ }
+ } else {
+ char fd_name[TDM_PATH_LEN];
+ int log_fd = -1;
+ FILE *log_fl;
- snprintf(fd_name, TDM_PATH_LEN, "%s", path);
+ snprintf(fd_name, TDM_PATH_LEN, "%s", path);
- log_fl = fopen(fd_name, "a");
- if (!log_fl) {
- TDM_ERR("failed: open file(%s)\n", fd_name);
- return;
- }
+ log_fl = fopen(fd_name, "a");
+ if (!log_fl) {
+ TDM_ERR("failed: open file(%s)\n", fd_name);
+ return;
+ }
- fflush(stdout);
- close(STDOUT_FILENO);
+ if (stdout_fd == -1) {
+ fflush(stdout);
+ stdout_fd = dup(STDOUT_FILENO);
+ TDM_RETURN_IF_FAIL(stdout_fd != -1);
+ }
- setvbuf(log_fl, NULL, _IOLBF, 512);
- log_fd = fileno(log_fl);
+ setvbuf(log_fl, NULL, _IOLBF, 512);
+ log_fd = fileno(log_fl);
- dup2(log_fd, STDOUT_FILENO);
- fclose(log_fl);
+ close(STDOUT_FILENO);
+ dup2(log_fd, STDOUT_FILENO);
+ fclose(log_fl);
+ }
}
EXTERN void