-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from pnuu/flake8-and-datetime-imports
Fix Flake8 complaints and datetime imports
- Loading branch information
Showing
12 changed files
with
162 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,26 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
# | ||
# Copyright (c) 2012, 2014, 2015 Martin Raspaud | ||
|
||
# | ||
# Author(s): | ||
|
||
# | ||
# Martin Raspaud <[email protected]> | ||
|
||
# | ||
# 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/>. | ||
|
||
"""Logger for pytroll system. | ||
""" | ||
"""Logger module for Posttroll.""" | ||
|
||
|
||
# TODO: remove old hanging subscriptions | ||
|
@@ -39,35 +38,36 @@ | |
|
||
|
||
class PytrollFormatter(logging.Formatter): | ||
|
||
"""Formats a pytroll message inside a log record. | ||
""" | ||
"""Formats a pytroll message inside a log record.""" | ||
|
||
def __init__(self, fmt, datefmt): | ||
"""Initialize formatter.""" | ||
logging.Formatter.__init__(self, fmt, datefmt) | ||
|
||
def format(self, record): | ||
"""Format the message.""" | ||
subject = "/".join(("log", record.levelname, str(record.name))) | ||
mesg = Message(subject, "log." + str(record.levelname).lower(), | ||
record.getMessage()) | ||
return str(mesg) | ||
|
||
|
||
class PytrollHandler(logging.Handler): | ||
|
||
"""Sends the record through a pytroll publisher. | ||
""" | ||
"""Sends the record through a pytroll publisher.""" | ||
|
||
def __init__(self, name, port=0): | ||
"""Initialize the handler.""" | ||
logging.Handler.__init__(self) | ||
self._publisher = NoisyPublisher(name, port) | ||
self._publisher.start() | ||
|
||
def emit(self, record): | ||
"""Emit the message.""" | ||
message = self.format(record) | ||
self._publisher.send(message) | ||
|
||
def close(self): | ||
"""Close the handler.""" | ||
self._publisher.stop() | ||
logging.Handler.close(self) | ||
|
||
|
@@ -87,15 +87,15 @@ def close(self): | |
|
||
|
||
class ColoredFormatter(logging.Formatter): | ||
|
||
"""Adds a color for the levelname. | ||
""" | ||
"""Adds a color for the levelname.""" | ||
|
||
def __init__(self, msg, use_color=True): | ||
"""Initialize the colored formatter.""" | ||
logging.Formatter.__init__(self, msg) | ||
self.use_color = use_color | ||
|
||
def format(self, record): | ||
"""Format the message.""" | ||
levelname = record.levelname | ||
if self.use_color and levelname in COLORS: | ||
levelname_color = (COLOR_SEQ % (30 + COLORS[levelname]) | ||
|
@@ -105,30 +105,24 @@ def format(self, record): | |
return logging.Formatter.format(self, record2) | ||
|
||
|
||
# logging.basicConfig(format='[%(asctime)s %(levelname)s] %(message)s', | ||
# level=logging.DEBUG) | ||
|
||
|
||
class Logger(object): | ||
|
||
"""The logging machine. | ||
Contains a thread listening to incomming messages, and a thread logging. | ||
""" | ||
|
||
def __init__(self, nameserver_address="localhost", nameserver_port=16543): | ||
"""Initialize the logger.""" | ||
del nameserver_address, nameserver_port | ||
self.log_thread = Thread(target=self.log) | ||
self.loop = True | ||
|
||
def start(self): | ||
"""Starts the logging. | ||
""" | ||
"""Start the logging.""" | ||
self.log_thread.start() | ||
|
||
def log(self): | ||
"""Log stuff. | ||
""" | ||
"""Log stuff.""" | ||
with Subscribe(services=[""], addr_listener=True) as sub: | ||
for msg in sub.recv(1): | ||
if msg: | ||
|
@@ -156,14 +150,12 @@ def log(self): | |
break | ||
|
||
def stop(self): | ||
"""Stop the machine. | ||
""" | ||
"""Stop the machine.""" | ||
self.loop = False | ||
|
||
|
||
def run(): | ||
"""Main function | ||
""" | ||
"""Run the logger.""" | ||
import argparse | ||
|
||
global LOGGER | ||
|
@@ -209,8 +201,8 @@ def run(): | |
time.sleep(1) | ||
except KeyboardInterrupt: | ||
tlogger.stop() | ||
print("Thanks for using pytroll/logger. " | ||
"See you soon on www.pytroll.org!") | ||
print("Thanks for using pytroll/logger. See you soon on www.pytroll.org!") | ||
|
||
|
||
if __name__ == '__main__': | ||
run() |
Oops, something went wrong.