shadowshell 0.0.40__tar.gz → 0.0.74__tar.gz

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.
Files changed (38) hide show
  1. {shadowshell-0.0.40 → shadowshell-0.0.74}/PKG-INFO +1 -1
  2. {shadowshell-0.0.40 → shadowshell-0.0.74}/pyproject.toml +2 -2
  3. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/config/configurator.py +6 -7
  4. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/configurator.py +1 -1
  5. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/logger_factory.py +6 -5
  6. shadowshell-0.0.74/src/shadowshell/monitor/monitor.py +86 -0
  7. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell.egg-info/PKG-INFO +1 -1
  8. shadowshell-0.0.40/src/shadowshell/monitor/monitor.py +0 -64
  9. {shadowshell-0.0.40 → shadowshell-0.0.74}/README.md +0 -0
  10. {shadowshell-0.0.40 → shadowshell-0.0.74}/setup.cfg +0 -0
  11. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/__init__.py +0 -0
  12. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/boot/__init__.py +0 -0
  13. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/boot/starter.py +0 -0
  14. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/bootstrap.py +0 -0
  15. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/config/__init__.py +0 -0
  16. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/console_logger.py +0 -0
  17. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/file/__init__.py +0 -0
  18. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/file/file_util.py +0 -0
  19. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/git_shell.py +0 -0
  20. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/logger.py +0 -0
  21. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/logging/__init__.py +0 -0
  22. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/logging/console_logger.py +0 -0
  23. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/logging/logger.py +0 -0
  24. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/logging/logger_factory.py +0 -0
  25. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/logging/logging_constants.py +0 -0
  26. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/monitor/__init__.py +0 -0
  27. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/serialize/__init__.py +0 -0
  28. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/serialize/serializer.py +0 -0
  29. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/serialize/serializer_factory.py +0 -0
  30. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/serialize/serializer_json.py +0 -0
  31. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/stock_trader.py +0 -0
  32. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/test/__init__.py +0 -0
  33. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell/test/test.py +0 -0
  34. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell.egg-info/SOURCES.txt +0 -0
  35. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell.egg-info/dependency_links.txt +0 -0
  36. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell.egg-info/requires.txt +0 -0
  37. {shadowshell-0.0.40 → shadowshell-0.0.74}/src/shadowshell.egg-info/top_level.txt +0 -0
  38. {shadowshell-0.0.40 → shadowshell-0.0.74}/tests/tests.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: shadowshell
3
- Version: 0.0.40
3
+ Version: 0.0.74
4
4
  Summary: www.shadowshell.xyz
5
5
  Author-email: shadowshell <shadowshellxyz@foxmail.com>
6
6
  License: MIT
@@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "shadowshell" # 全局唯一名称(检查PyPI是否被占用)
7
- version = "0.0.40" # 版本号(每次更新需递增)
8
- #version = "0.0.71" # 版本号(每次更新需递增)
7
+ #version = "0.0.41" # 版本号(每次更新需递增)
8
+ version = "0.0.74" # 版本号(每次更新需递增)
9
9
  authors = [{ name = "shadowshell", email = "shadowshellxyz@foxmail.com" }]
10
10
  description = "www.shadowshell.xyz"
11
11
  readme = "README.md"
@@ -8,24 +8,23 @@ Configurator
8
8
 
9
9
  import configparser
10
10
 
11
- from shadowshell import LoggerFactory
11
+ from shadowshell.logging import LoggerFactory
12
+ from shadowshell.monitor import function_monitor
13
+
14
+ class_name = "Configurator"
12
15
 
13
16
  class Configurator:
14
17
 
15
18
  config = None;
16
19
 
20
+ @function_monitor(class_name)
17
21
  def __init__(self, config_file):
18
-
19
- self.logger = LoggerFactory().get_logger()
20
-
21
- # 加载配置文件
22
22
  self.config = configparser.ConfigParser()
23
23
  self.config.read(config_file)
24
- self.logger.debug("load and read config file : %s." % (config_file))
25
24
 
25
+ @function_monitor(class_name)
26
26
  def get(self, group, key):
27
27
  value = self.config.get(group, key)
28
- self.logger.debug("group -> %s, key -> %s, value -> %s" % (group, key, value))
29
28
  return value
30
29
 
31
30
 
@@ -16,7 +16,7 @@ class Configurator:
16
16
 
17
17
  def __init__(self, config_file):
18
18
 
19
- self.logger = LoggerFactory().get_logger()
19
+ self.logger = LoggerFactory.get_logger()
20
20
 
21
21
  # 加载配置文件
22
22
  self.config = configparser.ConfigParser()
@@ -10,14 +10,15 @@ from shadowshell.console_logger import ConsoleLogger
10
10
 
11
11
  class LoggerFactory:
12
12
 
13
- logger = None
13
+ __logger = logger = ConsoleLogger()
14
14
 
15
15
  def __init__(self):
16
- self.logger = ConsoleLogger()
16
+ pass
17
17
 
18
- def get_logger(self, name = "default"):
19
- return self.logger
18
+ @staticmethod
19
+ def get_logger(name = "default"):
20
+ return LoggerFactory.__logger
20
21
 
21
22
  if __name__ == "__main__":
22
- LoggerFactory().get_logger().info("test")
23
+ LoggerFactory.get_logger().info("test")
23
24
 
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ @author: shadowshell
6
+ """
7
+
8
+ import sys
9
+ import time
10
+ from shadowshell.logging import LoggerFactory
11
+ from shadowshell.serialize import SerializerFactory
12
+ def __callback(request, response):
13
+ logger = LoggerFactory.get_logger()
14
+ logger.info(f"[CALLBACK][Request]{__format_request(request)}[Response]{__format_response(response)}")
15
+
16
+ def performance_monitor(class_name = None):
17
+ def decorator(func):
18
+ def wrapper(*args, **kwargs):
19
+ start = time.perf_counter()
20
+ response = None
21
+ is_successed = True
22
+ try:
23
+ response = func(*args, **kwargs)
24
+ except:
25
+ LoggerFactory.get_logger().error(sys.exc_info()[0])
26
+ is_successed = False
27
+ raise
28
+ finally:
29
+ cost = time.perf_counter() - start
30
+ # log
31
+ __record_digest_log("PERFORMANCE_MONITOR", class_name, func.__name__, cost, is_successed)
32
+ return response
33
+ return wrapper
34
+ return decorator
35
+
36
+ def function_monitor(class_name = None, callback = __callback):
37
+ logger = LoggerFactory.get_logger()
38
+ def decorator(func):
39
+ def wrapper(*args, **kwargs):
40
+ start = time.perf_counter()
41
+ response = None
42
+ is_successed = True
43
+ try:
44
+ response = func(*args, **kwargs)
45
+ except Exception as e:
46
+ logger.error(e)
47
+ is_successed = False
48
+ raise
49
+ except:
50
+ logger.error(sys.exc_info()[0])
51
+ is_successed = False
52
+ raise
53
+ finally:
54
+ cost = time.perf_counter() - start
55
+ # log
56
+ __record_digest_log("FUNCTION_MONITOR", class_name, func.__name__, cost, is_successed)
57
+ __record_detail_log("FUNCTION_MONITOR", class_name, func.__name__, args, response)
58
+ # callback
59
+ if callback is not None:
60
+ try:
61
+ callback(args, response)
62
+ finally:
63
+ logger.error(sys.exc_info()[0])
64
+
65
+ return response
66
+ return wrapper
67
+ return decorator
68
+
69
+ def __get_service_name(class_name, func_name):
70
+ service_name = func_name
71
+ if (class_name is not None):
72
+ service_name = class_name + "." + func_name
73
+ return service_name
74
+
75
+ def __format_request(request):
76
+ return SerializerFactory.get_instance().serialize(request)
77
+
78
+ def __format_response(response):
79
+ return SerializerFactory.get_instance().serialize(response)
80
+ def __record_digest_log(monitor_name, class_name, func_name, cost, is_successed):
81
+ logger = LoggerFactory.get_logger()
82
+ logger.info(f"[{monitor_name}][DIGEST_LOG][{__get_service_name(class_name, func_name)}]successed={is_successed}, cost:{cost:.6f}s.")
83
+
84
+ def __record_detail_log(monitor_name, class_name, func_name, request, response):
85
+ logger = LoggerFactory.get_logger()
86
+ logger.info(f"[{monitor_name}][DETAIL_LOG][{__get_service_name(class_name, func_name)}][Request]{__format_request(request)}[Response]{__format_response(response)}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: shadowshell
3
- Version: 0.0.40
3
+ Version: 0.0.74
4
4
  Summary: www.shadowshell.xyz
5
5
  Author-email: shadowshell <shadowshellxyz@foxmail.com>
6
6
  License: MIT
@@ -1,64 +0,0 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
-
4
- """
5
- @author: shadowshell
6
- """
7
-
8
- import sys
9
- import time
10
- from shadowshell.logging import LoggerFactory
11
-
12
- logger = LoggerFactory().get_logger()
13
-
14
- def performance_monitor(class_name=None):
15
- def decorator(func):
16
- def wrapper(*args, **kwargs):
17
- start = time.perf_counter()
18
- result = None
19
- try:
20
- result = func(*args, **kwargs)
21
- finally:
22
- elapsed = time.perf_counter() - start
23
- if (class_name is not None):
24
- logger.info(f"[PERFORMANCE_MONITOR][{class_name}.{func.__name__}] has ran, time elapsed:{elapsed:.6f}s.")
25
- else:
26
- logger.info(f"[PERFORMANCE_MONITOR][{func.__name__}] has ran, time elapsed:{elapsed:.6f}s.")
27
- return result
28
- return wrapper
29
- return decorator
30
-
31
- def function_monitor(class_name=None, callback=None):
32
- def decorator(func):
33
- def wrapper(*args, **kwargs):
34
- start = time.perf_counter()
35
- result = None
36
- is_success = True
37
- try:
38
- result = func(*args, **kwargs)
39
- except Exception as e:
40
- logger.error(e)
41
- is_success = False
42
- raise
43
- except:
44
- logger.error(sys.exc_info()[0])
45
- is_success = False
46
- raise
47
- finally:
48
- elapsed = time.perf_counter() - start
49
- # log
50
- if (class_name is not None):
51
- logger.info(f"[FUNCTION_MONITOR][{class_name}.{func.__name__}] has ran, is_success={is_success}, time elapsed:{elapsed:.6f}s.")
52
- else:
53
- logger.info(f"[FUNCTION_MONITOR][{func.__name__}] has ran, is_success={is_success}, time elapsed:{elapsed:.6f}s.")
54
-
55
- # callback
56
- if callback is not None:
57
- try:
58
- callback(args, kwargs, result, f"{elapsed:.6f}")
59
- finally:
60
- logger.error(sys.exc_info()[0])
61
-
62
- return result
63
- return wrapper
64
- return decorator
File without changes
File without changes