]> Softwares of Agnibho - medscript.git/commitdiff
Enabled logging
authorAgnibho Mondal <mondal@agnibho.com>
Tue, 7 Nov 2023 15:26:12 +0000 (20:56 +0530)
committerAgnibho Mondal <mondal@agnibho.com>
Tue, 7 Nov 2023 20:11:15 +0000 (01:41 +0530)
14 files changed:
config.py
customform.py
editpreset.py
filehandler.py
index.py
medscript.py
plugin.py
prescription.py
preset.py
renderbox.py
renderer.py
setting.py
signature.py
window.py

index 48d37a87fb36d6c81c73d36ed7d8a640cb3e13a2..0f0c84a51032cf51381a89ef59bb93c13abc1b67 100644 (file)
--- a/config.py
+++ b/config.py
@@ -5,7 +5,7 @@
 # MedScript 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 MedScript. If not, see <https://www.gnu.org/licenses/>.
 
-import argparse, json, os, sys, shutil
+import logging, argparse, json, os, sys, shutil
 
 default_config_file=os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "data", "config.json"))
 
@@ -37,6 +37,7 @@ default = {
         "enable_form": False,
         "plugin_directory": "plugin",
         "enable_plugin": False,
+        "log_directory": "log",
         "preset_newline": True,
         "preset_delimiter": ",",
         "markdown": False,
@@ -52,7 +53,7 @@ try:
         read = json.loads(conf.read())
     config = default | read
 except Exception as e:
-    print(e)
+    logging.warning(e)
     config=default
 
 config["filename"]=args.filename
@@ -63,6 +64,7 @@ config["form_directory"]=os.path.join(config["data_directory"], config["form_dir
 config["plugin_directory"]=os.path.join(config["data_directory"], config["plugin_directory"])
 config["template_directory"]=os.path.join(config["data_directory"], config["template_directory"])
 config["template"]=os.path.join(config["template_directory"], config["template"])
+config["log_directory"]=os.path.join(config["data_directory"], config["log_directory"])
 config["resource"]=os.path.abspath(os.path.join(real_dir, "resource"))
 if(args.prescriber is None):
     config["prescriber_directory"]=os.path.join(config["data_directory"], config["prescriber_directory"])
@@ -75,7 +77,7 @@ else:
         config["prescriber"]=args.prescriber
     else:
         config["prescriber"]=os.path.join(config["prescriber_directory"], config["prescriber"])
-        print("File "+args.prescriber+" not found.")
+        logging.warning("File "+args.prescriber+" not found.")
 
 os.makedirs(config["data_directory"], exist_ok=True)
 os.makedirs(config["document_directory"], exist_ok=True)
@@ -84,6 +86,7 @@ os.makedirs(config["preset_directory"], exist_ok=True)
 os.makedirs(config["form_directory"], exist_ok=True)
 os.makedirs(config["plugin_directory"], exist_ok=True)
 os.makedirs(config["template_directory"], exist_ok=True)
+os.makedirs(config["log_directory"], exist_ok=True)
 if not os.path.exists(os.path.join(config["data_directory"], "config.json")):
     shutil.copyfile(os.path.abspath(os.path.join(real_dir, "data", "config.json")), os.path.join(config["data_directory"], "config.json"))
 if not os.path.exists(os.path.join(config["prescriber_directory"], "prescriber.json")):
index d58bfd9594ae4c40f40f566961b5137f18e0e751..547ecfc00edcbe76ed32824056a3765a1c6d12d0 100644 (file)
@@ -8,7 +8,7 @@
 from PyQt6.QtWidgets import QWidget, QFormLayout, QLineEdit, QTextEdit, QCheckBox, QDateTimeEdit, QCalendarWidget
 from PyQt6.QtCore import QDateTime
 from glob import glob
-import os, json, sys, dateutil.parser
+import logging, os, json, sys, dateutil.parser
 from config import config
 
 class CustomForm(QWidget):
@@ -23,7 +23,7 @@ class CustomForm(QWidget):
                 try:
                     self.forms.append(json.loads(f.read()))
                 except Exception as e:
-                    print(e)
+                    logging.warning(e)
         for i in self.forms:
             try:
                 for j in i["form"]:
@@ -55,7 +55,7 @@ class CustomForm(QWidget):
                 elif(isinstance(self.inputs[index][1], QDateTimeEdit)):
                     self.custom[index][list(item)[0]]=self.inputs[index][1].text()
         except Exception as e:
-            print(e)
+            logging.warning(e)
         return(self.custom)
 
     def setData(self, custom=False):
@@ -74,7 +74,7 @@ class CustomForm(QWidget):
                     d=QDateTime.fromString(pdate.strftime("%Y-%m-%d %H:%M:%S"), "yyyy-MM-dd hh:mm:ss")
                     self.inputs[index][1].setDateTime(d)
         except Exception as e:
-            print(e)
+            logging.warning(e)
 
 
     def __init__(self, *args, **kwargs):
index 26289ada0c4c417bf1abde7ebf77895b0c2595a1..884a683f449403c784571b2ba2b830fcdceb5d60 100644 (file)
@@ -8,7 +8,7 @@
 from PyQt6.QtWidgets import QWidget, QMainWindow, QVBoxLayout, QHBoxLayout, QPushButton, QComboBox, QTextEdit, QTableView, QMessageBox
 from PyQt6.QtGui import QIcon, QStandardItemModel, QStandardItem
 from config import config
-import os, csv
+import logging, os, csv
 
 class EditPreset(QMainWindow):
 
@@ -61,7 +61,7 @@ class EditPreset(QMainWindow):
             self.load(file)
             QMessageBox.information(self,"File saved", "Changes saved. Please restart the program.")
         except Exception as e:
-            print(e)
+            logging.warning(e)
 
     def cmd_row(self):
         tablerow=[]
@@ -99,7 +99,7 @@ class EditPreset(QMainWindow):
             self.table.resizeRowsToContents()
             textedit=QTextEdit()
         except Exception as e:
-            print(e)
+            logging.warning(e)
 
     def confirm(self):
         return QMessageBox.StandardButton.Yes==QMessageBox.question(self,"Confirm action", "Unsaved changes may be lost. Continue?")
index 99e0a55b4617a95a0a95ce0bac1936c2d8300d9a..4deaea9c23bb02cbfcc684850216eb3e8fdabb06 100644 (file)
@@ -5,7 +5,7 @@
 # MedScript 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 MedScript. If not, see <https://www.gnu.org/licenses/>.
 
-import os, shutil, glob, tempfile, json
+import logging, os, shutil, glob, tempfile, json
 from zipfile import ZipFile
 from config import config
 from signature import Signature
@@ -33,7 +33,7 @@ class FileHandler():
         try:
             shutil.copyfile(file, os.path.join(dirname, os.path.basename(file)))
         except shutil.SameFileError as e:
-            print(e)
+            logging.warning(e)
 
     def list(self, category="attachment"):
         items=[]
@@ -85,20 +85,20 @@ class FileHandler():
                 signature=file.read()
             return Signature.verify(data, certificate=os.path.join(self.directory.name, "certificate.pem"), signature=signature)
         except FileNotFoundError as e:
-            print(e)
+            logging.warning(e)
 
     def delete_attachment(self, item):
         try:
             os.unlink(os.path.join(self.directory.name, "attachment", os.path.basename(item)))
         except Exception as e:
-            print(e)
+            logging.warning(e)
 
     def delete_sign(self):
         try:
             os.unlink(os.path.join(self.directory.name, "certificate.pem"))
             os.unlink(os.path.join(self.directory.name, "signature"))
         except Exception as e:
-            print(e)
+            logging.warning(e)
 
     def has_template(self):
         return(os.path.exists(os.path.join(self.directory.name, "template", "index.html")))
index 0948ef70e8b7e7962804f6ae9947945ba0c5697a..f855c9c0152beb7f386a4f70b9defbb3babac666 100644 (file)
--- a/index.py
+++ b/index.py
@@ -11,7 +11,7 @@ from PyQt6.QtCore import pyqtSignal, QSortFilterProxyModel
 from glob import glob
 from zipfile import ZipFile
 from config import config
-import os, json
+import logging, os, json
 
 class Index(QMainWindow):
 
@@ -75,7 +75,7 @@ class Index(QMainWindow):
             self.signal_open.emit(self.getSelectedFile())
             self.hide()
         except Exception as e:
-            print(e)
+            logging.warning(e)
 
     def cmd_copy(self):
         try:
@@ -85,7 +85,7 @@ class Index(QMainWindow):
             self.signal_copy.emit(pres)
             self.hide()
         except Exception as e:
-            print(e)
+            logging.warning(e)
 
 
     def getSelectedFile(self):
index af40c40c938ae20131c0a9df53692767a9cf3a13..d0ffa49b07b33b8dd6f960e6d95fc63498ea183c 100644 (file)
@@ -5,12 +5,18 @@
 # MedScript 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 MedScript. If not, see <https://www.gnu.org/licenses/>.
 
-import sys, os
+import logging, sys, os
+from logging.handlers import RotatingFileHandler
 from PyQt6.QtWidgets import QApplication
 from window import MainWindow
 from config import config
 
 if __name__=="__main__":
+    logging.basicConfig(level=logging.INFO,
+            format="[%(asctime)s] (%(module)s / %(funcName)s) %(levelname)s : %(message)s",
+            handlers=[RotatingFileHandler(os.path.join(config["log_directory"], "log.txt"), maxBytes=100000, backupCount=9), logging.StreamHandler()],
+            force=True
+            )
     app=QApplication(sys.argv)
     with open(os.path.join(config["resource"], "style.qss")) as qss:
         app.setStyleSheet(qss.read())
index e114f52e254388d842856f77b7acba9ee636e0bf..a45b801c7c95f1bfb1c79ea5d84da4c2eb794615 100644 (file)
--- a/plugin.py
+++ b/plugin.py
@@ -5,7 +5,7 @@
 # MedScript 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 MedScript. If not, see <https://www.gnu.org/licenses/>.
 
-import os, importlib, copy
+import logging, os, importlib, copy
 from PyQt6.QtWidgets import QMessageBox, QInputDialog, QFileDialog
 from PyQt6.QtCore import QThread, pyqtSignal
 from glob import glob
@@ -31,7 +31,7 @@ class Plugin():
                     spec.loader.exec_module(mod)
                     self.plugins.append(mod)
             except Exception as e:
-                print(i, ":", e)
+                logging.warning(i, ":", e)
 
     def get_name(self, mod):
             try:
@@ -56,7 +56,7 @@ class Plugin():
                     if(message):
                         self.showMessage(message)
             except Exception as e:
-                print(e)
+                logging.warning(e)
 
     def open(self, prescription):
         for i in self.plugins:
@@ -68,7 +68,7 @@ class Plugin():
                     if(message):
                         self.showMessage(message)
             except Exception as e:
-                print(e)
+                logging.warning(e)
 
     def save(self, prescription):
         for i in self.plugins:
@@ -80,7 +80,7 @@ class Plugin():
                     if(message):
                         self.showMessage(message)
             except Exception as e:
-                print(e)
+                logging.warning(e)
 
     def refresh(self, prescription):
         for i in self.plugins:
@@ -92,7 +92,7 @@ class Plugin():
                     if(message):
                         self.showMessage(message)
             except Exception as e:
-                print(e)
+                logging.warning(e)
 
     def run(self, module, prescription):
         try:
@@ -115,7 +115,7 @@ class Plugin():
                     if(message):
                         self.showMessage(message)
         except Exception as e:
-            print(e)
+            logging.warning(e)
 
     def input(self):
         try:
@@ -125,7 +125,7 @@ class Plugin():
             else:
                 return ""
         except Exception as e:
-            print(e)
+            logging.warning(e)
 
     def showMessage(self, message, index=None):
         QMessageBox.information(None, "Information", message)
index ab4ccc96f4701a2e5d7382a722f0ebaee1bff9a8..59fb733e1a41ebc9eaa989908c7d2850aa08973c 100644 (file)
@@ -5,7 +5,7 @@
 # MedScript 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 MedScript. If not, see <https://www.gnu.org/licenses/>.
 
-import json
+import logging, json
 from config import config
 
 class Prescriber:
@@ -34,7 +34,7 @@ class Prescriber:
             self.extra = data["extra"]
             self.properties = data["properties"]
         except Exception as e:
-            print(e)
+            logging.warning(e)
 
     def read_from(self, file):
         try:
@@ -112,7 +112,7 @@ class Prescription:
             self.custom = data.get("custom")
             self.properties = data.get("properties")
         except Exception as e:
-            print(e)
+            logging.warning(e)
 
     def get_json(self):
         return(json.dumps(self, default=lambda o: o.__dict__, indent=4))
@@ -124,7 +124,7 @@ class Prescription:
             except AttributeError as e:
                 pass
             except Exception as e:
-                print(e)
+                logging.warning(e)
             f.write(self.get_json())
         self.file=file
 
index 253f74565638a8b7180705bee07a39dd27e8365b..c73cd4e474cd598e33c80bfc406be361c8f0efe7 100644 (file)
--- a/preset.py
+++ b/preset.py
@@ -5,7 +5,7 @@
 # MedScript 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 MedScript. If not, see <https://www.gnu.org/licenses/>.
 
-import os, csv
+import logging, os, csv
 from glob import glob
 from config import config
 
@@ -33,10 +33,10 @@ class Preset():
                             buf[row[1].strip()]=row[1]
             self.data = buf | self.data
         except FileNotFoundError as e:
-            print(e)
+            logging.warning(e)
         except IndexError as e:
-            print(e)
+            logging.warning(e)
         except StopIteration as e:
-            print(e)
+            logging.warning(e)
         except Exception as e:
-            print(e)
+            logging.warning(e)
index 037b9de7a6144d342c16f3b8ad483165e0798c61..23ce9ba73edcc53113c82118336912fd4d694a5f 100644 (file)
@@ -10,7 +10,7 @@ from PyQt6.QtWebEngineWidgets import QWebEngineView
 from PyQt6.QtGui import QIcon, QPageLayout, QPageSize
 from PyQt6.QtCore import QUrl, QMarginsF
 from PyQt6.QtPrintSupport import QPrinter, QPrintDialog
-import os
+import logging, os
 from config import config
 
 class RenderBox(QMainWindow):
@@ -73,4 +73,4 @@ class RenderBox(QMainWindow):
         except Exception as e:
             QMessageBox.warning(self,"Display failed", "Failed to display file.")
             self.hide()
-            print(e)
+            logging.warning(e)
index e9ca921f2e43f4e5efcce90917c2476bf5656c4f..dfb28b75c874d25cdb3d51be20b4ec7478e34f2a 100644 (file)
@@ -5,7 +5,7 @@
 # MedScript 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 MedScript. If not, see <https://www.gnu.org/licenses/>.
 
-import os, shutil, tempfile, json, datetime, re
+import logging, os, shutil, tempfile, json, datetime, re
 from markdown import markdown
 from jinja2 import Template
 from config import config
@@ -29,7 +29,7 @@ class Renderer:
                 try:
                     data["date"]=datetime.datetime.strptime(data["date"], "%Y-%m-%d %H:%M:%S")
                 except Exception as e:
-                    print(e)
+                    logging.warning(e)
                 output=template_data.render(data)
                 target_file.write(output)
         return(target)
index d211956df618690a1019ccb1fbe6dfb332893dfc..9a33bb74f19b3b1e3114661ceb936048eaaded69 100644 (file)
@@ -9,7 +9,7 @@ from PyQt6.QtWidgets import QDialog, QFormLayout, QHBoxLayout, QVBoxLayout, QPus
 from PyQt6.QtGui import QIcon
 from PyQt6.QtCore import Qt, pyqtSignal
 from glob import glob
-import os, json
+import logging, os, json
 from prescription import Prescriber
 from config import config, config_file
 
@@ -75,7 +75,7 @@ class EditConfiguration(QDialog):
                 self.close()
             except Exception as e:
                 QMessageBox.critical(self,"Failed to save", "Failed to save the data to the file.")
-                print(e)
+                logging.warning(e)
 
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
@@ -84,7 +84,7 @@ class EditConfiguration(QDialog):
             with open(config_file) as f:
                 self.config=json.loads(f.read()) | config
         except Exception as e:
-            print(e)
+            logging.warning(e)
             self.config=config
 
         self.setWindowTitle("Configuration")
@@ -176,7 +176,7 @@ class EditPrescriber(QDialog):
             self.input_extra.setText(self.prescriber["extra"])
         except Exception as e:
             QMessageBox.critical(self,"Failed to load", "Failed to load the data into the application.")
-            print(e)
+            logging.error(e)
 
     def save(self, file=False):
         if(file is not False or QMessageBox.StandardButton.Yes==QMessageBox.question(self,"Confirm Save", "This action will overwrite the previous information. Continue?")):
@@ -196,7 +196,7 @@ class EditPrescriber(QDialog):
                 self.close()
             except Exception as e:
                 QMessageBox.critical(self,"Failed to save", "Failed to save the data to the file.")
-                print(e)
+                logging.error(e)
 
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
index b94e7b436ac8be06f82633ee8b8f17f8826f7b49..259e1d826dfce9925334082492a3a747b0e5d448 100644 (file)
@@ -5,6 +5,7 @@
 # MedScript 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 MedScript. If not, see <https://www.gnu.org/licenses/>.
 
+import logging
 from config import config
 from datetime import datetime
 from cryptography.hazmat.primitives.serialization import load_pem_private_key, Encoding
@@ -31,7 +32,7 @@ class Signature():
             if(not Signature.verify_chain(certificate)):
                 return False
         except Exception as e:
-            print(e)
+            logging.warning(e)
             return False
 
         with open(certificate, "rb") as f:
@@ -44,7 +45,7 @@ class Signature():
                 subattr+=i.oid._name+":"+i.value+"\n"
             return subattr
         except Exception as e:
-            print(e)
+            logging.warning(e)
             return False
 
     def verify_chain(cert_chain_path):
@@ -60,23 +61,23 @@ class Signature():
         for i in range(len(cert_chain)):
             cert=cert_chain[i]
             if(datetime.utcnow().timestamp()>cert.not_valid_after.timestamp()):
-                print("Certificate expired")
+                logging.warning("Certificate expired")
                 return False
             if(i>0):
                 prev_cert=cert_chain[i-1]
                 try:
                     cert.public_key().verify(prev_cert.signature, prev_cert.tbs_certificate_bytes, padding.PKCS1v15(), prev_cert.signature_hash_algorithm)
                 except InvalidSignature:
-                    print("Certificate chain signature verification failed")
+                    logging.warning("Certificate chain signature verification failed")
                     return False
         try:
             with open(config["root_bundle"]) as root:
                 root_bundle=root.read()
             if(cert_chain[-1].public_bytes(encoding=Encoding.PEM).decode() not in root_bundle):
-                print("Certificate not in root bundle")
+                logging.warning("Certificate not in root bundle")
                 return False
             return True
         except Exception as e:
-            print(e)
-            print("Root bundle could not be loaded")
+            logging.warning(e)
+            logging.warning("Root bundle could not be loaded")
             return False
index 96030e803a3984c494c565461e160b867e042cda..f308b1bd046ad2244701153ae56c4702cf24b5d4 100644 (file)
--- a/window.py
+++ b/window.py
@@ -5,7 +5,7 @@
 # MedScript 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 MedScript. If not, see <https://www.gnu.org/licenses/>.
 
-import os, sys, datetime, dateutil.parser, shutil, json, threading
+import logging, os, sys, datetime, dateutil.parser, shutil, json, threading
 from PyQt6.QtCore import Qt, QDateTime, QDate, QSize, pyqtSignal
 from PyQt6.QtWidgets import QWidget, QMainWindow, QMessageBox, QLabel, QPushButton, QLineEdit, QTextEdit, QDateTimeEdit, QDateEdit, QCalendarWidget, QListWidget, QComboBox, QCheckBox, QRadioButton, QButtonGroup, QVBoxLayout, QHBoxLayout, QFormLayout, QToolBar, QTabWidget, QStatusBar, QFileDialog, QInputDialog, QCompleter, QSizePolicy
 from PyQt6.QtGui import QAction, QIcon
@@ -64,7 +64,7 @@ class MainWindow(QMainWindow):
                 self.unchanged_state=True
             except Exception as e:
                 QMessageBox.warning(self,"Open failed", "Failed to open file.")
-                print(e)
+                logging.warning(e)
 
     def cmd_copy(self, data):
         self.cmd_new()
@@ -104,7 +104,7 @@ class MainWindow(QMainWindow):
                 self.save_state=md5(self.prescription.get_json().encode()).hexdigest()
             except Exception as e:
                 QMessageBox.warning(self,"Save failed", "Failed to save file.")
-                print(e)
+                logging.warning(e)
 
     def cmd_save_as(self):
         suggest=self.prescription.id if(self.prescription.id) else self.prescription.name
@@ -131,7 +131,7 @@ class MainWindow(QMainWindow):
                 self.signal_view.emit(target)
                 self.renderbox.showMaximized()
             except FileNotFoundError as e:
-                print(e)
+                logging.warning(e)
                 QMessageBox.information(self, "Save first", "Please save the file before rendering.")
 
         else:
@@ -148,25 +148,25 @@ class MainWindow(QMainWindow):
                         #self.current_file.sign(password)
                         self.cmd_save()
                     except FileNotFoundError as e:
-                        print(e)
+                        logging.warning(e)
                         QMessageBox.information(self, "Save first", "Please save the file before signing.")
                     except TypeError as e:
-                        print(e)
+                        logging.warning(e)
                         QMessageBox.information(self, "Configure", "Please add valid key and certificate to the config file.")
                     except EVPError as e:
-                        print(e)
+                        logging.warning(e)
                         QMessageBox.information(self, "Check password", "Failed to load key. Please check if password is correct.")
                     except BIOError as e:
-                        print(e)
+                        logging.warning(e)
                         QMessageBox.information(self, "Not found", "Certifcate and/or key not found.")
                     except SMIME_Error as e:
-                        print(e)
+                        logging.warning(e)
                         QMessageBox.information(self, "Failed to load", "Failed to sign. Please check if certificate and key match.")
                     except Exception as e:
-                        print(e)
+                        logging.warning(e)
                         QMessageBox.information(self, "Failed", "Failed to sign.")
                 except Exception as e:
-                    print(e)
+                    logging.warning(e)
         else:
            QMessageBox.information(self, "Save first", "Please save the file before signing.")
 
@@ -183,13 +183,13 @@ class MainWindow(QMainWindow):
             elif result is None:
                 QMessageBox.warning(self, "No Siganture", "No signature was found.")
             else:
-                print(result)
+                logging.info(result)
                 QMessageBox.information(self, "Valid signature", "Valid signature found with the following information:\n"+result)
         except FileNotFoundError as e:
-            print(e)
+            logging.warning(e)
             QMessageBox.warning(self, "No Siganture", "No signature was found.")
         except Exception as e:
-            print(e)
+            logging.warning(e)
             QMessageBox.warning(self, "Failed", "Failed to verify.")
 
     def cmd_tabular(self):
@@ -198,7 +198,7 @@ class MainWindow(QMainWindow):
             Tabular.export(filename)
             QMessageBox.information(self, "Data Exported", "Data exported to."+filename)
         except Exception as e:
-            print(e)
+            logging.warning(e)
             QMessageBox.critical(self, "Export failed", "Failed to export the data.")
 
     def cmd_index(self):
@@ -217,7 +217,7 @@ class MainWindow(QMainWindow):
             self.select_prescriber.load()
             self.select_prescriber.exec()
         except FileNotFoundError as e:
-            print(e)
+            logging.warning(e)
 
     def cmd_preset(self):
         self.edit_preset.show()
@@ -241,17 +241,17 @@ class MainWindow(QMainWindow):
 
     def cmd_update(self, silent=False):
         try:
-            print("Current version "+info["version"])
+            logging.info("Current version "+info["version"])
             with request.urlopen(info["url"]+"/info.json") as response:
                 latest=json.loads(response.read().decode())
-            print("Latest version "+latest["version"])
+            logging.info("Latest version "+latest["version"])
             if(version.parse(info["version"]) < version.parse(latest["version"])):
                 self.signal_update.emit("New version <strong>"+latest["version"]+"</strong> available.<br>Visit <a href='"+latest["url"]+"'>"+latest["url"]+"</a> to get the latest version.")
             elif(not silent):
                 self.signal_update.emit("No update available. You are using version "+info["version"]+".")
         except Exception as e:
             self.signal_update.emit("Failed to check available update.")
-            print(e)
+            logging.warning(e)
 
     def show_update(self, message):
         QMessageBox.information(self, "Check update", message)
@@ -339,7 +339,7 @@ class MainWindow(QMainWindow):
                     d=QDateTime.fromString(pdate.strftime("%Y-%m-%d %H:%M:%S"), "yyyy-MM-dd hh:mm:ss")
                 except Exception as e:
                     QMessageBox.warning(self,"Failed to load", str(e))
-                    print(e)
+                    logging.warning(e)
             self.input_date.setDateTime(d)
             self.input_id.setText(id)
             self.input_name.setText(name)
@@ -372,7 +372,7 @@ class MainWindow(QMainWindow):
             self.label_prescriber.setText(self.prescriber.name)
         except Exception as e:
             QMessageBox.warning(self,"Failed to load", "Failed to load the data into the application.")
-            print(e)
+            logging.warning(e)
 
     def load_interface_from_instance(self):
         if(self.current_file.has_template()):
@@ -431,7 +431,7 @@ class MainWindow(QMainWindow):
                     )
         except Exception as e:
             QMessageBox.critical(self,"Failed", "Critical failure happned. Please check console for more info.")
-            print(e)
+            logging.error(e)
 
     def new_doc(self):
         self.current_file.reset()
@@ -459,7 +459,7 @@ class MainWindow(QMainWindow):
                 self.input_attachment.addItem(new)
         except Exception as e:
             QMessageBox.warning(self,"Attach failed", "Failed to attach file.")
-            print(e)
+            logging.warning(e)
 
     def remove_attachment(self):
         index=self.input_attachment.currentRow()
@@ -473,7 +473,7 @@ class MainWindow(QMainWindow):
         try:
             shutil.copyfile(self.input_attachment.currentItem().text(), QFileDialog.getSaveFileName(self, "Save Attachment", os.path.join(config["document_directory"], os.path.basename(self.input_attachment.currentItem().text())))[0])
         except Exception as e:
-            print(e)
+            logging.warning(e)
 
     def load_attachment(self, attachments):
         for attach in attachments:
@@ -610,7 +610,7 @@ class MainWindow(QMainWindow):
                     action_plugin[-1].triggered.connect(partial(self.plugin.run, i[0], self.prescription))
                     action_plugin[-1].triggered.connect(self.load_interface_from_instance)
             except Exception as e:
-                print(e)
+                logging.warning(e)
             menu_plugin=menubar.addMenu("Plugin")
             for i in action_plugin:
                 menu_plugin.addAction(i)
@@ -636,7 +636,7 @@ class MainWindow(QMainWindow):
             templates.remove(os.path.basename(config["template"]))
             templates.insert(0, os.path.basename(config["template"]))
         except Exception as e:
-            print(e)
+            logging.warning(e)
         self.input_template.addItems(templates)
         toolbar.addWidget(self.input_template)
         spacer=QWidget(self)