Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

#381 Feature/sg 000 connect to lab

Merged
Ghost merged 1 commits into Deci-AI:master from deci-ai:feature/sg-000_connect_to_lab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
  1. import json
  2. import os
  3. import pkg_resources
  4. from super_gradients.common.environment.environment_config import DEFAULT_LOGGING_LEVEL
  5. class AutoLoggerConfig:
  6. """
  7. A Class for the Automated Logging Config that is created from the JSON config file (auto_logging_conf)
  8. """
  9. @staticmethod
  10. def generate_config_for_module_name(
  11. module_name,
  12. training_log_path=None,
  13. log_level=DEFAULT_LOGGING_LEVEL,
  14. max_bytes=10485760,
  15. logs_dir_path=None,
  16. handlers_list=None,
  17. ) -> dict:
  18. """
  19. generate_config_for_module_name - Returns a Config Dict For Logging
  20. :param module_name: The Python Module name to create auto_logging for
  21. :param log_level: Minimal log level to set for the new auto_logging
  22. :param max_bytes: Max size for the log file before rotation starts
  23. :param handlers_list: A list specifying the handlers (Console, etc..) - Better Leave Empty or None
  24. :param training_log_path: Path to training log file which all modules of super_gradients will write to. Ignored
  25. when set to None.
  26. :param logs_dir_path: Path to sg_logs directory (default=None), where module logs will be saved. When set
  27. to None- module logs will be saved in ~/sg_logs (created if path does not exist). Main use case is for
  28. testing.
  29. :return: python dict() with the new auto_logging for the module
  30. """
  31. # LOADING THE ORIGINAL ROOT CONFIG FILE
  32. conf_file_name = "auto_logging_conf.json"
  33. conf_file_path = os.path.join(
  34. pkg_resources.resource_filename("super_gradients", "/common/auto_logging/"), conf_file_name
  35. )
  36. with open(conf_file_path, "r") as logging_configuration_file:
  37. config_dict = json.load(logging_configuration_file)
  38. # CREATING THE PATH TO THE "HOME" FOLDER WITH THE LOG FILE NAME
  39. if not logs_dir_path:
  40. log_file_name = module_name + ".log"
  41. user_dir = os.path.expanduser(r"~")
  42. logs_dir_path = os.path.join(user_dir, "sg_logs")
  43. if not os.path.exists(logs_dir_path):
  44. try:
  45. os.mkdir(logs_dir_path)
  46. except Exception as ex:
  47. print(
  48. "[WARNING] - sg_logs folder was not found and couldn't be created from the code - "
  49. "All of the Log output will be sent to Console!" + str(ex)
  50. )
  51. # HANDLERS LIST IS EMPTY AS CONSOLE IS ONLY ROOT HANDLER BECAUSE MODULE LOGGERS PROPAGATE THEIR LOGS UP.
  52. handlers_list = []
  53. logger = {"level": log_level, "handlers": handlers_list, "propagate": True}
  54. config_dict["loggers"][module_name] = logger
  55. return config_dict
  56. log_file_path = os.path.join(logs_dir_path, log_file_name)
  57. # THE ENTRIES TO ADD TO THE ORIGINAL CONFIGURATION
  58. handler_name = module_name + "_file_handler"
  59. file_handler = {
  60. "class": "logging.handlers.RotatingFileHandler",
  61. "level": log_level,
  62. "formatter": "fileFormatter",
  63. "filename": log_file_path,
  64. "maxBytes": max_bytes,
  65. "backupCount": 20,
  66. "encoding": "utf8",
  67. }
  68. # CREATING ONLY A FILE HANDLER, CONSOLE IS ONLY ROOT HANDLER AS MODULE LOGGERS PROPAGATE THEIR LOGS UP.
  69. if handlers_list is None or handlers_list.empty():
  70. handlers_list = [handler_name]
  71. logger = {"level": log_level, "handlers": handlers_list, "propagate": True}
  72. # ADDING THE NEW LOGGER ENTRIES TO THE CONFIG DICT
  73. config_dict["handlers"][handler_name] = file_handler
  74. config_dict["loggers"][module_name] = logger
  75. config_dict["root"]["handlers"].append(handler_name)
  76. if training_log_path:
  77. training_file_handler = {
  78. "class": "logging.handlers.RotatingFileHandler",
  79. "level": log_level,
  80. "formatter": "fileFormatter",
  81. "filename": training_log_path,
  82. "maxBytes": max_bytes,
  83. "backupCount": 20,
  84. "encoding": "utf8",
  85. }
  86. # ALL OF DECI_TRAINER MODULES LOGGERS PROPAGATE UP TO THE ROOT SO THE ADD TRAIN FILE HANDLER FOR THE ROOT.
  87. config_dict["handlers"]["training"] = training_file_handler
  88. config_dict["root"]["handlers"].append("training")
  89. return config_dict
Discard
Tip!

Press p or to see the previous file or, n or to see the next file