Pathead
Pathead

Reputation: 778

popen returns error when executing python script containing logging

I have 2 python scripts where 1 is using subprocess to execute the other, see below:

main.py

import subprocess

command = ['python', 'logging_test.py']
proc1 = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

out, err = proc1.communicate()

print('Output returned from command: {}'.format(out))
print('Error returned from command: {}'.format(err))

logging_test.py

import logging

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('log')
logger.info('hello')

When running main.py I get this as the output:

Output returned from command:
Error returned from command: INFO:log:hello

I would expect for the log message to be returned by stdout, not stderr... Does anyone know why it is getting returned as an error?

Upvotes: 0

Views: 34

Answers (1)

chepner
chepner

Reputation: 531718

basicConfig, among other things, provides a StreamHandler for the root logger. By default, a new StreamHandler writes to standard error.

Upvotes: 1

Related Questions