adventuregamestudio / ags

AGS editor and engine source code
Other
678 stars 159 forks source link

Add a Log function to engine plugin API #2429

Closed ericoporto closed 2 months ago

ericoporto commented 2 months ago

Describe the problem Often it's useful to log from a Plugin, and usually this is done by simply throwing printfs or using iostream, but it would be nice to be able to use AGS own log functionality.

Plus there was a typo (https://github.com/adventuregamestudio/ags/commit/9acbba5f17e10921da19f8724bae75d080afd4b0) that made a bit hard to use the Engine script api for System.Log.

Suggested change Add some function for logging from the plugin API and increase the plugin version once adding it so it can be detected by a plugin that such function is available.

ivan-mogilko commented 2 months ago

In regards to the log group, there may be two approaches:

  1. Add a new general group "Plugins", and use it for all plugins. The engine's function may prepend plugin's name to the log message though, to help distinguish them. The advantage of this approach is that there's only 1 group to configure.
  2. Something I was thinking initially, is to dynamically create a new group id for each loaded plugin, and then use that group id for each particular plugin messages. The downside of this approach is that it makes it more difficult to configure.
  3. Not sure if will be easy to do, but the combined variant would have a group per plugin, but configured as one "plugins" group.
ericoporto commented 2 months ago

I don't know yet on the best approach, but I think as simple as possible would be alright, so from the options I guess it would be the option 1.

In the meantime I discovered I wasn't dreaming and found a function is in the API, it just has no log types!

https://github.com/adventuregamestudio/ags/blob/9acbba5f17e10921da19f8724bae75d080afd4b0/Engine/plugin/agsplugin.h#L512-L513

ivan-mogilko commented 2 months ago

Ah, that function prints into "Game" group; it's equivalent of function that prints warnings and errors when something wrong happens after a script command.

EDIT: I think originally it only printed to that in-game "console", which is now deprecated.