From 70f91b65f4efe7353df0fe2881d8f5c0fa964c67 Mon Sep 17 00:00:00 2001
From: ulif <uli@gnufix.de>
Date: Tue, 26 Apr 2016 01:56:47 +0200
Subject: [PATCH] Provide a logger, API-wise.

Add a common place where components can write messages to. Any
userinterface can decide, what messages should be visible
(depending on their severity).
---
 diceware/logger.py   | 37 +++++++++++++++++++++++++++++++++++++
 tests/test_logger.py | 11 +++++++++++
 2 files changed, 48 insertions(+)
 create mode 100644 diceware/logger.py
 create mode 100644 tests/test_logger.py

diff --git a/diceware/logger.py b/diceware/logger.py
new file mode 100644
index 0000000..54db8dd
--- /dev/null
+++ b/diceware/logger.py
@@ -0,0 +1,37 @@
+#  diceware -- passphrases to remember
+#  Copyright (C) 2016  Uli Fouquet and contributors
+#
+#  This program is free software: you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation, either version 3 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+"""logging -- output status and other data.
+"""
+import logging
+try:
+    from logging import NullHandler
+except ImportError:  # NOQA  # pragma: no cover
+    class NullHandler(object):
+        """Replacement for `logging.NullHandler` from py3.x standard lib.
+        """
+        def emit(self, record):
+            pass
+
+        def handle(self, record):
+            pass
+
+        def createLock(self):
+            pass
+
+
+#: Logger that can be used for all diceware related messages.
+logger = logging.getLogger("ulif.diceware")
+logger.addHandler(NullHandler())
diff --git a/tests/test_logger.py b/tests/test_logger.py
new file mode 100644
index 0000000..4718499
--- /dev/null
+++ b/tests/test_logger.py
@@ -0,0 +1,11 @@
+from diceware.logger import logger
+
+
+def test_logger_exists():
+    # the logger does exist
+    assert logger is not None
+
+
+def test_logger_has_handler():
+    # the logger has at least one handler
+    assert len(logger.handlers) > 0
-- 
GitLab