command: add msg command
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
Download the artifacts for this pull request:
Windows
Can't this be a flag parameter for print-text?
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.
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.
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.
@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.