Author |
Message
|
bobbee |
Posted: Tue Jul 19, 2022 7:43 am Post subject: Python Host/node name in Logging file name |
|
|
Knight
Joined: 20 Sep 2001 Posts: 545 Location: Tampa
|
I am writing an MQ Configuration Check script. I would like to add the host/node name to the file name. I looked at alot of Google search results on the subject. No one seems to use a logging.conf file. I tried implementing 'some' of what looked like what would fit. No luck. Anyone? Here is the logging.conf file. As a last resort I can add the host/node name to the message.
Code: |
[loggers]
keys=root,MQHardening
[handlers]
keys=fileHandler
[formatters]
keys=MQHardening
[logger_root]
level=DEBUG
handlers=fileHandler
[logger_MQHardening]
level=DEBUG
handlers=fileHandler
qualname=MQHardening
propagate=0
[handler_fileHandler]
class=FileHandler
level=DEBUG
formatter=MQHardening
args=(__import__("datetime").datetime.now().strftime('/var/mqm/hardening/MQHardening_%%Y-%%m-%%d_%%H-%%M-%%S.log'), 'a')
####### args=('MQHardening.log', 'w')
[formatter_MQHardening]
format=%(asctime)s - %(levelname)s - %(message)s |
|
|
Back to top |
|
|
gbaddeley |
Posted: Tue Jul 19, 2022 3:37 pm Post subject: |
|
|
Jedi Knight
Joined: 25 Mar 2003 Posts: 2527 Location: Melbourne, Australia
|
/var/mqm/hardening ? Is this a local MQ hardening / checking solution at your company ? It's not part of the MQ product, and shouldn't be in /var/mqm, as it may interfere with the IBM MQ installation or configuration. _________________ Glenn |
|
Back to top |
|
|
hughson |
Posted: Tue Jul 19, 2022 10:11 pm Post subject: |
|
|
Padawan
Joined: 09 May 2013 Posts: 1948 Location: Bay of Plenty, New Zealand
|
Your question is unclear. Are you asking how to obtain the current host/node name (in order to put them as part of a file name) in Python?
Cheers,
Morag _________________ Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
Get your IBM MQ training here!
MQGem Software |
|
Back to top |
|
|
bobbee |
Posted: Wed Jul 20, 2022 3:13 am Post subject: |
|
|
Knight
Joined: 20 Sep 2001 Posts: 545 Location: Tampa
|
I can get the Server/Node name. That is easy. Getting it into the name of the log file..........well.
I went the logging.conf file route. All the examples I see are setting the logging variables programmatically. I was looking for an example, but I feel I may have to change the code to do it programmatically. |
|
Back to top |
|
|
bobbee |
Posted: Wed Jul 20, 2022 3:16 am Post subject: |
|
|
Knight
Joined: 20 Sep 2001 Posts: 545 Location: Tampa
|
@gbaddeley,
Customer.
That was on a test AIX box I provisioned inside my own company. When I moved it to the customers server the location changed to something more appropriate. Thanks for Policing. |
|
Back to top |
|
|
hughson |
Posted: Wed Jul 20, 2022 3:30 am Post subject: |
|
|
Padawan
Joined: 09 May 2013 Posts: 1948 Location: Bay of Plenty, New Zealand
|
Do you mean that you are trying to use this: https://docs.python.org/3/library/logging.config.html
?
I use the same logging but have never used the config file, just called logging.basicConfig - I guess I didn't need whatever complexity you are after.
Suggest Stackoverflow might be a better forum for your question than here?
Cheers,
Morag _________________ Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
Get your IBM MQ training here!
MQGem Software |
|
Back to top |
|
|
bobbee |
Posted: Wed Jul 20, 2022 3:39 am Post subject: |
|
|
Knight
Joined: 20 Sep 2001 Posts: 545 Location: Tampa
|
Yes, EXACTLY!!
There was some education and video stuff on a UNIX forum for logging.conf . I found the creators name and sent him an email with the same question. But, that is a crap shoot.
When I have the time, I guess my route is to change the code. In the long run it will make changes easier. I can move the important stuff from the logging.conf file up to my main properties file and stilll have control.
You know what is going to happen? When I find the time, change it, get it tested and working, the guy will answer me..................and it will be simple!!!! LOL
They are going to run this script on all their QMGRS to get them in internal compliance and keep them that way. Not really Hardening, but that is what they want to name them. If they start uploading these to a repository I wanted the server name in the file name to distinguish them apart. |
|
Back to top |
|
|
gbaddeley |
Posted: Wed Jul 20, 2022 4:12 pm Post subject: |
|
|
Jedi Knight
Joined: 25 Mar 2003 Posts: 2527 Location: Melbourne, Australia
|
Code: |
args=(__import__("datetime").datetime.now().strftime('/var/mqm/hardening/MQHardening_%%Y-%%m-%%d_%%H-%%M-%%S.log'), 'a') |
Does this actually work, to include date time in the log file name?
args calls eval. Can eval be used to build up a formatted string with two { } expressions, containing code like strftime('%%Y-%%m-%%d_%%H-%%M-%%S), and os.environ['HOSTNAME'] ?
Sorry, I'm not an experienced python programmer, and haven't tried anything like this in eval. _________________ Glenn |
|
Back to top |
|
|
bobbee |
Posted: Thu Jul 21, 2022 3:16 am Post subject: |
|
|
Knight
Joined: 20 Sep 2001 Posts: 545 Location: Tampa
|
It has been working from the very start. This is the name of the file in my log directory:
MQHardening_2022-07-05_07-56-16.log
If you dig down into the logger doc. There are one or two things that are supported in naming the logger file. |
|
Back to top |
|
|
gbaddeley |
Posted: Thu Jul 21, 2022 3:17 pm Post subject: |
|
|
Jedi Knight
Joined: 25 Mar 2003 Posts: 2527 Location: Melbourne, Australia
|
bobbee wrote: |
If you dig down into the logger doc. |
Good luck. Sorry, I don't have time to pursue this any further atm. _________________ Glenn |
|
Back to top |
|
|
bobbee |
Posted: Fri Jul 22, 2022 3:18 am Post subject: |
|
|
Knight
Joined: 20 Sep 2001 Posts: 545 Location: Tampa
|
no problem, just did my 1/2 year review and under skill put down, 'Became proficient in Python Pymqi, LOL |
|
Back to top |
|
|
|