mpv icon indicating copy to clipboard operation
mpv copied to clipboard

command: add msg command

Open layercak3 opened this issue 5 months ago • 6 comments

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

Closes: https://github.com/mpv-player/mpv/issues/14551 Closes: https://github.com/mpv-player/mpv/issues/16707

layercak3 avatar Sep 29 '25 08:09 layercak3

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

na-na-hi avatar Sep 29 '25 12:09 na-na-hi

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.

avih avatar Sep 29 '25 13:09 avih

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.

kasper93 avatar Sep 29 '25 15:09 kasper93

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.

avih avatar Sep 29 '25 15:09 avih

@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.

na-na-hi avatar Oct 02 '25 18:10 na-na-hi