-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/logger setup #15
base: master
Are you sure you want to change the base?
Changes from all commits
9f5861c
7497e16
7e8fa2e
c2848b2
87f70b1
167ebd1
1f5c31f
eda3640
b78e211
b539957
cd4c8b0
caf4f71
c8b80d7
6e2a68b
58a8d4f
6d7cd60
302f234
23fcb11
88ac882
972b561
8e877c7
01123fc
f858735
29bff6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,5 +38,9 @@ | |
*.pyc | ||
*__pycache__ | ||
|
||
|
||
# Log files | ||
*.log | ||
|
||
# IDE-related files | ||
.idea/* | ||
.idea/* |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
# make sure to sync these up with _speedups.pyx | ||
CRITICAL = 15 | ||
ERROR = 14 | ||
WARNING = 13 | ||
NOTICE = 12 | ||
INFO = 11 | ||
DEBUG = 10 | ||
TRACE = 9 | ||
NOTSET = 0 | ||
|
||
_level_names = { | ||
CRITICAL: 'CRITICAL', | ||
ERROR: 'ERROR', | ||
WARNING: 'WARNING', | ||
NOTICE: 'NOTICE', | ||
INFO: 'INFO', | ||
DEBUG: 'DEBUG', | ||
TRACE: 'TRACE', | ||
NOTSET: 'NOTSET' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Installation of Logbook | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would list this as a requirement in requirements.txt found in the root-level directory. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I would rename this to README.md and make it a broader document. Logbook Setup could be a section, but we could also include other sections for usage, to-do's, etc. |
||
``` | ||
cd Aerocube | ||
pip install logbook | ||
# pip3 install logbook | ||
cd logger/tests | ||
# python3 TestLogger.py | ||
# python3.5 TestLogger.py | ||
``` | ||
|
||
|
||
# Todo's for Log book | ||
1. Initialize a handler for streaming logs to sys.stdout | ||
2. Initialize a handler for streaming logs to arbitrary files | ||
|
||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import unittest | ||
from tempfile import NamedTemporaryFile | ||
from logbook import FileHandler, Logger, TestHandler | ||
|
||
|
||
class TestFileLogHandler(unittest.TestCase): | ||
|
||
def setUp(self): | ||
""" | ||
Initialize Handler for arbitrary streams | ||
with a parameter to log to the standard output. | ||
Logger can be any name. The logger itself is a log channel | ||
or a record dispatcher. In this case, the logger is set to | ||
channel logs to the standard output | ||
:return: | ||
""" | ||
# Create an arbitrary temporary file | ||
self._tempfile = NamedTemporaryFile(delete=True) | ||
|
||
# Setup logging handler for standard output purposes | ||
self._output_stream = FileHandler( | ||
filename=self._tempfile.name, | ||
encoding='UTF-8', | ||
bubble=True | ||
) | ||
self._ctx = self._output_stream.push_application() | ||
|
||
# Setup logging handler for testing purposes | ||
self._log_handler = TestHandler(bubble=True) | ||
self._log_handler.push_thread() | ||
|
||
# Initialize Logger | ||
# Apply both standard-output and test log-handlers to the newly, initialized logger | ||
self._log = Logger('TestLog') | ||
self._log.handlers = [self._log_handler, self._output_stream] | ||
|
||
# string helper | ||
self._tempfile_buffer = '' | ||
|
||
def tearDown(self): | ||
""" | ||
Close the output stream. | ||
:return: | ||
""" | ||
self._output_stream.close() | ||
self._log_handler.pop_thread() | ||
self._log_handler.close() | ||
self._tempfile.close() | ||
|
||
|
||
def test_logger_init(self): | ||
""" | ||
Call all log methods | ||
:return: | ||
""" | ||
self.assertIsNotNone(self._log, msg='Logger resource not found') | ||
|
||
def test_warn_logging(self): | ||
self._log.warn('warn000.log') | ||
self._tempfile_buffer = str(self._tempfile.read()) | ||
self.assertTrue('warn000.log' in self._tempfile_buffer) | ||
|
||
self._log.warn('warn001.log') | ||
self._tempfile_buffer = str(self._tempfile.read()) | ||
self.assertTrue('warn001.log' in self._tempfile_buffer) | ||
self.assertFalse('warn002.log' in self._tempfile_buffer) | ||
|
||
|
||
def test_error_logging(self): | ||
self._log.error('error000.log') | ||
self._tempfile_buffer = str(self._tempfile.read()) | ||
self.assertTrue('error000.log' in self._tempfile_buffer) | ||
|
||
self._log.error('error001.log') | ||
self._tempfile_buffer = str(self._tempfile.read()) | ||
self.assertTrue('error001.log' in self._tempfile_buffer) | ||
self.assertFalse('error002.log' in self._tempfile_buffer) | ||
|
||
def test_critical_logging(self): | ||
self._log.critical('critical000.log') | ||
self._tempfile_buffer = str(self._tempfile.read()) | ||
self.assertTrue('critical000.log' in self._tempfile_buffer) | ||
|
||
self._log.critical('critical001.log') | ||
self._tempfile_buffer = str(self._tempfile.read()) | ||
self.assertTrue('critical001.log' in self._tempfile_buffer) | ||
self.assertFalse('critical002.log' in self._tempfile_buffer) | ||
|
||
def test_debug_logging(self): | ||
self._log.debug('debug000.log') | ||
self._tempfile_buffer = str(self._tempfile.read()) | ||
self.assertTrue('debug000.log' in self._tempfile_buffer) | ||
|
||
self._log.debug('debug001.log') | ||
self._tempfile_buffer = str(self._tempfile.read()) | ||
self.assertTrue('debug001.log' in self._tempfile_buffer) | ||
self.assertFalse('debug002.log' in self._tempfile_buffer) | ||
|
||
def test_info_logging(self): | ||
self._log.info('info000.log') | ||
self._tempfile_buffer = str(self._tempfile.read()) | ||
self.assertTrue('info000.log' in self._tempfile_buffer) | ||
|
||
self._log.info('info001.log') | ||
self._tempfile_buffer = str(self._tempfile.read()) | ||
self.assertTrue('info001.log' in self._tempfile_buffer) | ||
self.assertFalse('info002.log' in self._tempfile_buffer) | ||
|
||
def test_notice_logging(self): | ||
self._log.notice('notice000.log') | ||
self._tempfile_buffer = str(self._tempfile.read()) | ||
self.assertTrue('notice000.log' in self._tempfile_buffer) | ||
|
||
self._log.notice('notice001.log') | ||
self._tempfile_buffer = str(self._tempfile.read()) | ||
self.assertTrue('notice001.log' in self._tempfile_buffer) | ||
self.assertFalse('notice002.log' in self._tempfile_buffer) | ||
|
||
def test_trace_logging(self): | ||
self._log.trace('trace000.log') | ||
self._tempfile_buffer = str(self._tempfile.read()) | ||
self.assertTrue('trace000.log' in self._tempfile_buffer) | ||
|
||
self._log.trace('trace001.log') | ||
self._tempfile_buffer = str(self._tempfile.read()) | ||
self.assertTrue('trace001.log' in self._tempfile_buffer) | ||
self.assertFalse('trace002.log' in self._tempfile_buffer) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import unittest | ||
import sys | ||
from logbook import StreamHandler, Logger, TestHandler | ||
|
||
|
||
class TestLogbook(unittest.TestCase): | ||
|
||
def setUp(self): | ||
""" | ||
Initialize Handler for arbitrary streams | ||
with a parameter to log to the standard output. | ||
Logger can be any name. The logger itself is a log channel | ||
or a record dispatcher. In this case, the logger is set to | ||
channel logs to the standard output | ||
:return: | ||
""" | ||
# Setup logging handler for standard output purposes | ||
self._output_stream = StreamHandler(sys.stdout) | ||
self._ctx = self._output_stream.push_application() | ||
|
||
# Setup logging handler for testing purposes | ||
self._log_handler = TestHandler(bubble=True) | ||
self._log_handler.push_thread() | ||
|
||
# Initialize Logger | ||
# Apply both standard-output and test log-handlers to the newly, initialized logger | ||
self._log = Logger('TestLog') | ||
self._log.handlers = [self._log_handler, self._output_stream] | ||
|
||
def tearDown(self): | ||
""" | ||
Close the output stream. | ||
:return: | ||
""" | ||
self._output_stream.close() | ||
self._log_handler.pop_thread() | ||
self._log_handler.close() | ||
|
||
def test_logger_init(self): | ||
""" | ||
Call all log methods | ||
:return: | ||
""" | ||
self.assertIsNotNone(self._log, msg='Logger resource not found') | ||
|
||
def test_warn_logging(self): | ||
self.assertFalse(self._log_handler.has_warning('warn000.log')) | ||
self._log.warn('warn000.log') | ||
self.assertTrue(self._log_handler.has_warning) | ||
self._log.warn('warn001.log') | ||
self.assertTrue(self._log_handler.has_warning('warn000.log')) | ||
self.assertTrue(self._log_handler.has_warning('warn001.log')) | ||
self.assertFalse(self._log_handler.has_warning('warn002.log')) | ||
|
||
def test_error_logging(self): | ||
self.assertFalse(self._log_handler.has_errors) | ||
self.assertFalse(self._log_handler.has_error('error000.log')) | ||
self._log.error('error000.log') | ||
self.assertTrue(self._log_handler.has_error) | ||
self._log.error('error001.log') | ||
self.assertTrue(self._log_handler.has_error('error000.log')) | ||
self.assertTrue(self._log_handler.has_error('error001.log')) | ||
self.assertFalse(self._log_handler.has_error('error002.log')) | ||
self.assertTrue(self._log_handler.has_errors) | ||
|
||
def test_critical_logging(self): | ||
self.assertFalse(self._log_handler.has_criticals) | ||
self.assertFalse(self._log_handler.has_critical('critical000.log')) | ||
self._log.critical('critical000.log') | ||
self.assertTrue(self._log_handler.has_error) | ||
self._log.critical('critical001.log') | ||
self.assertTrue(self._log_handler.has_critical('critical000.log')) | ||
self.assertTrue(self._log_handler.has_critical('critical001.log')) | ||
self.assertFalse(self._log_handler.has_critical('critical002.log')) | ||
self.assertTrue(self._log_handler.has_criticals) | ||
|
||
def test_debug_logging(self): | ||
self.assertFalse(self._log_handler.has_debugs) | ||
self.assertFalse(self._log_handler.has_debug('debug000.log')) | ||
self._log.debug('debug000.log') | ||
self.assertTrue(self._log_handler.has_debug) | ||
self._log.debug('debug001.log') | ||
self.assertTrue(self._log_handler.has_debug('debug000.log')) | ||
self.assertTrue(self._log_handler.has_debug('debug001.log')) | ||
self.assertFalse(self._log_handler.has_debug('debug002.log')) | ||
self.assertTrue(self._log_handler.has_debugs) | ||
|
||
def test_info_logging(self): | ||
self.assertFalse(self._log_handler.has_infos) | ||
self.assertFalse(self._log_handler.has_info('info000.log')) | ||
self._log.info('info000.log') | ||
self.assertTrue(self._log_handler.has_info) | ||
self._log.info('info001.log') | ||
self.assertTrue(self._log_handler.has_info('info000.log')) | ||
self.assertTrue(self._log_handler.has_info('info001.log')) | ||
self.assertFalse(self._log_handler.has_info('info002.log')) | ||
self.assertTrue(self._log_handler.has_infos) | ||
|
||
def test_notice_logging(self): | ||
self.assertFalse(self._log_handler.has_notices) | ||
self.assertFalse(self._log_handler.has_notice('notice000.log')) | ||
self._log.notice('notice000.log') | ||
self.assertTrue(self._log_handler.has_notice) | ||
self._log.notice('notice001.log') | ||
self.assertTrue(self._log_handler.has_notice('notice000.log')) | ||
self.assertTrue(self._log_handler.has_notice('notice001.log')) | ||
self.assertFalse(self._log_handler.has_notice('notice002.log')) | ||
self.assertTrue(self._log_handler.has_notices) | ||
|
||
@unittest.skip('Trace test is skipped, because the log handler has no `has_trace` field\n') | ||
def test_trace_logging(self): | ||
self._log.trace('Trace') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from logbook import Logger | ||
import unittest | ||
#from ../Logger import Logger | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd remove this line just to keep things clean, unless it's kept in here for some reason. |
||
|
||
class TestLogger(unittest.TestCase): | ||
|
||
def setUp(self): | ||
# Declare the Logger | ||
self._log_handler = logbook.TestHandler() | ||
self._log_handler.push_thread() | ||
self._logger = Logger('TestLogger') | ||
|
||
def tearDown(self): | ||
self._log_handler.pop_thread() | ||
self._logger = None | ||
|
||
#@classmethod | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd also remove these commented lines if they aren't serving a purpose. |
||
#def instantiateState(logger): | ||
|
||
|
||
def testLoggerWithWarning(): | ||
with logbook.TestHandler() as handler: | ||
_logger.warn('A warning') | ||
assert logger.has_warning('A warning') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is _speedups.pyx?