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:
parent
08e4673bd1
commit
65c8ac92e1
@ -24,8 +24,8 @@ redfish-client ::
|
|||||||
--insecure Ignore SSL certificates
|
--insecure Ignore SSL certificates
|
||||||
--debug LEVEL Run in debug mode, LEVEL from 1 to 3 increase verbosity
|
--debug LEVEL Run in debug mode, LEVEL from 1 to 3 increase verbosity
|
||||||
Security warning LEVEL > 1 could reveal password into the logs
|
Security warning LEVEL > 1 could reveal password into the logs
|
||||||
--debugfile FILE Specify the client debugfile [default: /var/log/python-redfish/redfish-client.log]
|
--debugfile FILE Specify the client debugfile [default: $HOME/.redfish/redfish-client.log]
|
||||||
--libdebugfile FILE Specify python-redfish library log file [default: /var/log/python-redfish/python-redfish.log]
|
--libdebugfile FILE Specify python-redfish library log file [default: $HOME/.redfish/python-redfish.log]
|
||||||
|
|
||||||
config commands : manage the configuration file.
|
config commands : manage the configuration file.
|
||||||
manager commands : manage the manager (Light out management). If <manager_name>
|
manager commands : manage the manager (Light out management). If <manager_name>
|
||||||
|
@ -16,7 +16,22 @@ from logging.handlers import RotatingFileHandler
|
|||||||
|
|
||||||
logger = None
|
logger = None
|
||||||
TORTILLADEBUG = True
|
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
|
CONSOLE_LOGGER_LEVEL = logging.DEBUG
|
||||||
FILE_LOGGER_LEVEL = logging.DEBUG
|
FILE_LOGGER_LEVEL = logging.DEBUG
|
||||||
|
|
||||||
@ -43,14 +58,13 @@ def initialize_logger(REDFISH_LOGFILE,
|
|||||||
formatter = logging.Formatter(
|
formatter = logging.Formatter(
|
||||||
'%(asctime)s :: %(levelname)s :: %(message)s'
|
'%(asctime)s :: %(levelname)s :: %(message)s'
|
||||||
)
|
)
|
||||||
|
f = open(os.path.expandvars(REDFISH_LOGFILE), 'w')
|
||||||
|
f.close()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
file_handler = RotatingFileHandler(REDFISH_LOGFILE, 'a', 1000000, 1)
|
file_handler = RotatingFileHandler(os.path.expandvars(REDFISH_LOGFILE), 'a', 1000000, 1)
|
||||||
except IOError:
|
except IOError:
|
||||||
print('ERROR: {} does not exist or is not writeable.\n'.format(REDFISH_LOGFILE))
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
# First logger to file
|
# First logger to file
|
||||||
|
Loading…
x
Reference in New Issue
Block a user