Skip to content

Conversation

@layercak3
Copy link
Contributor

@layercak3 layercak3 commented Sep 29, 2025

This allows C plugins, IPC clients, and libmpv to write log messages.

Closes: #14551
Closes: #16707

@github-actions
Copy link

github-actions bot commented Sep 29, 2025

@na-na-hi
Copy link
Contributor

Can't this be a flag parameter for print-text?

@avih
Copy link
Member

avih commented Sep 29, 2025

I feel that the correct approach here would be to implement a log-message mpv command or some such, which would have the following advantages:

  • Avoid duplicating a client log API yet again (it already exists in lua.c and javascript.c).
  • Allow unifying the existing implementations, so the code can be removed from lua.c and javascript.c, and instead become a trivial passthrough to this command in defaults.lua and defaults.js.
  • Allow also IPC clients to use it.

@sfan5 mentioned a concern that currently all mpv commands are logged, and this can be annoying, and if indeed it is, then maybe this command could use an exception from auto-logging the log command itself.

@kasper93
Copy link
Member

Can't this be a flag parameter for print-text?

print-text is executed in context of cplayer, and frankly it's bit of a hack right now. It doesn't allow changing log level, it should crate and use own mp_log_new(tmp, mpctx->log, cmd->cmd->sender); or something. Doesn't allow formatting, but allows property expansion instead.

I feel like logging primitives are lower level than commands. Especially because commands are already logging by its own, so this would spam more than it should.

Either way, I don't have strong opinion about this, if script authors prefer command, so be it. Though, for me it would be natural to expose native logging functions, same as lua/js already does.

@avih
Copy link
Member

avih commented Sep 29, 2025

if script authors prefer command, so be it.

Scripting API's won't change. Just under the hood it will use this command instead of C code which is currently duplicated in lua.c and javascript.c.

@na-na-hi
Copy link
Contributor

na-na-hi commented Oct 2, 2025

@sfan5 mentioned a concern that currently all mpv commands are logged, and this can be annoying, and if indeed it is, then maybe this command could use an exception from auto-logging the log command itself.

Especially because commands are already logging by its own, so this would spam more than it should.

is_noisy already exists, and commands with that flag (like print-text) will only log on trace level, so the log-message command can just have that set.

@layercak3 layercak3 closed this Oct 2, 2025
@layercak3 layercak3 deleted the client-msg-api branch October 2, 2025 21:41
@layercak3 layercak3 restored the client-msg-api branch October 2, 2025 21:44
@layercak3 layercak3 reopened this Oct 2, 2025
This allows C plugins, IPC clients, and libmpv to write log messages.

Closes: mpv-player#14551
Closes: mpv-player#16707
This may be useful for IPC clients and libmpv users, which do not have
descriptive client names (`ipc_%d`, `main`), or may want to log using
a different prefixes for different components.
@layercak3 layercak3 changed the title client API: add mpv_msg() and mpv_msg_va() functions command: add msg command Oct 5, 2025
@sfan5 sfan5 self-requested a review October 5, 2025 16:59

This line of Lua prints "foo \\{bar}" on the OSD.

``msg <level> <message> [...]``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not extend print-text command with optional arguments? It can be aliased to msg if preferred, but both do the same thing.


.. note:: Lua and JS code should use the provided ``mp.msg`` modules.

``msg-prefix <level> <prefix> <message> [...]``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want that? I would say we don't let clients to change their prefix.

Or it may be additional arg in msg, but instead of replacing the existing prefix, it should create sub logger, to form <client_name>/<perfix> form.

if (level < 0)
return;

struct mp_log *log = mp_log_new(NULL, mpctx->log, cmd->cmd->sender);
Copy link
Member

@kasper93 kasper93 Oct 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to create logger during client init and set it in cmd, same as cmd->cmd->sender. sender field can be made a struct with char *name and mp_log log.

talloc_free(log);
}

static void cmd_msg_prefix(void *p)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicated code above, it should be made single function/command.

@kasper93 kasper93 added this to the Release v0.42.0 milestone Oct 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logging API for C scripts Allow frontends/GUIs to write log messages

5 participants