Merge pull request #41 from bcornec/logfile
Fix #39 with new log files management
This commit is contained in:
commit
ce55371ed5
@ -23,7 +23,7 @@ if HOME == '':
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
with open(HOME + "/.redfish.conf") as json_data:
|
||||
with open(HOME + "/.redfish/inventory") as json_data:
|
||||
config = json.load(json_data)
|
||||
json_data.close()
|
||||
except IOError as e:
|
||||
|
@ -21,7 +21,7 @@ if HOME == '':
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
with open(HOME + "/.redfish.conf") as json_data:
|
||||
with open(HOME + "/.redfish/inventory") as json_data:
|
||||
config = json.load(json_data)
|
||||
json_data.close()
|
||||
except IOError as e:
|
||||
|
@ -20,12 +20,12 @@ redfish-client ::
|
||||
-h --help Show this screen.
|
||||
--version Show version.
|
||||
-c --config FILE Configuration file
|
||||
-i --inventory FILE Configuration file [default: $HOME/.redfish.conf]
|
||||
-i --inventory FILE Configuration file [default: $HOME/.redfish/inventory]
|
||||
--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>
|
||||
@ -61,7 +61,7 @@ class InventoryFile(object):
|
||||
If the file does not exist create an empty one ready to receive data
|
||||
|
||||
:param inventory_file: File name of the configuration file
|
||||
default: ~/.redfish.conf
|
||||
default: ~/.redfish/inventory
|
||||
:type config-file: str
|
||||
:returns: Nothing
|
||||
|
||||
@ -337,16 +337,6 @@ if __name__ == '__main__':
|
||||
logger.info("Arguments parsed")
|
||||
logger.debug(arguments)
|
||||
|
||||
# Get $HOME environment variables.
|
||||
HOME = os.getenv('HOME')
|
||||
|
||||
if(not HOME):
|
||||
print('ERROR: $HOME environment variable not set,' +
|
||||
'please check your system')
|
||||
logger.error('$HOME environment variable not set')
|
||||
sys.exit(1)
|
||||
logger.debug("Home directory : %s" % HOME)
|
||||
|
||||
# Load config
|
||||
config = configparser.ConfigParser(allow_no_value=True)
|
||||
logger.debug("Read configuration file")
|
||||
@ -365,8 +355,7 @@ if __name__ == '__main__':
|
||||
logger.error('Configuration file not found at %s.' % configfile)
|
||||
sys.exit(1)
|
||||
|
||||
arguments['--inventory'] = arguments['--inventory'].replace('~', HOME)
|
||||
arguments['--inventory'] = arguments['--inventory'].replace('$HOME', HOME)
|
||||
arguments['--inventory'] = os.path.expandvars(arguments['--inventory'])
|
||||
inventory = InventoryFile(arguments['--inventory'])
|
||||
|
||||
# Initialize Template system (jinja2)
|
||||
|
@ -5,18 +5,36 @@ from __future__ import print_function
|
||||
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)
|
||||
|
||||
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'
|
||||
)
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user