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

DM-15361: Enable logging to Python streams. #33

Merged
merged 2 commits into from Apr 8, 2021
Merged

Conversation

ktlim
Copy link
Contributor

@ktlim ktlim commented Sep 11, 2018

This allows log output to go to Jupyter notebook cells.

@andy-slac
Copy link
Contributor

This is not just for logging only - it takes anything written to a file descriptor and sends it somewhere? Can't we implement special appender for log4cxx to write directly to Python object?

@ktlim
Copy link
Contributor Author

ktlim commented Sep 11, 2018

In a notebook environment, nothing else should be writing to the file descriptor. I thought this would be a quick, Python-only way to start getting the desired functionality. Writing a log4cxx appender seemed more difficult.

@andy-slac
Copy link
Contributor

Implementing log4cxx appender should not be hard, the only non-trivial question is how to configure log4cxx, but that can be done through some special utility method. Anyways, I'm OK with this initial implementation. Maybe if we can provide a more abstract API for enabling redirection then we can re-implement it later in a different way without need to change user code, e.g:

def enable_notebook_logging():
    """Enable notebook output for log4cxx messages."""
    # current implementation
    global redirect
    redirect = LogRedirect()

def disable_notebook_logging():
    """Stop notebook output for log4cxx messages."""
    # current implementation
    global redirect
    redirect.finish()

@@ -37,3 +41,62 @@ def traceSetAt(name, number):
for i in range(6):
level = Log.INFO if i > number else Log.DEBUG
Log.getLogger('TRACE%d.%s' % (i, name)).setLevel(level)


class LogRedirect:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like singletons but this should not be allowed to be instantiated more than once.

@timj timj changed the title Enable logging to Python streams. DM-15361: Enable logging to Python streams. Feb 2, 2019
@ktlim ktlim force-pushed the tickets/DM-15361 branch 5 times, most recently from dd80801 to 26d876a Compare April 8, 2021 20:41
@ktlim ktlim merged commit f1b3ebf into master Apr 8, 2021
@ktlim ktlim deleted the tickets/DM-15361 branch April 8, 2021 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants