Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logging in interactive mode #731

Merged
merged 1 commit into from
Apr 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions rdflib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,22 @@
assert sys.version_info >= (2, 7, 0), "rdflib requires Python 2.7 or higher"

import logging
logger = logging.getLogger(__name__)
_interactive_mode = False
try:
import __main__
if not hasattr(__main__, '__file__') and sys.stdout.isatty():
if not hasattr(__main__, '__file__') and sys.stderr.isatty():
# show log messages in interactive mode
_interactive_mode = True
logging.basicConfig(level=logging.INFO)
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler())
del __main__
except ImportError:
#Main already imported from elsewhere
import warnings
warnings.warn('__main__ already imported', ImportWarning)
del warnings

logger = logging.getLogger(__name__)
if _interactive_mode:
logger.info("RDFLib Version: %s" % __version__)
else:
Expand Down