-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
419 additions
and
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
# C extensions | ||
*.so | ||
# log files | ||
*.log | ||
|
||
# Packages | ||
*.egg | ||
|
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 |
---|---|---|
|
@@ -18,4 +18,5 @@ coveralls | |
pytest-cov | ||
docutils | ||
cx_freeze | ||
pyyaml | ||
|
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
version: 1 | ||
disable_existing_loggers: True | ||
formatters: | ||
simple: | ||
format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s" | ||
|
||
handlers: | ||
console: | ||
class: logging.StreamHandler | ||
level: DEBUG | ||
formatter: simple | ||
stream: ext://sys.stdout | ||
|
||
info_file_handler: | ||
class: logging.handlers.RotatingFileHandler | ||
level: INFO | ||
formatter: simple | ||
filename: info.log | ||
maxBytes: 10485760 # 10MB | ||
backupCount: 20 | ||
encoding: utf8 | ||
|
||
error_file_handler: | ||
class: logging.handlers.RotatingFileHandler | ||
level: ERROR | ||
formatter: simple | ||
filename: error.log | ||
maxBytes: 10485760 # 10MB | ||
backupCount: 20 | ||
encoding: utf8 | ||
|
||
emitting_logger: | ||
class: rrpam_wds.logger.EmittingLogger | ||
level: INFO | ||
formatter: simple | ||
|
||
root: | ||
level: INFO | ||
handlers: [console, info_file_handler, error_file_handler, emitting_logger] | ||
|
||
rrpam_wds: | ||
level: INFO | ||
handlers: [console, info_file_handler, error_file_handler, emitting_logger] | ||
|
||
... |
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import logging.config | ||
import os | ||
|
||
import yaml | ||
from PyQt5.QtCore import QObject | ||
from PyQt5.QtCore import pyqtSignal | ||
from PyQt5.QtCore import pyqtSlot | ||
from PyQt5.QtWidgets import QApplication | ||
|
||
DEFAULTCONFIG = os.path.join(os.path.dirname(__file__), 'log', 'logging.yml') | ||
|
||
|
||
class LogSender(QObject): | ||
logsender_signal = pyqtSignal(object) | ||
|
||
def __init__(self): | ||
super(LogSender, self).__init__() | ||
if not hasattr(self, 'logsender_signal'): | ||
LogSender.logsender_signal = pyqtSignal(object) | ||
|
||
|
||
class EmittingLogger(logging.Handler): | ||
|
||
def __init__(self): | ||
super(EmittingLogger, self).__init__() | ||
# self.widget = QPlainTextEdit(parent) | ||
# self.widget.setReadOnly(True) | ||
self.logsender = LogSender() | ||
self.setFormatter(logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")) | ||
|
||
def emit(self, record): | ||
msg = self.format(record) | ||
# self.widget.appendPlainText(msg) | ||
self.logsender.logsender_signal.emit(msg) | ||
|
||
|
||
def setup_logging(default_path=DEFAULTCONFIG, default_level=logging.INFO, | ||
env_key='LOG_CFG'): | ||
"""Setup logging configuration | ||
""" | ||
|
||
path = default_path | ||
value = os.getenv(env_key, None) | ||
if value: | ||
path = value | ||
if os.path.exists(path): | ||
with open(path, 'rt') as f: | ||
config = yaml.safe_load(f.read()) | ||
logging.config.dictConfig(config) | ||
|
||
else: | ||
logging.basicConfig(level=default_level) | ||
# emittinglogger=EmittingLogger() | ||
|
||
# logger=logging.getLogger() | ||
# logger.addHandler(emittinglogger) | ||
|
||
|
||
@pyqtSlot(object) | ||
def reciever(object): | ||
print("I Got: ", str(object)) | ||
|
||
|
||
if __name__ == "__main__": | ||
from rrpam_wds.gui.dialogs import MainWindow | ||
|
||
app = QApplication([]) | ||
|
||
mw = MainWindow() | ||
# setup_logging() | ||
|
||
# logger=logging.getLogger() | ||
# win=QPlainTextEdit() | ||
# mw.mdi.addSubWindow(win) | ||
# print(logger.handlers) | ||
# from rrpam_wds.logger import EmittingLogger | ||
# handler=[x for x in logger.handlers if isinstance(x,EmittingLogger)][0] | ||
# handler.logsender.logsender_signal.connect(reciever) | ||
# handler.logsender.logsender_signal.connect(win.appendPlainText) | ||
logger = logging.getLogger() | ||
logger.info("Hello, world!") | ||
logger.info("Hello, world!") | ||
mw.show() | ||
mw.show_logwindow() | ||
mw.show_logwindow() | ||
|
||
mw.show_logwindow() | ||
|
||
app.exec_() |
Oops, something went wrong.