Changeset 76d92db1 in mainline
- Timestamp:
- 2012-08-14T09:37:42Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- cddcc4a3
- Parents:
- 14de4106
- Location:
- uspace/srv/logger
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/logger/logger.h
r14de4106 r76d92db1 42 42 #include <fibril_synch.h> 43 43 44 #define DEFAULT_LOGGING_LEVEL LVL_ WARN44 #define DEFAULT_LOGGING_LEVEL LVL_NOTE 45 45 46 46 #define NAME "logger" … … 67 67 68 68 void namespace_wait_for_reader_change(logging_namespace_t *, bool *); 69 bool namespace_has_reader(logging_namespace_t * );69 bool namespace_has_reader(logging_namespace_t *, log_level_t); 70 70 void namespace_add_message(logging_namespace_t *, const char *, log_level_t); 71 71 log_message_t *namespace_get_next_message(logging_namespace_t *); -
uspace/srv/logger/main.c
r14de4106 r76d92db1 74 74 static int handle_receive_message(logging_namespace_t *namespace, int level) 75 75 { 76 bool skip_message = (level > DEFAULT_LOGGING_LEVEL) && !namespace_has_reader(namespace );76 bool skip_message = (level > DEFAULT_LOGGING_LEVEL) && !namespace_has_reader(namespace, level); 77 77 if (skip_message) { 78 78 /* Abort the actual message buffer transfer. */ -
uspace/srv/logger/namespace.c
r14de4106 r76d92db1 40 40 */ 41 41 42 42 43 struct logging_namespace { 43 44 fibril_mutex_t guard; … … 45 46 fibril_condvar_t reader_appeared_cv; 46 47 bool has_reader; 48 FILE *logfile; 49 log_level_t logfile_level; 47 50 const char *name; 48 51 link_t link; … … 107 110 return NULL; 108 111 } 112 113 char *logfilename; 114 int rc = asprintf(&logfilename, "/log/%s", name); 115 if (rc < 0) { 116 free(namespace->name); 117 free(namespace); 118 return NULL; 119 } 120 namespace->logfile = fopen(logfilename, "a"); 121 free(logfilename); 122 if (namespace->logfile == NULL) { 123 free(namespace->name); 124 free(namespace); 125 return NULL; 126 } 127 128 namespace->logfile_level = DEFAULT_LOGGING_LEVEL; 109 129 110 130 fibril_mutex_initialize(&namespace->guard); … … 153 173 154 174 // TODO - destroy pending messages 175 fclose(namespace->logfile); 155 176 free(namespace->name); 156 177 free(namespace); … … 223 244 } 224 245 225 bool namespace_has_reader(logging_namespace_t *namespace) 226 { 227 fibril_mutex_lock(&namespace->guard); 228 bool has_reader = namespace->has_reader; 246 bool namespace_has_reader(logging_namespace_t *namespace, log_level_t level) 247 { 248 fibril_mutex_lock(&namespace->guard); 249 bool has_reader = namespace->has_reader 250 || level <= namespace->logfile_level; 229 251 fibril_mutex_unlock(&namespace->guard); 230 252 return has_reader; … … 247 269 if (level <= DEFAULT_LOGGING_LEVEL) { 248 270 printf("[%s %d]: %s\n", namespace->name, level, message); 271 } 272 if (level <= namespace->logfile_level) { 273 fprintf(namespace->logfile, "[%d]: %s\n", level, message); 274 fflush(namespace->logfile); 249 275 } 250 276
Note:
See TracChangeset
for help on using the changeset viewer.