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

Adds logfile and loglevel optional parameters #63

Merged
merged 1 commit into from
Oct 31, 2016

Conversation

mracine
Copy link
Contributor

@mracine mracine commented Oct 27, 2016

Addresses #46, please review.

Note: logging defaults to stdout, DEBUG level. Parameters can be specified via command line or in config.json file.

Copy link
Member

@sjrct sjrct left a comment

Choose a reason for hiding this comment

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

This is mergable as is. I added a couple comments that could be improvements, though. Should probably give a nice error message when the log level is invalid too. I also, personally, prefer --log-level and --log-file to --loglevel and --logfile, but perhaps that is just opinion.

loglevel = logging.DEBUG
loglevel_str = "DEBUG"
loglevels = { "CRITICAL": logging.CRITICAL, "ERROR": logging.ERROR, "WARNING": logging.WARNING, "INFO": logging.INFO,
"DEBUG": logging.DEBUG, "NOTSET": logging.NOTSET }
Copy link
Member

Choose a reason for hiding this comment

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

Might be easier on the eyes to have these on separate lines rather than two longish ones

loglevel_str = args.loglevel
elif "loglevel" in bot.config:
loglevel = loglevels[bot.config["loglevel"]]
loglevel_str = bot.config["loglevel"]
Copy link
Member

Choose a reason for hiding this comment

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

Could just put loglevel = loglevels[loglevel_str] after the if/else block. Would also allow you to chop off line 69. Would then have a common place to check for a bad log level too.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with this, loglevel assignment can be factored out to make it a bit clearer

bot = halibot.Halibot()
bot._load_config()
Copy link
Contributor

Choose a reason for hiding this comment

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

Not an issue, but the config will be loaded twice when running a bot.

I think this is more arguments that we need some kind of solution to #57

@coveralls
Copy link

coveralls commented Oct 27, 2016

Coverage Status

Coverage remained the same at 68.537% when pulling c34604d on mracine:issue-46 into 6dedad2 on Halibot:master.


# Error check log level string
if loglevel_str not in loglevels:
print("Log level {} invalid. Continuing with log level {}".format(loglevel_str, loglevel))
Copy link
Contributor

Choose a reason for hiding this comment

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

This will print ...Continuing with log level 10 I think. I have no issue with this, but it might just be worth defaulting to saying "DEBUG" there too

Copy link
Contributor

Choose a reason for hiding this comment

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

Or should this be a runtime error? Passing an invalid log should maybe just be irrecoverable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, you're right. And it doesn't matter to me, should it just throw a runtime error in that case?

Copy link
Contributor

Choose a reason for hiding this comment

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

@sjrct Thoughts on this? I'm starting to think that this should be an error, since it implies misconfiguration. Rather than have it limp along, should it just give up and yell at you?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, this should be a runtime error. Should fail like any other incorrectly specified argument.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 68.537% when pulling 4766075 on mracine:issue-46 into 6021e52 on Halibot:master.

@richteer
Copy link
Contributor

richteer commented Oct 28, 2016

Huh, the build broke on 3.5 for some reason, but I can't see anything related to it in this commit; looks like a fluke to me. Unless @sjrct has any complaints about that, I might just merge it anyway.

@sjrct
Copy link
Member

sjrct commented Oct 31, 2016

I have no complaints

@sjrct sjrct merged commit 1c5118c into Halibot:master Oct 31, 2016
@sjrct
Copy link
Member

sjrct commented Oct 31, 2016

We should certainly fix that problem though...

@richteer richteer mentioned this pull request Sep 14, 2017
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

Successfully merging this pull request may close these issues.

4 participants