Tomato6966 / lavalink-client

Easy, flexible and feature-rich lavalink@v4 Client. Both for Beginners and Proficients.
https://tomato6966.github.io/lavalink-client/
MIT License
61 stars 22 forks source link

feat: create debug event #43

Closed NedcloarBR closed 2 months ago

NedcloarBR commented 2 months ago

For handling the debug options instead of direct logging

also i can create a PR

Tomato6966 commented 2 months ago

wdym the logs are only ment to be turned on if smt isn't working so you don'T have to debug the internal code

EvilG-MC commented 2 months ago

I think, he means to create a debug event to send logs

Like:

client.lavalink.on("debug", (message) => console.log(message));
Tomato6966 commented 2 months ago

This makes not really sense for lavalink-client, i'd rather create a function on manager Options like internalLogging(module:"node"|"player"|"utils"|"manager"|"filters", { error: null|Error, info: string })

But ofc. i could also add an event, i'd call it not debug tho, maybe "internal" but also debug makes sense, i'm just thinking in a way that it's clear that it's only for the client, and not related to lavalink at all

EvilG-MC commented 2 months ago

It's a little bit related with the manager... But it would be a bit nice to have that event, but if you don't see it necessary, it's okay

NedcloarBR commented 2 months ago

I think, he means to create a debug event to send logs

Like:

client.lavalink.on("debug", (message) => console.log(message));

Yeah is that I think thats is useful for logging controll like users with custom logger just for styled terminal or functional custom loggers with transcript

EvilG-MC commented 2 months ago

I guess there is a good point in wanting to use some custom logger

Tomato6966 commented 2 months ago

Version 2.3.3 released

This introduces a first version of the debug event

I added a bunch of events

export enum DebugEvents {
    SetSponsorBlock = "SetSponsorBlock",
    DeleteSponsorBlock = "DeleteSponsorBlock",
    TrackEndReplaced = "TrackEndReplaced",

    AutoplayNoSongsAdded = "AutoplayNoSongsAdded",
    AutoplayThresholdSpamLimiter = "AutoplayThresholdSpamLimiter",
    TriggerQueueEmptyInterval = "TriggerQueueEmptyInterval",
    QueueEnded = "QueueEnded",
    TrackStartNewSongsOnly = "TrackStartNewSongsOnly",
    TrackStartNoTrack = "TrackStartNoTrack",

    ResumingFetchingError = "ResumingFetchingError",

    PlayerUpdateNoPlayer = "PlayerUpdateNoPlayer",
    PlayerUpdateFilterFixApply = "PlayerUpdateFilterFixApply",
    PlayerUpdateSuccess = "PlayerUpdateSuccess",

    HeartBeatTriggered = "HeartBeatTriggered",
    NoSocketOnDestroy = "NoSocketOnDestroy",
    SocketTerminateHeartBeatTimeout = "SocketTerminateHeartBeatTimeout",

    TryingConnectWhileConnected = "TryingConnectWhileConnected",

    LavaSearchNothingFound = "LavaSearchNothingFound",
    SearchNothingFound = "SearchNothingFound",

    ValidatingBlacklistLinks = "ValidatingBlacklistLinks",
    ValidatingWhitelistLinks = "ValidatingWhitelistLinks",

    TrackErrorMaxTracksErroredPerTime = "TrackErrorMaxTracksErroredPerTime",
    TrackStuckMaxTracksErroredPerTime = "TrackStuckMaxTracksErroredPerTime",

    PlayerDestroyingSomewhereElse = "PlayerDestroyingSomewhereElse",
    PlayerCreateNodeNotFound = "PlayerCreateNodeNotFound",
    PlayerPlayQueueEmptyTimeoutClear = "PlayerPlayQueueEmptyTimeoutClear",
    PlayerPlayWithTrackReplace = "PlayerPlayWithTrackReplace",
    PlayerPlayUnresolvedTrack = "PlayerPlayUnresolvedTrack",
    PlayerPlayUnresolvedTrackFailed = "PlayerPlayUnresolvedTrackFailed",
    PlayerVolumeAsFilter = "PlayerVolumeAsFilter",
    BandcampSearchLokalEngine = "BandcampSearchLokalEngine",
    PlayerChangeNode = "PlayerChangeNode",

    BuildTrackError = "BuildTrackError",
    TransformRequesterFunctionFailed = "TransformRequesterFunctionFailed",
    GetClosestTrackFailed = "GetClosestTrackFailed",
    PlayerDeleteInsteadOfDestroy = "PlayerDeleteInsteadOfDestroy",
    FailedToConnectToNodes = "FailedToConnectToNodes",
    NoAudioDebug = "NoAudioDebug",
    PlayerAutoReconnect = "PlayerAutoReconnect"
}

This is how you can listen to them:

client.lavalink.on("debug", (eventKey, eventData) => {
        // skip specific log
        if(eventKey === DebugEvents.NoAudioDebug && eventData.message === "Manager is not initated yet") return;
        // skip specific event log of a log-level-state "log"
        if(eventKey === DebugEvents.PlayerUpdateSuccess && eventData.state === "log") return;

        console.group("Lavalink-Client-Debug:");
        console.log("-".repeat(20));
        console.debug(`[${eventKey}]`);
        console.debug(eventData)
        console.log("-".repeat(20));
        console.groupEnd();
    });

Update Log:

Version 2.3.1

Version 2.3.2

Tomato6966 commented 2 months ago

Please leave a review wether you like or not, feel free to add more debug logs via PR or suggestions by openign a ticket / messaging me on discord.

It took quite some time to setup just debug logs which i recommend to only use on a testing environment.