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

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

Comments

Loading...