zzstoatzz commited on
Commit
e1f78df
·
1 Parent(s): 13fe992

add rich handler and dotenv loading for settings

Browse files
src/fastmcp/cli/cli.py CHANGED
@@ -13,7 +13,7 @@ from typing_extensions import Annotated
13
  from ..utilities.logging import get_logger
14
  from . import claude
15
 
16
- logger = get_logger(__name__)
17
 
18
  app = typer.Typer(
19
  name="fastmcp",
@@ -352,7 +352,7 @@ def install(
352
  with_packages=with_packages,
353
  force=force,
354
  ):
355
- print(f"Successfully installed {name} in Claude app")
356
  else:
357
- print(f"Failed to install {name} in Claude app")
358
  sys.exit(1)
 
13
  from ..utilities.logging import get_logger
14
  from . import claude
15
 
16
+ logger = get_logger("cli")
17
 
18
  app = typer.Typer(
19
  name="fastmcp",
 
352
  with_packages=with_packages,
353
  force=force,
354
  ):
355
+ logger.info(f"Successfully installed {name} in Claude app")
356
  else:
357
+ logger.error(f"Failed to install {name} in Claude app")
358
  sys.exit(1)
src/fastmcp/server.py CHANGED
@@ -53,7 +53,11 @@ class Settings(BaseSettings):
53
  For example, FASTMCP_DEBUG=true will set debug=True.
54
  """
55
 
56
- model_config: SettingsConfigDict = SettingsConfigDict(env_prefix="FASTMCP_")
 
 
 
 
57
 
58
  # Server settings
59
  debug: bool = False
 
53
  For example, FASTMCP_DEBUG=true will set debug=True.
54
  """
55
 
56
+ model_config: SettingsConfigDict = SettingsConfigDict(
57
+ env_prefix="FASTMCP_",
58
+ env_file=".env",
59
+ extra="ignore",
60
+ )
61
 
62
  # Server settings
63
  debug: bool = False
src/fastmcp/utilities/logging.py CHANGED
@@ -1,30 +1,31 @@
1
- """Logging utilities for FastMCP."""
2
 
3
  import logging
4
  from typing import Literal
5
 
 
 
6
 
7
  def get_logger(name: str) -> logging.Logger:
8
- """Get a logger nested under FastMCP namespace.
9
 
10
- Args:
11
- name: The name of the logger, which will be prefixed with 'FastMCP.'
12
 
13
- Returns:
14
- A configured logger instance
15
  """
16
- return logging.getLogger(f"FastMCP.{name}")
17
 
18
 
19
  def configure_logging(
20
  level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "INFO",
21
  ) -> None:
22
- """Configure logging for FastMCP.
23
 
24
- Args:
25
- level: The log level to use
26
  """
27
  logging.basicConfig(
28
- level=level,
29
- format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
30
  )
 
1
+ """logging utilities for fastmcp"""
2
 
3
  import logging
4
  from typing import Literal
5
 
6
+ from rich.logging import RichHandler
7
+
8
 
9
  def get_logger(name: str) -> logging.Logger:
10
+ """get a logger nested under fastmcp namespace.
11
 
12
+ args:
13
+ name: the name of the logger, which will be prefixed with 'fastmcp.'
14
 
15
+ returns:
16
+ a configured logger instance
17
  """
18
+ return logging.getLogger(f"fastmcp.{name}")
19
 
20
 
21
  def configure_logging(
22
  level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "INFO",
23
  ) -> None:
24
+ """configure logging for fastmcp.
25
 
26
+ args:
27
+ level: the log level to use
28
  """
29
  logging.basicConfig(
30
+ level=level, format="%(message)s", handlers=[RichHandler(rich_tracebacks=True)]
 
31
  )