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

V2: WithLogger not used when Debug mode set using WithDebug #145

Closed
andysnowden opened this issue Aug 24, 2023 · 3 comments
Closed

V2: WithLogger not used when Debug mode set using WithDebug #145

andysnowden opened this issue Aug 24, 2023 · 3 comments

Comments

@andysnowden
Copy link

Hello,

I am trying out the new v2 library and so far the changes are great. I'm just running into something of an odd behavior and wanted to confirm if this was intentional or perhaps an oversight.

When initializing the library with NewClient I am passing in my own logger (logrus.Logger) and optionally setting WithDebug if my logrus instance log level is also set to debug level. What I'm noticing is when not in debug the logs are properly being formatted and processed via my log instance. However, once I enable debug it appears to bypass my logger and log straight to os.Stderr. This is not causing any real issue other than just my desired control over log formats/etc.

Lib init

	slackBot := slacker.NewClient(
		viper.GetString("slack_bot_token"),
		viper.GetString("slack_app_token"),
		slacker.WithLogger(log),
		slacker.WithDebug(internal.IsDebugMode(log)),
	)

IsDebugMode wrapper

func IsDebugMode(logger *logrus.Logger) bool {
	if logger.Level == logrus.DebugLevel {
		return true
	}
	return false
}

output while in debug

{"fileline":"zenbot/main.go:40","level":"debug","message":"basic initialization complete","time":"2023-08-24T12:54:21-04:00"}
slack-go/slack/socketmode2023/08/24 12:54:21 socket_mode_managed_conn.go:257: Starting SocketMode
{"fileline":"[email protected]/slacker.go:219","level":"info","message":"connecting to Slack with Socket Mode...\n","time":"2023-08-24T12:54:21-04:00"}
slack-go/slack/socketmode2023/08/24 12:54:21 socket_mode_managed_conn.go:261: Failed to start or connect with SocketMode: not_authed
slack-go/slack/socketmode2023/08/24 12:54:21 socket_mode_managed_conn.go:209: invalid auth when connecting with SocketMode: not_authed
slack-go/slack/socketmode2023/08/24 12:54:21 socket_mode_managed_conn.go:76: Failed to connect with Socket Mode on try 0: not_authed
{"fileline":"bot/init.go:51","level":"error","message":"slack bot failure: not_authed","time":"2023-08-24T12:54:21-04:00"}

Process finished with the exit code 0

output without WithDebug

{"fileline":"zenbot/main.go:40","level":"debug","message":"basic initialization complete","time":"2023-08-24T12:55:30-04:00"}
{"fileline":"[email protected]/slacker.go:219","level":"info","message":"connecting to Slack with Socket Mode...\n","time":"2023-08-24T12:55:30-04:00"}
{"fileline":"bot/init.go:50","level":"error","message":"slack bot failure: not_authed","time":"2023-08-24T12:55:30-04:00"}

Process finished with the exit code 0
@raed-shomali
Copy link
Contributor

I believe it is intended.

When Debug is turned on, we pass that value to the underlying slack API library too. So you will see its logs too.

@andysnowden
Copy link
Author

That makes sense, going to mark this one closed then

@raed-shomali
Copy link
Contributor

Thank you!

Just letting you know, I am rewriting the Logger to use the new standard slog.Logger #155

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

No branches or pull requests

2 participants