Add log_remove_target

Don't need to deinit+init struct log any more just to switch log target
:)

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui
2019-02-07 21:48:39 +00:00
parent 049cc94e7a
commit 68c77cd7d8
3 changed files with 37 additions and 17 deletions

View File

@@ -103,7 +103,22 @@ void log_add_target(struct log *l, struct log_target *tgt) {
l->head = tgt;
}
/// Destroy a log struct
/// Remove a previously added log target for a log struct. If the log target was never
/// added, nothing happens.
void log_remove_target(struct log *l, struct log_target *tgt) {
struct log_target *now = l->head, **prev = &l->head;
while (now) {
if (now == tgt) {
*prev = now->next;
tgt->ops->destroy(tgt);
break;
}
prev = &now->next;
now = now->next;
}
}
/// Destroy a log struct and every log target added to it
void log_destroy(struct log *l) {
// free all tgt
struct log_target *head = l->head;