Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended Log Callbacks #39

Open
MonzUn opened this issue Feb 13, 2022 · 1 comment
Open

Extended Log Callbacks #39

MonzUn opened this issue Feb 13, 2022 · 1 comment

Comments

@MonzUn
Copy link

MonzUn commented Feb 13, 2022

Is your feature request related to a problem? Please describe.
I want to propagate ingame logs to Discord, but the only existing way that I know of is to subscribe to ClientLogEventTrigger::OnLogWritten. This gives me only the main server log messages (no admin command log etc) and gives me formatting that I need to strip from the message.

Describe the solution you'd like
If ILogWriter itself could have a callback so that any log could be fetched as long as we could fetch the ILogWriter object, that would be amazing ^^

Describe alternatives you've considered
If the above is not possible, then a log callback that only sends the raw message (and maybe log category?) would also be helpful :)

@MonzUn
Copy link
Author

MonzUn commented May 9, 2022

We now have ClientLogEventTrigger.OnLogWritten but it's only for the main log and it doesn't allow handling of the various log levels. I've done some ugly handling of this on my end but it would be preferable if we could track any log writing.

        public void ConvertServerLogEvent(string logEventText)
        {
            string strippedEventText = MessageUtils.StripTags(logEventText);
            Logger.LogLevel eventLevel = Logger.LogLevel.Silent;
            string[] parts = strippedEventText.Split( ':', 2);
            if (parts.Length == 0)
            {
                Logger.Warning($"Ignored non delimited log event: \"{strippedEventText}\"");
                return;
            }

            if (parts[0].ContainsCaseInsensitive("Log"))
                eventLevel = Logger.LogLevel.Information;
            else if (parts[0].ContainsCaseInsensitive("Error"))
                eventLevel = Logger.LogLevel.Error;
            else if (parts[0].ContainsCaseInsensitive("Warning"))
                eventLevel = Logger.LogLevel.Warning;
            else if (parts[0].ContainsCaseInsensitive("Debug"))
                eventLevel = Logger.LogLevel.Debug;

            FireEvent(DLEventType.ServerLogWritten, eventLevel, parts[1].Trim());
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant