Repository navigation
Fix #39 with new log files management #41
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,18 +5,36 @@ | |
| from __future__ import division | ||
| from __future__ import absolute_import | ||
| from future import standard_library | ||
| standard_library.install_aliases() | ||
| import logging | ||
| import sys | ||
| import os | ||
| import getpass | ||
| from logging.handlers import RotatingFileHandler | ||
| standard_library.install_aliases() | ||
|
|
||
| # Global variable definition | ||
|
|
||
| logger = None | ||
| TORTILLADEBUG = True | ||
| REDFISH_LOGFILE = "/var/log/python-redfish/python-redfish.log" | ||
| HOME = os.getenv('HOME') | ||
| if HOME is None: | ||
| print("$HOME environment variable not set, please check your system") | ||
| sys.exit(1) | ||
| if HOME == '': | ||
| print("$HOME environment is set, but empty, please check your system") | ||
| sys.exit(1) | ||
|
|
||
| REDFISH_HOME = os.path.join(HOME, ".redfish") | ||
| if not os.path.exists(REDFISH_HOME): | ||
| try: | ||
| os.mkdir(REDFISH_HOME) | ||
| except IOError: | ||
| print('ERROR: can\'t create {}.\n'.format(REDFISH_HOME)) | ||
| print(' Try to create directory {}'.format(os.path.dirname(REDFISH_LOGFILE))) | ||
| print(' using: mkdir -p {}'.format(os.path.dirname(REDFISH_LOGFILE))) | ||
| sys.exit(1) | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part should be in the init method, or a function called here and at init step. |
||
| REDFISH_LOGFILE = os.path.join(REDFISH_HOME, "python-redfish.log") | ||
| CONSOLE_LOGGER_LEVEL = logging.DEBUG | ||
| FILE_LOGGER_LEVEL = logging.DEBUG | ||
|
|
||
|
|
@@ -43,14 +61,13 @@ def initialize_logger(REDFISH_LOGFILE, | |
| formatter = logging.Formatter( | ||
| '%(asctime)s :: %(levelname)s :: %(message)s' | ||
| ) | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To my mind it is not needed. I guess you want to create the file, but that will be handled by RotatingFileHandler.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without this, in case the file doesn't exist yet, it's not created by RotatingFileHandler. I experienced that thus added these 2 lines. I'm not sure I undertand why we need a with here, but let's discuss this afternoon. |
||
| try: | ||
| file_handler = RotatingFileHandler(REDFISH_LOGFILE, 'a', 1000000, 1) | ||
| file_handler = RotatingFileHandler(os.path.expandvars(REDFISH_LOGFILE), 'a', 1000000, 1) | ||
| except IOError: | ||
| print('ERROR: {} does not exist or is not writeable.\n'.format(REDFISH_LOGFILE)) | ||
| print('1- Try to create directory {}'.format(os.path.dirname(REDFISH_LOGFILE))) | ||
| print(' using: sudo mkdir -p {}'.format(os.path.dirname(REDFISH_LOGFILE))) | ||
| print('2- Try to get the {} ownership'.format(os.path.dirname(REDFISH_LOGFILE))) | ||
| print(' using: sudo chown {} {}'.format(getpass.getuser(), os.path.dirname(REDFISH_LOGFILE))) | ||
| print(' Try to create directory {}'.format(os.path.dirname(REDFISH_LOGFILE))) | ||
| print(' using: mkdir -p {}'.format(os.path.dirname(REDFISH_LOGFILE))) | ||
| sys.exit(1) | ||
|
|
||
| # First logger to file | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, so we should remove that check in the redfish-client to be DRY.