python-eigen-ingenuity-nocli 0.5.22b2__py3-none-any.whl → 0.5.23__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,8 +13,6 @@ h = get_historian("instancename")
13
13
  h.listDataTags()
14
14
  """
15
15
 
16
- from __future__ import absolute_import, division, print_function, unicode_literals
17
-
18
16
  try:
19
17
  from importlib.metadata import version, PackageNotFoundError
20
18
  except ImportError:
@@ -45,6 +43,7 @@ from eigeningenuity.settings import (
45
43
  set_auth_scope,
46
44
  )
47
45
  from eigeningenuity.util import EigenException
46
+ from eigeningenuity.logformatter import log_handler
48
47
 
49
48
  __all__ = [
50
49
  "get_historian",
@@ -68,7 +67,9 @@ __all__ = [
68
67
  "set_api_token",
69
68
  "set_auth_scope",
70
69
  "EigenException",
70
+ "log_handler",
71
71
  ]
72
+
72
73
  try:
73
74
  __version__ = version("python-eigen-ingenuity")
74
75
  except PackageNotFoundError:
@@ -0,0 +1,96 @@
1
+ import datetime
2
+ import traceback
3
+ import sys
4
+ import logging
5
+
6
+
7
+ # Function to add the filename to each line of the traceback
8
+ def format_traceback(exc_type, exc_value, exc_traceback, filename, configfile):
9
+ tb_lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
10
+ tb_lines2 = []
11
+ tb_lines2.append(
12
+ datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S,%f")[:-3]
13
+ + " - "
14
+ + filename
15
+ + configfile
16
+ + " - ERROR - An Error Occurred\n"
17
+ )
18
+ for line in tb_lines:
19
+ x = line.split("\n")
20
+ for y in x:
21
+ if y != "":
22
+ tb_lines2.append(
23
+ datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S,%f")[:-3]
24
+ + " - "
25
+ + filename
26
+ + configfile
27
+ + " - ERROR - "
28
+ + y
29
+ + "\n"
30
+ )
31
+ tb_lines2.append(
32
+ datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S,%f")[:-3]
33
+ + " - "
34
+ + filename
35
+ + configfile
36
+ + " - ERROR - Finished Executing\n"
37
+ )
38
+ return "".join(tb_lines2)
39
+
40
+
41
+ def exception_formatter(exc_type, exc_value, exc_traceback, filename, configfile=""):
42
+ if configfile != "":
43
+ configfile = ":" + configfile
44
+ tb_formatted = format_traceback(
45
+ exc_type, exc_value, exc_traceback, filename, configfile
46
+ )
47
+ print(tb_formatted)
48
+
49
+
50
+ sys.excepthook = exception_formatter
51
+
52
+
53
+ def log_handler(filename, configfile=""):
54
+ if configfile != "":
55
+ configfile = ":" + configfile
56
+ stream_handler = logging.StreamHandler(
57
+ sys.stdout
58
+ ) # By default, it logs to sys.stderr, but you can specify stdout.
59
+ stream_handler.setLevel(logging.INFO) # Set the log level for the stream handler
60
+ stream_formatter = logging.Formatter(
61
+ f"%(asctime)s - {filename}{configfile} - %(levelname)s - %(message)s"
62
+ )
63
+ stream_handler.setFormatter(stream_formatter)
64
+
65
+ # Get the root logger and add the stream handler to it
66
+ root_logger = logging.getLogger()
67
+ root_logger.setLevel(logging.INFO)
68
+ root_logger.addHandler(stream_handler)
69
+
70
+
71
+ def setup_logging(filename, configfile=""):
72
+ """Set up all logging, warning, and exception handling in one call."""
73
+ import warnings
74
+ import os
75
+
76
+ # Extract just the filename if a full path is provided
77
+ if "/" in filename or "\\" in filename:
78
+ filename = os.path.basename(filename)
79
+
80
+ # Set up logging handler
81
+ log_handler(filename, configfile)
82
+
83
+ # Set up custom warning handler
84
+ def custom_warning_handler(
85
+ message, category, warn_filename, lineno, file=None, line=None
86
+ ):
87
+ logging.warning(f"{message}\n")
88
+
89
+ warnings.filterwarnings("always", category=Warning, append=True)
90
+ warnings.showwarning = custom_warning_handler
91
+
92
+ # Set up custom exception handler
93
+ def custom_exception_handler(exc_type, exc_value, exc_traceback):
94
+ exception_formatter(exc_type, exc_value, exc_traceback, filename, configfile)
95
+
96
+ sys.excepthook = custom_exception_handler
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-eigen-ingenuity-nocli
3
- Version: 0.5.22b2
3
+ Version: 0.5.23
4
4
  Summary: A python library used to query data from the Eigen Ingenuity system
5
5
  Home-page: https://www.eigen.co/
6
6
  Author: Murray Callander
@@ -1,4 +1,4 @@
1
- eigeningenuity/__init__.py,sha256=4LT6hgRT2366khYaZ1M8SJwFgvD-5JJUBKnNTWbjy6I,2030
1
+ eigeningenuity/__init__.py,sha256=doDpiKJBQYBt3DIiVopXvssWJAN_07W38mHGLPpFGjo,2018
2
2
  eigeningenuity/assetmodel.py,sha256=S62dxVOtYucVPXyxmiqxIZ8gkKprrG_ovOKcX_0Fzes,21375
3
3
  eigeningenuity/auth.py,sha256=RjmtLBS6m4YhDZJa7RgB4RYWJDhE4zd-9tKeOz0iNug,7578
4
4
  eigeningenuity/commonmenu.py,sha256=G-l5fhOnLNpxJpMeek373zEyS26G9-HBH4VtzmRCT3E,15257
@@ -6,6 +6,7 @@ eigeningenuity/elastic.py,sha256=RC9BZ_DZJsVzW1Sd5F9-ziCLGImCGLMt94VAqpdRM5A,727
6
6
  eigeningenuity/events.py,sha256=I2W5SMvDQA5dwW9mjzOpv6CGEbVhYD42t36i5m6Ljas,12911
7
7
  eigeningenuity/historian.py,sha256=ByjGqD-70DQUTDFo88gWyoFOrGMXf-OUYzR8rWSnODI,39843
8
8
  eigeningenuity/historianmulti.py,sha256=h85jaKVaw1EmS0jaX5YCNC5q1_BhQKiUR4Jl2tx6nag,35479
9
+ eigeningenuity/logformatter.py,sha256=eBi0zHxy3psAekg1H5b_0GKH8seSaZqRXi-4Ue0531A,3064
9
10
  eigeningenuity/settings.py,sha256=sCY7AONBrc0IWSa3D37Scu_JapQoEBfJbRbY7BdDoBM,4212
10
11
  eigeningenuity/sql.py,sha256=r9kHjOymZxKY2HpAT3jYSr77oSDyT8UK-DLSaSDk7zI,5063
11
12
  eigeningenuity/util.py,sha256=ZCJwJ2WlvqzEM3mSmRkZarhFtvlNYVFRu2TdPkMtOh4,22732
@@ -86,7 +87,7 @@ regressiontests/eigeningenuity/historian-multi/test_getRawDatapoints.py,sha256=f
86
87
  regressiontests/eigeningenuity/historian-multi/test_listDataTags.py,sha256=TcceNSjCKoiK5SJcgTH2JXfKLYxIHdQdwZWlkpGnEVM,2006
87
88
  regressiontests/eigeningenuity/historian-multi/test_tagManagement.py,sha256=ylInBt453d1RaSih1eTTxGPZmb60UK4vMwI3UW-U1JY,4830
88
89
  regressiontests/eigeningenuity/historian-multi/test_writePoints.py,sha256=51tfUSLUqLKcCKJ1EyhjfzoC_4OP6n1oL3zgTSkXu4s,2696
89
- python_eigen_ingenuity_nocli-0.5.22b2.dist-info/METADATA,sha256=iRebeaO1ghKfxtXmIbX7Jlf83OF6AcGODLd1x-8ejLM,1436
90
- python_eigen_ingenuity_nocli-0.5.22b2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
91
- python_eigen_ingenuity_nocli-0.5.22b2.dist-info/top_level.txt,sha256=oDWOSmlNPKNBlIEKP8_JaV01O60jTcUIt2tDkq3OD18,56
92
- python_eigen_ingenuity_nocli-0.5.22b2.dist-info/RECORD,,
90
+ python_eigen_ingenuity_nocli-0.5.23.dist-info/METADATA,sha256=dFg9wjiv5Cke2uqffbsyX88AuSSf9J-q_3n7WJMMDmI,1434
91
+ python_eigen_ingenuity_nocli-0.5.23.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
92
+ python_eigen_ingenuity_nocli-0.5.23.dist-info/top_level.txt,sha256=oDWOSmlNPKNBlIEKP8_JaV01O60jTcUIt2tDkq3OD18,56
93
+ python_eigen_ingenuity_nocli-0.5.23.dist-info/RECORD,,