1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-17 04:58:06 +00:00

msg: allow duplicating a mp_log

Trivial; this is mostly just reindenting the normal codepath.
This commit is contained in:
wm4 2014-08-24 23:34:20 +02:00
parent 95286cd8b8
commit cae22ae3b6

View File

@ -367,17 +367,18 @@ void mp_msg_va(struct mp_log *log, int lev, const char *format, va_list va)
// parent's name. If the name starts with "/", the parent's name is not // parent's name. If the name starts with "/", the parent's name is not
// prefixed (except in verbose mode), and if it starts with "!", the name is // prefixed (except in verbose mode), and if it starts with "!", the name is
// not printed at all (except in verbose mode). // not printed at all (except in verbose mode).
// If name is NULL, the parent's name/prefix is used.
// Thread-safety: fully thread-safe, but keep in mind that talloc is not (so // Thread-safety: fully thread-safe, but keep in mind that talloc is not (so
// talloc_ctx must be owned by the current thread). // talloc_ctx must be owned by the current thread).
struct mp_log *mp_log_new(void *talloc_ctx, struct mp_log *parent, struct mp_log *mp_log_new(void *talloc_ctx, struct mp_log *parent,
const char *name) const char *name)
{ {
assert(parent); assert(parent);
assert(name);
struct mp_log *log = talloc_zero(talloc_ctx, struct mp_log); struct mp_log *log = talloc_zero(talloc_ctx, struct mp_log);
if (!parent->root) if (!parent->root)
return log; // same as null_log return log; // same as null_log
log->root = parent->root; log->root = parent->root;
if (name) {
if (name[0] == '!') { if (name[0] == '!') {
name = &name[1]; name = &name[1];
} else if (name[0] == '/') { } else if (name[0] == '/') {
@ -395,6 +396,10 @@ struct mp_log *mp_log_new(void *talloc_ctx, struct mp_log *parent,
log->prefix = NULL; log->prefix = NULL;
if (!log->verbose_prefix[0]) if (!log->verbose_prefix[0])
log->verbose_prefix = "global"; log->verbose_prefix = "global";
} else {
log->prefix = talloc_strdup(log, parent->prefix);
log->verbose_prefix = talloc_strdup(log, parent->verbose_prefix);
}
return log; return log;
} }