From 05a9955513ef3dbb8a079c57556e1e806536c31a Mon Sep 17 00:00:00 2001 From: chris Date: Sun, 16 Feb 2014 23:31:55 +0100 Subject: [PATCH] use logging module instead of print(). --- blogtopoid/blogtopoid.py | 5 ++--- blogtopoid/commands.py | 8 ++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/blogtopoid/blogtopoid.py b/blogtopoid/blogtopoid.py index b94a9b0..8d3c2d8 100644 --- a/blogtopoid/blogtopoid.py +++ b/blogtopoid/blogtopoid.py @@ -12,6 +12,7 @@ import glob import codecs import shutil import hashlib +import logging import datetime try: import ConfigParser @@ -115,9 +116,6 @@ class Post(object): """ generate post html and write to disk """ config = Config() - print("writing {}".format(os.path.join(config.outputdir, - self.outfile))) - # parse front matter re_yaml = re.compile(r'(^---\s*$(?P.*?)^---\s*$)' '?(?P.*)', re.M | re.S) @@ -338,5 +336,6 @@ def write_file(filename, content): :param filename: filename to write to :param content: content to write """ + logging.getLogger('blogtopoid').info('writing %s', filename) with codecs.open(filename, 'w', 'utf-8') as afile: afile.write(content) diff --git a/blogtopoid/commands.py b/blogtopoid/commands.py index b3fa21d..2524ecb 100644 --- a/blogtopoid/commands.py +++ b/blogtopoid/commands.py @@ -6,6 +6,7 @@ from __future__ import absolute_import import os import sys import codecs +import logging try: import ConfigParser except ImportError: @@ -94,6 +95,13 @@ def generate(): """ config = Config() + # set up logging + ch = logging.StreamHandler(sys.stdout) + formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') + ch.setFormatter(formatter) + logging.getLogger('blogtopoid').addHandler(ch) + logging.getLogger('blogtopoid').setLevel(logging.DEBUG) + pages = [] for infile in os.listdir(unicode(config.pagesdir)): if os.path.splitext(infile)[1].lower() in config.supported_blogtypes: