Skip to content

Commit 0abee72

Browse files
committedJul 10, 2015
Merge pull request #1866 from getnikola/logging
Remove custom log handlers
2 parents 77a5b46 + a2cd345 commit 0abee72

21 files changed

+32
-200
lines changed
 

‎CHANGES.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ New in master
44
Features
55
--------
66

7+
* Remove logging handlers (Issue #1797)
78
* Add ``-d``, ``--detach`` option to ``nikola serve`` (Issue #1871)
89
* Use provided teaser format (``*_READ_MORE_LINK``) with custom teaser text
910
(Issue #1879)

‎nikola/__main__.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
from . import __version__
5050
from .plugin_categories import Command
5151
from .nikola import Nikola
52-
from .utils import sys_decode, sys_encode, get_root_dir, req_missing, LOGGER, STRICT_HANDLER, ColorfulStderrHandler
52+
from .utils import sys_decode, sys_encode, get_root_dir, req_missing, LOGGER, STRICT_HANDLER, STDERR_HANDLER, ColorfulStderrHandler
5353

5454
if sys.version_info[0] == 3:
5555
import importlib.machinery
@@ -88,13 +88,18 @@ def main(args=None):
8888
break
8989

9090
quiet = False
91+
strict = False
9192
if len(args) > 0 and args[0] == 'build' and '--strict' in args:
9293
LOGGER.notice('Running in strict mode')
9394
STRICT_HANDLER.push_application()
95+
strict = True
9496
if len(args) > 0 and args[0] == 'build' and '-q' in args or '--quiet' in args:
95-
nullhandler = NullHandler()
96-
nullhandler.push_application()
97+
NullHandler().push_application()
9798
quiet = True
99+
if not quiet and not strict:
100+
NullHandler().push_application()
101+
STDERR_HANDLER[0].push_application()
102+
98103
global config
99104

100105
original_cwd = os.getcwd()

‎nikola/conf.py.in

-20
Original file line numberDiff line numberDiff line change
@@ -925,26 +925,6 @@ UNSLUGIFY_TITLES = True
925925
# sometimes crash Nikola, your web server, or eat your cat.
926926
# USE_SLUGIFY = True
927927

928-
# You can configure the logging handlers installed as plugins or change the
929-
# log level of the default stderr handler.
930-
# WARNING: The stderr handler allows only the loglevels of 'INFO' and 'DEBUG'.
931-
# This is done for safety reasons, as blocking out anything other
932-
# than 'DEBUG' may hide important information and break the user
933-
# experience!
934-
935-
LOGGING_HANDLERS = {
936-
'stderr': {'loglevel': 'INFO', 'bubble': True},
937-
# 'smtp': {
938-
# 'from_addr': 'test-errors@example.com',
939-
# 'recipients': ('test@example.com'),
940-
# 'credentials':('testusername', 'password'),
941-
# 'server_addr': ('127.0.0.1', 25),
942-
# 'secure': (),
943-
# 'level': 'DEBUG',
944-
# 'bubble': True
945-
# }
946-
}
947-
948928
# Templates will use those filters, along with the defaults.
949929
# Consult your engine's documentation on filters if you need help defining
950930
# those.

‎nikola/nikola.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def __init__(self, **config):
281281
self._template_system = None
282282
self._THEMES = None
283283
self.debug = DEBUG
284-
self.loghandlers = []
284+
self.loghandlers = utils.STDERR_HANDLER # TODO remove on v8
285285
self.colorful = config.pop('__colorful__', False)
286286
self.invariant = config.pop('__invariant__', False)
287287
self.quiet = config.pop('__quiet__', False)

‎nikola/plugins/command/auto/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959

6060
from nikola.plugin_categories import Command
61-
from nikola.utils import req_missing, get_logger, get_theme_path
61+
from nikola.utils import req_missing, get_logger, get_theme_path, STDERR_HANDLER
6262
LRJS_PATH = os.path.join(os.path.dirname(__file__), 'livereload.js')
6363
error_signal = signal('error')
6464
refresh_signal = signal('refresh')
@@ -116,7 +116,7 @@ class CommandAuto(Command):
116116
def _execute(self, options, args):
117117
"""Start the watcher."""
118118

119-
self.logger = get_logger('auto', self.site.loghandlers)
119+
self.logger = get_logger('auto', STDERR_HANDLER)
120120
LRSocket.logger = self.logger
121121

122122
if WebSocket is object and watchdog is None:

‎nikola/plugins/command/check.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import requests
4141

4242
from nikola.plugin_categories import Command
43-
from nikola.utils import get_logger
43+
from nikola.utils import get_logger, STDERR_HANDLER
4444

4545

4646
def _call_nikola_list(site):
@@ -147,7 +147,7 @@ class CommandCheck(Command):
147147

148148
def _execute(self, options, args):
149149
"""Check the generated site."""
150-
self.logger = get_logger('check', self.site.loghandlers)
150+
self.logger = get_logger('check', STDERR_HANDLER)
151151

152152
if not options['links'] and not options['files'] and not options['clean']:
153153
print(self.help())

‎nikola/plugins/command/deploy.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from blinker import signal
3636

3737
from nikola.plugin_categories import Command
38-
from nikola.utils import get_logger, remove_file, unicode_str, makedirs
38+
from nikola.utils import get_logger, remove_file, unicode_str, makedirs, STDERR_HANDLER
3939

4040

4141
class CommandDeploy(Command):
@@ -48,7 +48,7 @@ class CommandDeploy(Command):
4848
logger = None
4949

5050
def _execute(self, command, args):
51-
self.logger = get_logger('deploy', self.site.loghandlers)
51+
self.logger = get_logger('deploy', STDERR_HANDLER)
5252
# Get last successful deploy date
5353
timestamp_path = os.path.join(self.site.config['CACHE_FOLDER'], 'lastdeploy')
5454
if self.site.config['COMMENT_SYSTEM_ID'] == 'nikolademo':

‎nikola/plugins/command/github_deploy.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
from nikola.plugin_categories import Command
3535
from nikola.plugins.command.check import real_scan_files
36-
from nikola.utils import get_logger, req_missing, makedirs, unicode_str
36+
from nikola.utils import get_logger, req_missing, makedirs, unicode_str, STDERR_HANDLER
3737
from nikola.__main__ import main
3838
from nikola import __version__
3939

@@ -71,9 +71,7 @@ class CommandGitHubDeploy(Command):
7171

7272
def _execute(self, command, args):
7373

74-
self.logger = get_logger(
75-
CommandGitHubDeploy.name, self.site.loghandlers
76-
)
74+
self.logger = get_logger(CommandGitHubDeploy.name, STDERR_HANDLER)
7775

7876
# Check if ghp-import is installed
7977
check_ghp_import_installed()

‎nikola/plugins/command/serve.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from http.server import SimpleHTTPRequestHandler # NOQA
3737

3838
from nikola.plugin_categories import Command
39-
from nikola.utils import get_logger
39+
from nikola.utils import get_logger, STDERR_HANDLER
4040

4141

4242
class IPv6Server(HTTPServer):
@@ -97,7 +97,7 @@ class CommandServe(Command):
9797

9898
def _execute(self, options, args):
9999
"""Start test server."""
100-
self.logger = get_logger('serve', self.site.loghandlers)
100+
self.logger = get_logger('serve', STDERR_HANDLER)
101101
out_dir = self.site.config['OUTPUT_FOLDER']
102102
if not os.path.isdir(out_dir):
103103
self.logger.error("Missing '{0}' folder?".format(out_dir))

‎nikola/plugins/compile/ipynb.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
flag = None
5050

5151
from nikola.plugin_categories import PageCompiler
52-
from nikola.utils import makedirs, req_missing, get_logger
52+
from nikola.utils import makedirs, req_missing, get_logger, STDERR_HANDLER
5353

5454

5555
class CompileIPynb(PageCompiler):
@@ -61,7 +61,7 @@ class CompileIPynb(PageCompiler):
6161
default_kernel = 'python2' if sys.version_info[0] == 2 else 'python3'
6262

6363
def set_site(self, site):
64-
self.logger = get_logger('compile_ipynb', site.loghandlers)
64+
self.logger = get_logger('compile_ipynb', STDERR_HANDLER)
6565
super(CompileIPynb, self).set_site(site)
6666

6767
def compile_html(self, source, dest, is_two_file=True):

‎nikola/plugins/compile/rest/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import docutils.writers.html4css1
3737

3838
from nikola.plugin_categories import PageCompiler
39-
from nikola.utils import unicode_str, get_logger, makedirs, write_metadata
39+
from nikola.utils import unicode_str, get_logger, makedirs, write_metadata, STDERR_HANDLER
4040

4141

4242
class CompileRest(PageCompiler):
@@ -133,7 +133,7 @@ def set_site(self, site):
133133
self.config_dependencies.append(plugin_info.name)
134134
plugin_info.plugin_object.short_help = plugin_info.description
135135

136-
self.logger = get_logger('compile_rest', site.loghandlers)
136+
self.logger = get_logger('compile_rest', STDERR_HANDLER)
137137
if not site.debug:
138138
self.logger.level = 4
139139

‎nikola/plugins/loghandler/__init__.py

-25
This file was deleted.

‎nikola/plugins/loghandler/smtp.plugin

-9
This file was deleted.

‎nikola/plugins/loghandler/smtp.py

-54
This file was deleted.

‎nikola/plugins/loghandler/stderr.plugin

-9
This file was deleted.

‎nikola/plugins/loghandler/stderr.py

-56
This file was deleted.

‎nikola/plugins/task/bundles.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class BuildBundles(LateTask):
4343
name = "create_bundles"
4444

4545
def set_site(self, site):
46-
self.logger = utils.get_logger('bundles', site.loghandlers)
46+
self.logger = utils.get_logger('bundles', utils.STDERR_HANDLER)
4747
if webassets is None and site.config['USE_BUNDLES']:
4848
utils.req_missing(['webassets'], 'USE_BUNDLES', optional=True)
4949
self.logger.warn('Setting USE_BUNDLES to False.')

‎nikola/plugins/task/galleries.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def set_site(self, site):
6565
site.register_path_handler('gallery_global', self.gallery_global_path)
6666
site.register_path_handler('gallery_rss', self.gallery_rss_path)
6767

68-
self.logger = utils.get_logger('render_galleries', site.loghandlers)
68+
self.logger = utils.get_logger('render_galleries', utils.STDERR_HANDLER)
6969

7070
self.kw = {
7171
'thumbnail_size': site.config['THUMBNAIL_SIZE'],

‎nikola/plugins/task/scale_images.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ScaleImage(Task, ImageProcessor):
3737
name = "scale_images"
3838

3939
def set_site(self, site):
40-
self.logger = utils.get_logger('scale_images', site.loghandlers)
40+
self.logger = utils.get_logger('scale_images', utils.STDERR_HANDLER)
4141
return super(ScaleImage, self).set_site(site)
4242

4343
def process_tree(self, src, dst):

‎nikola/utils.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import warnings
4848
import PyRSS2Gen as rss
4949
from collections import defaultdict, Callable
50+
from logbook.compat import redirect_logging
5051
from logbook.more import ExceptionHandler, ColorizedStderrHandler
5152
from pygments.formatters import HtmlFormatter
5253
from zipfile import ZipFile as zipf
@@ -116,14 +117,14 @@ def get_logger(name, handlers):
116117
level=logbook.INFO if not DEBUG else logbook.DEBUG,
117118
format_string=u'[{record.time:%Y-%m-%dT%H:%M:%SZ}] {record.level_name}: {record.channel}: {record.message}'
118119
)]
120+
121+
119122
LOGGER = get_logger('Nikola', STDERR_HANDLER)
120123
STRICT_HANDLER = ExceptionHandler(ApplicationWarning, level='WARNING')
121124

122125
USE_SLUGIFY = True
123126

124-
# This will block out the default handler and will hide all unwanted
125-
# messages, properly.
126-
logbook.NullHandler().push_application()
127+
redirect_logging()
127128

128129
if DEBUG:
129130
logging.basicConfig(level=logging.DEBUG)

‎tests/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def __init__(self):
218218
"MarkdownExtension": MarkdownExtension,
219219
"RestExtension": RestExtension
220220
})
221-
self.loghandlers = [nikola.utils.STDERR_HANDLER]
221+
self.loghandlers = nikola.utils.STDERR_HANDLER # TODO remove on v8
222222
self.plugin_manager.setPluginInfoExtension('plugin')
223223
if sys.version_info[0] == 3:
224224
places = [

0 commit comments

Comments
 (0)
Please sign in to comment.