Skip to content

Instantly share code, notes, and snippets.

@photofroggy
Created November 7, 2011 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save photofroggy/1343886 to your computer and use it in GitHub Desktop.
Save photofroggy/1343886 to your computer and use it in GitHub Desktop.
import os
import os.path
from stutter import logging
class ChannelLogger(logging.ThreadedLogger):
""" Channel-concious logger.
This logger hopefully manages to save logs for different channels in
appropriate sub folders of the logging directory.
"""
def __init__(self, default_ns=None, *args, **kwargs):
super(ChannelLogger, self).__init__(*args, **kwargs)
self.default_ns = default_ns or '~Global'
def _fname(self, timestamp, ns=None, showns=True):
""" Return a file name based on the given input. """
ns = ns or self.default_ns
cdir = '{0}/{1}'.format(self.save_folder, ns)
if not os.path.exists(cdir):
os.mkdir(cdir, 0o755)
return '{0}/{1}.txt'.format(cdir, time.strftime('%Y-%m-%d', time.localtime(timestamp)))
def _display(self, lower, message, timestamp, ns=None, showns=True):
""" Display the message. """
if lower:
return
ns = ns or self.default_ns
mns = '{0}|'.format(ns) if showns else ''
self.stdout('{0}{1}{2}\n'.format(self.time(timestamp), mns, message))
# EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment