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

__init__.py 1.1 KB

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
33
34
35
36
37
38
39
40
41
42
43
44
  1. import sys
  2. import pathlib
  3. import logging
  4. _simple_format = logging.Formatter('{asctime} [{levelname:7s}] {name} {message}',
  5. datefmt='%Y-%m-%d %H:%M:%S',
  6. style='{')
  7. _initialized = False
  8. def setup(debug=False):
  9. global _initialized
  10. ch = logging.StreamHandler(sys.stderr)
  11. ch.setLevel(logging.DEBUG if debug else logging.INFO)
  12. ch.setFormatter(_simple_format)
  13. root = logging.getLogger()
  14. root.addHandler(ch)
  15. root.setLevel(logging.INFO)
  16. logging.getLogger('dvc').setLevel(logging.ERROR)
  17. logging.getLogger('lenskit').setLevel(logging.DEBUG)
  18. logging.getLogger('').setLevel(logging.DEBUG)
  19. root.debug('log system configured')
  20. _initialized = True
  21. def script_log(name, debug=False):
  22. """
  23. Initialize logging and get a logger for a script.
  24. Args:
  25. name(str): The ``__file__`` of the script being run.
  26. debug(bool): whether to enable debug logging to the console
  27. """
  28. if not _initialized:
  29. setup(debug)
  30. name = pathlib.Path(name).stem
  31. logger = logging.getLogger(name)
  32. return logger
Tip!

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

Comments

Loading...