fmtr.tools 1.0.23__py3-none-any.whl → 1.0.25__py3-none-any.whl

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.

Potentially problematic release.


This version of fmtr.tools might be problematic. Click here for more details.

@@ -1,71 +1,57 @@
1
- import sys
1
+ import logging
2
+ import os
2
3
 
3
- from fmtr.tools.config import ToolsConfig
4
- from fmtr.tools.config_tools import ConfigClass
5
- from fmtr.tools.environment_tools import get
6
- from fmtr.tools.path_tools import Path
4
+ from fmtr.tools import environment_tools
7
5
 
6
+ DEVELOPMENT = "development"
7
+ PRODUCTION = "production"
8
+ HOST_DEFAULT = "log.sv.fmtr.dev"
9
+ ORG_DEFAULT = "fmtr"
10
+ STREAM_DEFAULT = DEVELOPMENT
11
+ ENVIRONMENT_DEFAULT = DEVELOPMENT
8
12
 
9
- class LoggingConfig(ConfigClass):
10
- SEP = ' '
11
- TIME = '<bold><green>{time:' + ToolsConfig.DATETIME_FILENAME_FORMAT + '}</green></bold>'
12
- ICON = '<level>{level.icon}</level>'
13
- LEVEL = '<level>{level:<8}</level>'
14
- FILE = '{file}:{line}'
15
- FUNCTION = '{function}(…)'
16
- MESSAGE = '{message}'
17
- DEFAULT_LEVEL_KEY = 'FMTR_LOG_LEVEL'
18
- DEFAULT_LEVEL = get(DEFAULT_LEVEL_KEY, 'INFO')
13
+ LEVEL_DEFAULT = logging.DEBUG if environment_tools.IS_DEBUG else logging.INFO
19
14
 
20
- FILENAME = f'log-{ToolsConfig.DATETIME_NOW_STR}.log'
21
15
 
22
-
23
- def default_filter(record):
24
- return True
25
-
26
-
27
- def default_patch(record):
28
- return record
29
-
30
-
31
- def get_logger(terminal=True, level=LoggingConfig.DEFAULT_LEVEL, time_format=LoggingConfig.TIME,
32
- icon_format=LoggingConfig.ICON,
33
- level_format=LoggingConfig.LEVEL, file_format=LoggingConfig.FILE, function_format=LoggingConfig.FUNCTION,
34
- message_format=LoggingConfig.MESSAGE,
35
- logfile=False, logfile_dir=None):
16
+ def get_logger(name, version, host=HOST_DEFAULT, org=ORG_DEFAULT, stream=STREAM_DEFAULT,
17
+ environment=ENVIRONMENT_DEFAULT, level=LEVEL_DEFAULT):
36
18
  """
37
19
 
38
- Get a pre-configured loguru logger, if dependency is present, otherwise default to native logger.
20
+ Get a pre-configured logfire logger, if dependency is present, otherwise default to native logger.
39
21
 
40
22
  """
41
23
 
42
24
  try:
43
- from loguru import logger as logger_loguru
44
- logger = logger_loguru
25
+ import logfire
45
26
  except ImportError:
46
- import logging
47
-
48
27
  logger = logging.getLogger(None)
49
28
  logger.setLevel(level)
29
+ logger.warning(f'Logging dependencies not installed. Using native logger.')
50
30
 
51
31
  return logger
52
32
 
33
+ key = environment_tools.get("FMTR_OBS_API_KEY")
34
+ traces_endpoint = f"https://{host}/api/{org}/v1/traces"
35
+ headers = f"Authorization=Basic {key},stream-name={stream}"
53
36
 
37
+ os.environ["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] = traces_endpoint
38
+ os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = headers
39
+ os.environ["OTEL_EXPORTER_OTLP_INSECURE"] = str(False).lower()
54
40
 
55
- components = [time_format, icon_format, level_format, file_format, function_format, message_format]
56
- format = LoggingConfig.SEP.join([component for component in components if component])
57
- logger.remove()
41
+ logfire.configure(
42
+ service_name=name,
43
+ service_version=version,
44
+ environment=environment,
45
+ send_to_logfire=False
58
46
 
59
- if terminal:
60
- logger.add(sys.stderr, format=format, level=level, filter=default_filter)
61
- logger = logger.patch(default_patch)
47
+ )
62
48
 
63
- if logfile:
64
- logfile_dir = Path(logfile_dir or '.')
65
- logfile_path = logfile_dir / LoggingConfig.FILENAME
66
- logger.add(logfile_path, format=format)
49
+ logging.getLogger(name).setLevel(level)
67
50
 
51
+ logger = logfire
68
52
  return logger
69
53
 
70
54
 
55
+ logger = get_logger(name='fmtr.tools', version='0.0.0')
56
+
71
57
  logger = get_logger()
fmtr/tools/version CHANGED
@@ -1 +1 @@
1
- 1.0.23
1
+ 1.0.25
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fmtr.tools
3
- Version: 1.0.23
3
+ Version: 1.0.25
4
4
  Summary: Collection of high-level tools to simplify everyday development tasks, with a focus on AI/ML
5
5
  Home-page: https://github.com/fmtr/fmtr.tools
6
6
  Author: Frontmatter
@@ -21,7 +21,7 @@ Requires-Dist: pydantic ; extra == 'ai.client'
21
21
  Requires-Dist: pydantic-ai[openai] ; extra == 'ai.client'
22
22
  Provides-Extra: api
23
23
  Requires-Dist: fastapi ; extra == 'api'
24
- Requires-Dist: loguru ; extra == 'api'
24
+ Requires-Dist: logfire ; extra == 'api'
25
25
  Requires-Dist: pydantic ; extra == 'api'
26
26
  Requires-Dist: uvicorn ; extra == 'api'
27
27
  Provides-Extra: augmentation
@@ -48,7 +48,7 @@ Requires-Dist: streamlit ; extra == 'interface'
48
48
  Provides-Extra: json-fix
49
49
  Requires-Dist: json-repair ; extra == 'json-fix'
50
50
  Provides-Extra: logging
51
- Requires-Dist: loguru ; extra == 'logging'
51
+ Requires-Dist: logfire ; extra == 'logging'
52
52
  Provides-Extra: merging
53
53
  Requires-Dist: deepmerge ; extra == 'merging'
54
54
  Provides-Extra: metric
@@ -62,7 +62,7 @@ Requires-Dist: bokeh ; extra == 'parallel'
62
62
  Requires-Dist: dask[bag] ; extra == 'parallel'
63
63
  Requires-Dist: distributed ; extra == 'parallel'
64
64
  Provides-Extra: process
65
- Requires-Dist: loguru ; extra == 'process'
65
+ Requires-Dist: logfire ; extra == 'process'
66
66
  Provides-Extra: profiling
67
67
  Requires-Dist: contexttimer ; extra == 'profiling'
68
68
  Provides-Extra: semantic
@@ -88,7 +88,7 @@ Requires-Dist: google-auth-oauthlib ; extra == 'test'
88
88
  Requires-Dist: html2text ; extra == 'test'
89
89
  Requires-Dist: huggingface-hub ; extra == 'test'
90
90
  Requires-Dist: json-repair ; extra == 'test'
91
- Requires-Dist: loguru ; extra == 'test'
91
+ Requires-Dist: logfire ; extra == 'test'
92
92
  Requires-Dist: ollama ; extra == 'test'
93
93
  Requires-Dist: openai ; extra == 'test'
94
94
  Requires-Dist: pandas ; extra == 'test'
@@ -244,9 +244,9 @@ The included modules, plus any extra requirements, are as follows:
244
244
  - Extras: `semantic`
245
245
  - `tools.string`: Provides utilities for handling string formatting.
246
246
  - Extras: None
247
- - `tools.logging`: Configures and initializes a logger using the Loguru library. Provides customizable logging formats for time, level, file, function, and message components.
247
+ - `tools.logging`: Configures and initializes a logger using the Logfire library to log to an OpenTelemetry consumer.
248
248
  - Extras: `logging`
249
- - `tools.logger`: Prefabricated `logger` object, suitable for most projects, timestamped, color-coded, etc.
249
+ - `tools.logger`: Prefabricated `logger` object, suitable for most projects: service name, timestamped, etc.
250
250
  - Extras: `logging`
251
251
  - `tools.augmentation`: Data augmentation stub.
252
252
  - Extras: `augmentation`
@@ -23,7 +23,7 @@ fmtr/tools/interface_tools.py,sha256=fi0KW0veB2NQCmVmCA9iJUL_03gz0MD-gJ4OK-QUBVA
23
23
  fmtr/tools/iterator_tools.py,sha256=xj5f0c7LgLK53dddRRRJxBoLaBzlZoQS3_GfmpDPMoo,1311
24
24
  fmtr/tools/json_fix_tools.py,sha256=vNSlswVQnujPmKEqDjFJcO901mjMyv59q3awsT7mlhs,477
25
25
  fmtr/tools/json_tools.py,sha256=IKmrANhcftIz2msCZeItidJ1PcpY_tnbfxbRDnta-c0,349
26
- fmtr/tools/logging_tools.py,sha256=bO2w0L68IQSD4-ZEdSRxC_hrvZJGih1FNzPTO3inGEA,2040
26
+ fmtr/tools/logging_tools.py,sha256=-2yq4Q4ix2GAhfaiVVIewTugVJhRQbCC5WhUX0pBbH0,1527
27
27
  fmtr/tools/merging_tools.py,sha256=KDxCEFJEQJEwGw1qGKAgR55uUE2X2S5NWLKcfHRmX_k,227
28
28
  fmtr/tools/metric_tools.py,sha256=Lvia5CGFRIfrDFA8s37btIfTU5zHbo04cPJdAMtbndQ,272
29
29
  fmtr/tools/name_tools.py,sha256=5CB_phqhHjl66iI8oLxOGPF2odC1apdul-M8Fv2xBhs,5514
@@ -41,7 +41,7 @@ fmtr/tools/string_tools.py,sha256=w0lw70bgzJ8tAHj_4lMrjtMyefE5kELgpCBgGzGcalo,31
41
41
  fmtr/tools/tokenization_tools.py,sha256=9FP5vgPufWv0XA961eVKObFll0d_2mM0W3ut3rtZyeo,4329
42
42
  fmtr/tools/tools.py,sha256=xnfUrOnrT4OxFYez6vV5tAhydzCICJFiGVnviiZDEQo,796
43
43
  fmtr/tools/unicode_tools.py,sha256=yS_9wpu8ogNoiIL7s1G_8bETFFO_YQlo4LNPv1NLDeY,52
44
- fmtr/tools/version,sha256=-0IsOoAYGw3apMf_bkqNUj3ez-bflN6Nhv4yAlIek9U,6
44
+ fmtr/tools/version,sha256=g68-alC5ZPPI3XsrxUra7Vi69ztfWGBJHODg-kMqXc4,6
45
45
  fmtr/tools/version_tools.py,sha256=pHxD425tc5JhGfMjE3-lRLnJOVPpf63Y5FGha5ntiVY,1112
46
46
  fmtr/tools/yaml_tools.py,sha256=Ol43ZwbnSXGnn1K98Uxx61KPGSqfC4axE-X2q1LKMwk,349
47
47
  fmtr/tools/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -52,9 +52,9 @@ fmtr/tools/tests/test_environment.py,sha256=iHaiMQfECYZPkPKwfuIZV9uHuWe3aE-p_dN_
52
52
  fmtr/tools/tests/test_json.py,sha256=IeSP4ziPvRcmS8kq7k9tHonC9rN5YYq9GSNT2ul6Msk,287
53
53
  fmtr/tools/tests/test_path.py,sha256=AkZQa6_8BQ-VaCyL_J-iKmdf2ZaM-xFYR37Kun3k4_g,2188
54
54
  fmtr/tools/tests/test_yaml.py,sha256=jc0TwwKu9eC0LvFGNMERdgBue591xwLxYXFbtsRwXVM,287
55
- fmtr.tools-1.0.23.dist-info/LICENSE,sha256=FW9aa6vVN5IjRQWLT43hs4_koYSmpcbIovlKeAJ0_cI,10757
56
- fmtr.tools-1.0.23.dist-info/METADATA,sha256=DnR_GKPlVgKaCMqgLCiqWnA0XaDQqvg5a_RiHqp_7qQ,12854
57
- fmtr.tools-1.0.23.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
58
- fmtr.tools-1.0.23.dist-info/entry_points.txt,sha256=CEStVkwJ1mTFvhN1WV5RdW83SkNW1d5Syj-KZ6A19ng,72
59
- fmtr.tools-1.0.23.dist-info/top_level.txt,sha256=t5341a8ii3n4RFizwTeXGmcq_pf4GqL1h9ylE5LIWRk,12
60
- fmtr.tools-1.0.23.dist-info/RECORD,,
55
+ fmtr.tools-1.0.25.dist-info/LICENSE,sha256=FW9aa6vVN5IjRQWLT43hs4_koYSmpcbIovlKeAJ0_cI,10757
56
+ fmtr.tools-1.0.25.dist-info/METADATA,sha256=M81uS0nLsDF31jgvgrzFIk_n05ls5u912iakzyZBpsA,12801
57
+ fmtr.tools-1.0.25.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
58
+ fmtr.tools-1.0.25.dist-info/entry_points.txt,sha256=CEStVkwJ1mTFvhN1WV5RdW83SkNW1d5Syj-KZ6A19ng,72
59
+ fmtr.tools-1.0.25.dist-info/top_level.txt,sha256=t5341a8ii3n4RFizwTeXGmcq_pf4GqL1h9ylE5LIWRk,12
60
+ fmtr.tools-1.0.25.dist-info/RECORD,,