Fix #39 with new log files management

- Default location for log files is now under the HOME directory of the
  user instead of /var/log
- Create that default .redfish dir if not already existing
- Adapt error messages
This commit is contained in:
Bruno Cornec 2016-04-02 03:07:41 +02:00
parent 08e4673bd1
commit 65c8ac92e1
2 changed files with 22 additions and 8 deletions

View File

@ -24,8 +24,8 @@ redfish-client ::
--insecure Ignore SSL certificates
--debug LEVEL Run in debug mode, LEVEL from 1 to 3 increase verbosity
Security warning LEVEL > 1 could reveal password into the logs
--debugfile FILE Specify the client debugfile [default: /var/log/python-redfish/redfish-client.log]
--libdebugfile FILE Specify python-redfish library log file [default: /var/log/python-redfish/python-redfish.log]
--debugfile FILE Specify the client debugfile [default: $HOME/.redfish/redfish-client.log]
--libdebugfile FILE Specify python-redfish library log file [default: $HOME/.redfish/python-redfish.log]
config commands : manage the configuration file.
manager commands : manage the manager (Light out management). If <manager_name>

View File

@ -16,7 +16,22 @@ from logging.handlers import RotatingFileHandler
logger = None
TORTILLADEBUG = True
REDFISH_LOGFILE = "/var/log/python-redfish/python-redfish.log"
HOME = os.getenv('HOME')
if HOME == '':
print("$HOME environment variable not set, please check your system")
sys.exit(1)
REDFISH_HOME = 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)
REDFISH_LOGFILE = REDFISH_HOME + "/python-redfish.log"
CONSOLE_LOGGER_LEVEL = logging.DEBUG
FILE_LOGGER_LEVEL = logging.DEBUG
@ -43,14 +58,13 @@ def initialize_logger(REDFISH_LOGFILE,
formatter = logging.Formatter(
'%(asctime)s :: %(levelname)s :: %(message)s'
)
f = open(os.path.expandvars(REDFISH_LOGFILE), 'w')
f.close()
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)))
sys.exit(1)
# First logger to file