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

Fix #405 by providing a better way to configure logger #406

Merged
merged 2 commits into from
Feb 19, 2020

Conversation

seratch
Copy link
Member

@seratch seratch commented Feb 15, 2020

Summary

This pull request fixes #405 by changing the initialization of the App instances a bit. The changes included in this PR are:

  • Set the logger name for the default one
  • Change the default values for logger, logLevel arguments of App constructor to distinguish they're explicitly specified or not
  • Stop sharing a single logger with WebClient as WebClient has its own logger initialization logics - in other words, only the logLevel will be shared between Bolt apps and WebClient

The behavior

The log output with this fix will be more straight-forward.

If a developer goes with the default settings (default ConsoleLogger and LogLevel.INFO) gives only logLevel to the App constructor as below,

const { LogLevel } = require("@slack/logger");
const { App } = require("@slack/bolt");
const app = new App({
  logLevel: LogLevel.DEBUG,
  token: process.env.SLACK_BOT_TOKEN,
  signingSecret: process.env.SLACK_SIGNING_SECRET
});

The logger shows the following outputs.

[DEBUG]  WebClient:0 initialized
[DEBUG]  WebClient:0 apiCall('auth.test') start
[DEBUG]  WebClient:0 will perform http request
⚡️ Bolt app is running!
[DEBUG]  WebClient:0 http response received
[DEBUG]  WebClient:1 initialized
[DEBUG]  bolt-app Conversation context not loaded: Conversation not found

If a developer wants to customize the logger name, doing as below works.

const { LogLevel, ConsoleLogger } = require("@slack/logger");
const logger = new ConsoleLogger();
logger.setName('my-bolt-app');
logger.setLevel(LogLevel.DEBUG);

const { App } = require("@slack/bolt");
const app = new App({
  logger: logger,
  token: process.env.SLACK_BOT_TOKEN,
  signingSecret: process.env.SLACK_SIGNING_SECRET
});

The output can be like this. The only last line is different from the default logger.

[DEBUG]  WebClient:0 initialized
[DEBUG]  WebClient:0 apiCall('auth.test') start
[DEBUG]  WebClient:0 will perform http request
⚡️ Bolt app is running!
[DEBUG]  WebClient:0 http response received
[DEBUG]  WebClient:1 initialized
[DEBUG]  my-bolt-app Conversation context not loaded: Conversation not found

If a developer gives both logger and logLevel, Bolt gives priority to logLevel than logger's log level (the log level in logger will be overwritten by the logLevel while the initialization). This behavior is compatible with the past versions so that I think we should not change it at least this time.

Next Steps

I'm sure this improvement should be applied to both Bolt v1 and v2. Once other maintainers approve this change, I will make another PR that brings the same change to the v2 branch later on.

Requirements (place an x in each [ ])

@seratch seratch added bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:minor labels Feb 15, 2020
@seratch seratch self-assigned this Feb 15, 2020
@codecov
Copy link

codecov bot commented Feb 15, 2020

Codecov Report

Merging #406 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##           master    #406   +/-   ##
======================================
  Coverage    81.5%   81.5%           
======================================
  Files           7       7           
  Lines         530     530           
  Branches      152     152           
======================================
  Hits          432     432           
  Misses         70      70           
  Partials       28      28

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d45f209...4f3f3ea. Read the comment docs.

if (typeof logger === 'undefined') {
// Initialize with the default logger
const consoleLogger = new ConsoleLogger();
consoleLogger.setName('bolt-app');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone has suggestions for the default name, leave comments here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine to me

if (typeof logger === 'undefined') {
// Initialize with the default logger
const consoleLogger = new ConsoleLogger();
consoleLogger.setName('bolt-app');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine to me

logger = new ConsoleLogger(),
logLevel = LogLevel.INFO,
logger = undefined,
logLevel = undefined,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we still setting LogLevel.INFO as the default somewhere? Looks like we lost that logic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay rad!

@seratch
Copy link
Member Author

seratch commented Feb 18, 2020

@stevengill Thanks for your review!
Once I get approval on this, we can merge this. Also, I will make a PR for the v2 branch.

@seratch
Copy link
Member Author

seratch commented Feb 19, 2020

@stevengill This one seems to already look good to you but just in case can you approve this? (no rush)

@seratch seratch merged commit 217fe72 into slackapi:master Feb 19, 2020
@seratch seratch deleted the issue-405 branch February 19, 2020 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:minor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to specify log level in Bolt >= 1.4.0
2 participants