I have this code: -
cmd_output =subprocess.Popen([cmd], shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()
-
log.debug(cmd))
I have a logger defined, and all the logs goes to the file. Now, what I want to do is, log output and error of subprocess to this log_file. Also I can you tell what does it do, when you set stderr=subprocess.PIPE and stdout=subprocess.PIPE, and where does the log get output and errors get written?
2 1993
Logging messages are subjected to a dispatch mechanism through the use of handlers, which are instances of subclasses of the Handler class. Handlers are responsible for ensuring that a logged message (in the form of a LogRecord) ends up in a particular location (or set of locations) which is useful for the target audience for that message (such as end users, support desk staff, system administrators, developers). Handlers are passed LogRecord instances intended for particular destinations. Each logger can have zero, one or more handlers associated with it (via the addHandler() method of Logger). In addition to any handlers directly associated with a logger, all handlers associated with all ancestors of the logger are called to dispatch the message.
Sounds like you need to write the handler; maybe there are default handlers to write files for you.
Sounds like you need to write the handler; maybe there are default handlers to write files for you.
I did setup a handler in a method called LogSetup: -
def LogSetup():
-
log = logging.getLogger("sitelogs")
-
fmt = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
-
-
log.setLevel(logging.DEBUG)
-
fhnd = logging.FileHandler('logs.log', 'a')
-
fhnd.setLevel(logging.DEBUG)
-
fhnd.setFormatter(fmt)
-
log.addHandler(fhnd)
My question how would I use this with subprocess ?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Roman Neuhauser |
last post by:
Hello,
I have a piece of code that gets run in a script that has its stdout
closed:
import sys
sys.stdout = sys.stderr
c = subprocess.Popen (...,
stdin = subprocess.PIPE,
|
by: Darren Dale |
last post by:
I'm a developer on the matplotlib project, and I am having trouble with the
subprocess module on windows (Python 2.4.2 on winXP). No trouble to report
with linux. I need to use _subprocess instead...
|
by: Grant Edwards |
last post by:
I'm trying to use the py-gnuplot module on windows, and have
been unable to get it to work reliably under Win2K and WinXP.
By default, it uses popen(gnuplotcmd,'w'), but in some
situations that...
|
by: Jim |
last post by:
Hello,
I need a program that will traverse a directory tree to ensure that
there
are unix-style line endings on every file in that tree that is a text
file.
To tell text files from others I...
|
by: Eric_Dexter |
last post by:
I am trying to modify a programming example and I am coming up with
two problems... first is that I can't seem to pass along the
arguments to the external command (I have been able to do that with...
|
by: Phoe6 |
last post by:
Hi all,
Consider this scenario, where in I need to use subprocess to execute a
command like 'ping 127.0.0.1' which will have a continuous non-
terminating output in Linux.
# code
# This...
|
by: Dave Sampson |
last post by:
hey folks,
A simple question hopefully. despite all my searching I have not found a
satisfactory response.
The goal. Interact with a command line program. Simple enough, but the
key is...
|
by: bhunter |
last post by:
Hi,
I've used subprocess with 2.4 several times to execute a process, wait
for it to finish, and then look at its output. Now I want to spawn
the process separately, later check to see if it's...
|
by: Harishankar |
last post by:
Hi,
Sorry to start off on a negative note in the list, but I feel that the Python
subprocess module is sorely deficient because it lacks a mechanism to:
1. Create non-blocking pipes which can...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| | |