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

logger.py 1016 B

You have to be logged in to leave a comment. Sign In
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
  1. import logging
  2. import os
  3. from datetime import datetime
  4. """
  5. Utility functions for logging.
  6. This module provides functions for configuring logging settings and defining custom exceptions.
  7. Functions:
  8. setup_logging: Configure logging settings.
  9. CustomException: Custom exception class for handling errors.
  10. """
  11. # -- Create a logging file path configuration --
  12. LOG_FILE = f"{datetime.now().strftime('%m_%d_%Y_%H_%M_%S')}.log" # define file name using date format
  13. logs_path = os.path.join(os.getcwd(),"logs", LOG_FILE) # define the targeted path to store the file
  14. # generate the folder
  15. os.makedirs(logs_path, exist_ok=True) # create the logging file
  16. LOG_FILE_PATH = os.path.join(logs_path, LOG_FILE) # define the targeted path
  17. # -- Logging info into the file
  18. logging.basicConfig(
  19. filename = LOG_FILE_PATH,
  20. format = "[ %(asctime)s] %(lineno)d %(name)s - %(levelname)s - %(message)s",
  21. level = logging.INFO, # has many (can check documentation), but .INFO is just level for general information
  22. )
Tip!

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

Comments

Loading...