Commit 28f5de90 authored by Sam Ruby's avatar Sam Ruby

Support verbose option again

parent b25df8b9
......@@ -25,7 +25,7 @@ from htmlentitydefs import entitydefs
import planet
from planet import config, feedparser
from planet.spider import filename
log = planet.getLogger(config.log_level(),config.log_format())
log = planet.logger
options = config.filter_options(sys.argv[0])
MEMES_ATOM = os.path.join(config.output_dir(),'memes.atom')
......
xmlns = 'http://planet.intertwingly.net/'
logger = None
loggerParms = None
import os, sys, re
import config
......@@ -11,8 +12,8 @@ from urlparse import urljoin
def getLogger(level, format):
""" get a logger with the specified log level """
global logger
if logger: return logger
global logger, loggerParms
if logger and loggerParms == (level,format): return logger
try:
import logging
......@@ -21,13 +22,14 @@ def getLogger(level, format):
import compat_logging as logging
logging.basicConfig(format=format)
logging.getLogger().setLevel(logging.getLevelName(level))
logger = logging.getLogger("planet.runner")
logger.setLevel(logging.getLevelName(level))
try:
logger.warning
except:
logger.warning = logger.warn
loggerParms = (level,format)
return logger
# Configure feed parser
......
......@@ -139,7 +139,9 @@ def load(config_file):
import config, planet
from planet import opml, foaf
log = planet.getLogger(config.log_level(),config.log_format())
log = planet.logger
if not log:
log = planet.getLogger(config.log_level(),config.log_format())
# Theme support
theme = config.output_theme()
......
......@@ -5,8 +5,7 @@ from spider import filename
def expungeCache():
""" Expunge old entries from a cache of entries """
import planet
log = planet.getLogger(config.log_level(),config.log_format())
log = planet.logger
log.info("Determining feed subscriptions")
entry_count = {}
......
......@@ -6,7 +6,7 @@ logged_modes = []
def run(template_file, doc, mode='template'):
""" select a template module based on file extension and execute it """
log = planet.getLogger(planet.config.log_level(),planet.config.log_format())
log = planet.logger
if mode == 'template':
dirs = planet.config.template_directories()
......
......@@ -329,7 +329,7 @@ def httpThread(thread_index, input_queue, output_queue, log):
def spiderPlanet(only_if_new = False):
""" Spider (fetch) an entire planet """
log = planet.getLogger(config.log_level(),config.log_format())
log = planet.logger
global index
index = True
......
......@@ -9,7 +9,7 @@ from planet import idindex
def splice():
""" Splice together a planet from a cache of entries """
import planet
log = planet.getLogger(config.log_level(),config.log_format())
log = planet.logger
log.info("Loading cached data")
cache = config.cache_directory()
......@@ -109,7 +109,7 @@ def splice():
def apply(doc):
output_dir = config.output_dir()
if not os.path.exists(output_dir): os.makedirs(output_dir)
log = planet.getLogger(config.log_level(),config.log_format())
log = planet.logger
planet_filters = config.filters('Planet')
......
......@@ -15,7 +15,7 @@ configfile = 'tests/data/expunge/config.ini'
class ExpungeTest(unittest.TestCase):
def setUp(self):
# silence errors
planet.logger = None
self.original_logger = planet.logger
planet.getLogger('CRITICAL',None)
try:
......@@ -29,6 +29,7 @@ class ExpungeTest(unittest.TestCase):
def tearDown(self):
shutil.rmtree(workdir)
os.removedirs(os.path.split(workdir)[0])
planet.logger = self.original_logger
def test_expunge(self):
config.load(configfile)
......
#!/usr/bin/env python
import unittest
from planet import idindex, config, logger
import unittest, planet
from planet import idindex, config
class idIndexTest(unittest.TestCase):
def setUp(self):
# silence errors
import planet
planet.logger = None
self.original_logger = planet.logger
planet.getLogger('CRITICAL',None)
def tearDown(self):
idindex.destroy()
planet.logger = self.original_logger
def test_unicode(self):
from planet.spider import filename
......@@ -69,6 +69,6 @@ class idIndexTest(unittest.TestCase):
try:
module = 'dbhash'
except ImportError:
logger.warn("dbhash is not available => can't test id index")
planet.logger.warn("dbhash is not available => can't test id index")
for method in dir(idIndexTest):
if method.startswith('test_'): delattr(idIndexTest,method)
......@@ -12,7 +12,7 @@ configfile = 'tests/data/spider/config.ini'
class SpiderTest(unittest.TestCase):
def setUp(self):
# silence errors
planet.logger = None
self.original_logger = planet.logger
planet.getLogger('CRITICAL',None)
try:
......@@ -24,6 +24,7 @@ class SpiderTest(unittest.TestCase):
def tearDown(self):
shutil.rmtree(workdir)
os.removedirs(os.path.split(workdir)[0])
planet.logger = self.original_logger
def test_filename(self):
self.assertEqual(os.path.join('.', 'example.com,index.html'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment