Mercurial > audlegacy
annotate src/audacious/logger.c @ 3957:fed07be6b708
every other menu shows on button press..
| author | Tomasz Mon <desowin@gmail.com> |
|---|---|
| date | Fri, 16 Nov 2007 15:20:07 +0100 |
| parents | 978fbda4855f |
| children | de33c83aa06f |
| rev | line source |
|---|---|
|
3112
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
1 /* Audacious - Cross-platform multimedia player |
|
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
2 * Copyright (C) 2005-2007 Audacious development team |
| 2313 | 3 * |
|
3112
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
4 * Based on BMP: |
|
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
5 * Copyright (C) 2003-2004 BMP development team |
| 2313 | 6 * |
|
3112
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
7 * This program is free software; you can redistribute it and/or modify |
|
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
8 * it under the terms of the GNU General Public License as published by |
|
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
3112
diff
changeset
|
9 * the Free Software Foundation; under version 3 of the License. |
| 2313 | 10 * |
|
3112
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
11 * This program is distributed in the hope that it will be useful, |
|
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
14 * GNU General Public License for more details. |
|
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
15 * |
|
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
16 * You should have received a copy of the GNU General Public License |
|
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
3112
diff
changeset
|
17 * along with this program. If not, see <http://www.gnu.org/licenses>. |
|
3123
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
18 * |
|
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
19 * The Audacious team does not consider modular code linking to |
|
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
20 * Audacious or using our public API to be a derived work. |
| 2313 | 21 */ |
| 22 | |
| 23 #ifdef HAVE_CONFIG_H | |
| 24 # include "config.h" | |
| 25 #endif | |
| 26 | |
| 27 #include "logger.h" | |
| 28 | |
| 29 #include <glib.h> | |
| 30 #include <glib/gi18n.h> | |
| 31 #include <glib/gprintf.h> | |
| 32 #include <stdio.h> | |
| 33 #include <stdlib.h> | |
| 34 #include <sys/stat.h> | |
| 35 #include <time.h> | |
| 36 | |
| 37 #include "main.h" | |
| 38 | |
| 39 | |
| 40 #define LOG_ALL_LEVELS \ | |
| 41 (G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION) | |
| 42 | |
| 43 | |
| 44 struct _LogHandler { | |
| 45 gchar *domain; | |
| 46 GLogLevelFlags level; | |
| 47 guint id; | |
| 48 }; | |
| 49 | |
| 50 typedef struct _LogHandler LogHandler; | |
| 51 | |
| 52 | |
| 53 static FILE *bmp_log_file = NULL; | |
| 54 | |
| 55 G_LOCK_DEFINE_STATIC(bmp_log_file); | |
| 56 | |
| 57 static LogHandler log_handlers[] = { | |
| 58 {NULL, LOG_ALL_LEVELS, 0}, | |
| 59 {"Glib", LOG_ALL_LEVELS, 0}, | |
|
3581
978fbda4855f
Add GThread to domain logging targets.
William Pitcock <nenolod@atheme.org>
parents:
3123
diff
changeset
|
60 {"GThread", LOG_ALL_LEVELS, 0}, |
| 2313 | 61 {"Gtk", LOG_ALL_LEVELS, 0} |
| 62 }; | |
| 63 | |
| 64 static guint log_handler_count = G_N_ELEMENTS(log_handlers); | |
| 65 | |
| 66 | |
| 67 static const gchar * | |
| 68 get_timestamp_str(void) | |
| 69 { | |
| 70 time_t current_time = time(NULL); | |
| 71 return ctime(¤t_time); | |
| 72 } | |
| 73 | |
| 74 static size_t | |
| 75 get_filesize(const gchar *filename) | |
| 76 { | |
| 77 struct stat info; | |
| 78 | |
| 79 if (stat(filename, &info)) | |
| 80 return 0; | |
| 81 | |
| 82 return info.st_size; | |
| 83 } | |
| 84 | |
| 85 static void | |
| 86 log_to_file(const gchar * domain, GLogLevelFlags level, | |
| 87 const gchar * message, gpointer data) | |
| 88 { | |
| 89 FILE *file = (FILE *) data; | |
| 90 | |
| 91 if (!file) { | |
| 92 g_printerr(G_STRLOC ": file is NULL!\n"); | |
| 93 return; | |
| 94 } | |
| 95 | |
| 96 G_LOCK(bmp_log_file); | |
| 97 | |
| 98 if (domain) | |
| 99 g_fprintf(file, "(%s) ", domain); | |
| 100 | |
| 101 if (message) | |
| 102 g_fprintf(file, "%s\n", message); | |
| 103 else | |
| 104 g_fprintf(file, "message is NULL!\n"); | |
| 105 | |
| 106 fflush(file); | |
| 107 | |
| 108 G_UNLOCK(bmp_log_file); | |
| 109 } | |
| 110 | |
| 111 gboolean | |
| 112 bmp_logger_start(const gchar * filename) | |
| 113 { | |
| 114 guint i; | |
| 115 | |
| 116 g_return_val_if_fail(filename != NULL, FALSE); | |
| 117 | |
| 118 /* truncate file when size limit is reached */ | |
| 119 if (get_filesize(filename) < BMP_LOGGER_FILE_MAX_SIZE) | |
| 120 bmp_log_file = fopen(filename, "at"); | |
| 121 else | |
| 122 bmp_log_file = fopen(filename, "w+t"); | |
| 123 | |
| 124 if (!bmp_log_file) { | |
| 125 g_printerr(_("Unable to create log file (%s)!\n"), filename); | |
| 126 return FALSE; | |
| 127 } | |
| 128 | |
| 129 for (i = 0; i < log_handler_count; i++) { | |
| 130 log_handlers[i].id = g_log_set_handler(log_handlers[i].domain, | |
| 131 log_handlers[i].level, | |
| 132 log_to_file, bmp_log_file); | |
| 133 } | |
| 134 | |
| 135 g_message("\n** LOGGING STARTED AT %s", get_timestamp_str()); | |
| 136 | |
| 137 return TRUE; | |
| 138 } | |
| 139 | |
| 140 void | |
| 141 bmp_logger_stop(void) | |
| 142 { | |
| 143 guint i; | |
| 144 | |
| 145 if (!bmp_log_file) | |
| 146 return; | |
| 147 | |
| 148 g_message("\n** LOGGING STOPPED AT %s", get_timestamp_str()); | |
| 149 | |
| 150 for (i = 0; i < log_handler_count; i++) | |
| 151 g_log_remove_handler(log_handlers[i].domain, log_handlers[i].id); | |
| 152 | |
| 153 fclose(bmp_log_file); | |
| 154 bmp_log_file = NULL; | |
| 155 } |
