Skip to content

Commit

Permalink
ipython friendly logging
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgigante committed Jun 2, 2018
1 parent ee73086 commit 758cd1c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions graphtools/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import logging
import time
import sys


__logger_name__ = "graphtools"
Expand All @@ -14,11 +15,21 @@ class RSafeStdErr(object):
This class writes directly to stderr to avoid this.
"""

def write(self, msg):
os.write(2, bytes(msg, 'utf8'))
def __init__(self):
try:
__IPYTHON__
self.write = self.write_ipython
except NameError:
self.write = self.write_r_safe

def write_ipython(self, msg):
print(msg, end='', file=sys.stdout)

def write_r_safe(self, msg):
os.write(1, bytes(msg, 'utf8'))

def flush(self):
pass
sys.stdout.flush()


class TaskLogger(object):
Expand Down

0 comments on commit 758cd1c

Please sign in to comment.