Changeset ebbc8a74 in mainline
- Timestamp:
- 2012-08-16T15:44:27Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d6ddeb7
- Parents:
- dc5aa568
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/io/log.c
rdc5aa568 rebbc8a74 62 62 #define MESSAGE_BUFFER_SIZE 4096 63 63 64 FIBRIL_RWLOCK_INITIALIZE(current_observed_level_lock);65 log_level_t current_observed_level;66 67 64 static int logger_register(async_sess_t *session, const char *prog_name) 68 65 { … … 113 110 114 111 return reg_msg_rc; 115 }116 117 static void cannot_use_level_changed_monitor(void)118 {119 fibril_rwlock_write_lock(¤t_observed_level_lock);120 current_observed_level = LVL_LIMIT;121 fibril_rwlock_write_unlock(¤t_observed_level_lock);122 }123 124 static int observed_level_changed_monitor(void *arg)125 {126 async_sess_t *monitor_session = service_connect_blocking(EXCHANGE_SERIALIZE, SERVICE_LOGGER, LOGGER_INTERFACE_SINK, 0);127 if (monitor_session == NULL) {128 cannot_use_level_changed_monitor();129 return ENOMEM;130 }131 132 int rc = logger_register(monitor_session, log_prog_name);133 if (rc != EOK) {134 cannot_use_level_changed_monitor();135 return rc;136 }137 138 async_exch_t *exchange = async_exchange_begin(monitor_session);139 if (exchange == NULL) {140 cannot_use_level_changed_monitor();141 return ENOMEM;142 }143 144 while (true) {145 sysarg_t has_reader;146 sysarg_t msg_rc = async_req_0_1(exchange,147 LOGGER_BLOCK_UNTIL_READER_CHANGED, &has_reader);148 if (msg_rc != EOK) {149 cannot_use_level_changed_monitor();150 break;151 }152 153 fibril_rwlock_write_lock(¤t_observed_level_lock);154 if ((bool) has_reader) {155 current_observed_level = LVL_LIMIT;156 } else {157 current_observed_level = LVL_NOTE;158 }159 fibril_rwlock_write_unlock(¤t_observed_level_lock);160 }161 162 async_exchange_end(exchange);163 164 return EOK;165 }166 167 static log_level_t get_current_observed_level(void)168 {169 fibril_rwlock_read_lock(¤t_observed_level_lock);170 log_level_t level = current_observed_level;171 fibril_rwlock_read_unlock(¤t_observed_level_lock);172 return level;173 112 } 174 113 … … 230 169 int rc = logger_register(logger_session, log_prog_name); 231 170 232 current_observed_level = LVL_NOTE;233 234 fid_t observed_level_changed_fibril = fibril_create(observed_level_changed_monitor, NULL);235 if (observed_level_changed_fibril == 0) {236 cannot_use_level_changed_monitor();237 } else {238 fibril_add_ready(observed_level_changed_fibril);239 }240 241 171 return rc; 242 172 } … … 266 196 } 267 197 268 bool _log_shall_record(log_context_t context, log_level_t level)269 {270 return get_current_observed_level() >= level;271 }272 273 198 /** Write an entry to the log. 274 199 * … … 278 203 * @param fmt Format string (no traling newline). 279 204 */ 280 void _log_ctx_msg(log_context_t ctx, log_level_t level, const char *fmt, ...)205 void log_ctx_msg(log_context_t ctx, log_level_t level, const char *fmt, ...) 281 206 { 282 207 va_list args; 283 208 284 209 va_start(args, fmt); 285 _log_ctx_msgv(ctx, level, fmt, args);210 log_ctx_msgv(ctx, level, fmt, args); 286 211 va_end(args); 287 212 } … … 294 219 * @param fmt Format string (no trailing newline) 295 220 */ 296 void _log_ctx_msgv(log_context_t ctx, log_level_t level, const char *fmt, va_list args)221 void log_ctx_msgv(log_context_t ctx, log_level_t level, const char *fmt, va_list args) 297 222 { 298 223 assert(level < LVL_LIMIT); 299 300 if (get_current_observed_level() < level) {301 return;302 }303 224 304 225 char *message_buffer = malloc(MESSAGE_BUFFER_SIZE); -
uspace/lib/c/include/io/log.h
rdc5aa568 rebbc8a74 58 58 extern int log_level_from_str(const char *, log_level_t *); 59 59 60 extern bool _log_shall_record(log_context_t, log_level_t);61 60 extern int log_init(const char *, log_level_t); 62 61 63 62 extern log_context_t log_context_create(const char *); 64 65 #define log_ctx_msg(context, level, format, ...) \66 do { \67 if (_log_shall_record((context), (level))) { \68 _log_ctx_msg((context), (level), format, ##__VA_ARGS__); \69 } \70 } while (false)71 72 #define log_ctx_msgv(context, level, format, args) \73 do { \74 if (_log_shall_record((context), (level))) { \75 _log_ctx_msgv((context), (level), format, args); \76 } \77 } while (false)78 63 79 64 #define log_msg(level, format, ...) \ … … 82 67 log_ctx_msgv(LOG_CONTEXT_DEFAULT, (level), (format), (args)) 83 68 84 extern void _log_ctx_msg(log_context_t, log_level_t, const char *, ...);85 extern void _log_ctx_msgv(log_context_t, log_level_t, const char *, va_list);69 extern void log_ctx_msg(log_context_t, log_level_t, const char *, ...); 70 extern void log_ctx_msgv(log_context_t, log_level_t, const char *, va_list); 86 71 87 72 #endif -
uspace/lib/c/include/ipc/logger.h
rdc5aa568 rebbc8a74 46 46 LOGGER_REGISTER = IPC_FIRST_USER_METHOD, 47 47 LOGGER_CREATE_CONTEXT, 48 LOGGER_MESSAGE, 49 LOGGER_BLOCK_UNTIL_READER_CHANGED 48 LOGGER_MESSAGE 50 49 } logger_sink_request_t; 51 50 -
uspace/srv/logger/logger.h
rdc5aa568 rebbc8a74 56 56 int namespace_change_level(logging_namespace_t *, log_level_t); 57 57 58 void namespace_wait_for_reader_change(logging_namespace_t *, bool *);59 58 bool namespace_has_reader(logging_namespace_t *, sysarg_t, log_level_t); 60 59 void namespace_add_message(logging_namespace_t *, const char *, sysarg_t, log_level_t); -
uspace/srv/logger/namespace.c
rdc5aa568 rebbc8a74 51 51 fibril_mutex_t guard; 52 52 size_t writers_count; 53 fibril_condvar_t level_changed_cv;54 53 FILE *logfile; 55 54 log_level_t level; … … 135 134 136 135 fibril_mutex_initialize(&namespace->guard); 137 fibril_condvar_initialize(&namespace->level_changed_cv);138 136 namespace->writers_count = 0; 139 137 link_initialize(&namespace->link); … … 228 226 namespace->context[i].level = level; 229 227 } 230 fibril_condvar_broadcast(&namespace->level_changed_cv);231 228 fibril_mutex_unlock(&namespace->guard); 232 229 … … 277 274 namespace->context[i].level = new_level; 278 275 rc = EOK; 279 fibril_condvar_broadcast(&namespace->level_changed_cv);280 276 goto leave; 281 277 } … … 287 283 return rc; 288 284 } 289 290 void namespace_wait_for_reader_change(logging_namespace_t *namespace, bool *has_reader_now)291 {292 fibril_mutex_lock(&namespace->guard);293 // FIXME: properly watch for state change294 fibril_condvar_wait(&namespace->level_changed_cv, &namespace->guard);295 *has_reader_now = true;296 fibril_mutex_unlock(&namespace->guard);297 }298 299 285 300 286 void namespace_add_message(logging_namespace_t *namespace, const char *message, sysarg_t context, log_level_t level)
Note:
See TracChangeset
for help on using the changeset viewer.