1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
3 * ALSA SEQ < - > JACK MIDI bridge
5 * Copyright (c) 2008,2009,2010 Nedko Arnaudov <nedko@arnaudov.name>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 static ino_t g_log_file_ino
;
34 static FILE * g_logfile
= NULL
;
36 static bool a2j_log_open(void)
42 if (g_logfile
!= NULL
)
44 ret
= stat(g_a2j_log_path
, &st
);
45 if (ret
!= 0 || g_log_file_ino
!= st
.st_ino
)
55 for (retry
= 0; retry
< 10; retry
++)
57 g_logfile
= fopen(g_a2j_log_path
, "a");
58 if (g_logfile
== NULL
)
60 fprintf(stderr
, "Cannot open a2jmidid log file \"%s\": %d (%s)\n", g_a2j_log_path
, errno
, strerror(errno
));
64 ret
= stat(g_a2j_log_path
, &st
);
67 g_log_file_ino
= st
.st_ino
;
75 fprintf(stderr
, "Cannot stat just opened a2jmidid log file \"%s\": %d (%s). %d retries\n", g_a2j_log_path
, errno
, strerror(errno
), retry
);
79 bool a2j_log_init(bool use_logfile
)
83 return a2j_log_open();
89 void a2j_log_uninit(void)
91 if (g_logfile
!= NULL
)
106 char timestamp_str
[26];
108 if (g_logfile
!= NULL
&& a2j_log_open())
116 case A2J_LOG_LEVEL_DEBUG
:
117 case A2J_LOG_LEVEL_INFO
:
120 case A2J_LOG_LEVEL_ERROR
:
126 if (g_logfile
!= NULL
)
129 ctime_r(×tamp
, timestamp_str
);
130 timestamp_str
[24] = 0;
132 fprintf(stream
, "%s: ", timestamp_str
);
135 va_start(ap
, format
);
136 vfprintf(stream
, format
, ap
);