azure-deploy-cli 0.1.6__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.
@@ -0,0 +1,125 @@
1
+ import logging
2
+ import sys
3
+ from typing import cast
4
+
5
+ # Color codes for output
6
+ RED = "\033[0;31m"
7
+ GREEN = "\033[0;32m"
8
+ YELLOW = "\033[1;33m"
9
+ BLUE = "\033[0;34m"
10
+ NC = "\033[0m" # No Color
11
+
12
+ # Symbol map for each log level
13
+ LEVEL_SYMBOLS = {
14
+ "DEBUG": f"{BLUE}ℹ{NC}",
15
+ "INFO": f"{BLUE}ℹ{NC}",
16
+ "SUCCESS": f"{GREEN}✓{NC}",
17
+ "WARNING": f"{YELLOW}⚠{NC}",
18
+ "ERROR": f"{RED}✗{NC}",
19
+ "CRITICAL": f"{GREEN}✓{NC}",
20
+ }
21
+
22
+ # Custom log level
23
+ SUCCESS_LEVEL = 25
24
+ STDOUT_LEVEL = 26
25
+
26
+
27
+ class ColoredFormatter(logging.Formatter):
28
+ """Custom formatter that adds colored symbols based on log level"""
29
+
30
+ def format(self, record: logging.LogRecord) -> str:
31
+ # For stdout, don't add any symbols
32
+ if record.levelno == STDOUT_LEVEL:
33
+ return super().format(record)
34
+
35
+ symbol = LEVEL_SYMBOLS.get(record.levelname, "")
36
+ record.msg = f"{symbol} {record.msg}"
37
+ return super().format(record)
38
+
39
+
40
+ class CCLogger(logging.Logger):
41
+ """Custom logger with success and stdout methods"""
42
+
43
+ def success(self, message: str, *args, **kwargs) -> None:
44
+ """Log success message"""
45
+ self.log(SUCCESS_LEVEL, message, *args, **kwargs)
46
+
47
+ def stdout(self, message: str, *args, **kwargs) -> None:
48
+ """Log a message to stdout"""
49
+ self.log(STDOUT_LEVEL, message, *args, **kwargs)
50
+
51
+
52
+ configured = False
53
+
54
+
55
+ def configure_logging(level: str = "info") -> None:
56
+ """
57
+ Configure root logger.
58
+
59
+ - All logs except STDOUT go to stderr.
60
+ - STDOUT level logs go to stdout.
61
+ - Log level is configurable (debug, info, warning, error, critical, none).
62
+ """
63
+ global configured
64
+ if configured:
65
+ return
66
+ # Set custom logger class
67
+ logging.setLoggerClass(CCLogger)
68
+
69
+ # Add custom levels
70
+ logging.SUCCESS = SUCCESS_LEVEL # type: ignore
71
+ logging.addLevelName(SUCCESS_LEVEL, "SUCCESS")
72
+ logging.STDOUT = STDOUT_LEVEL # type: ignore
73
+ logging.addLevelName(STDOUT_LEVEL, "STDOUT")
74
+
75
+ root_logger = logging.getLogger()
76
+
77
+ # Only configure if not already configured
78
+ if root_logger.handlers:
79
+ return
80
+
81
+ # Map string level to logging constant
82
+ level_upper = level.upper()
83
+ log_level = logging.getLevelName(level_upper)
84
+
85
+ root_logger.setLevel(log_level)
86
+
87
+ # Handler for stderr (all logs except stdout)
88
+ stderr_handler = logging.StreamHandler(sys.stderr)
89
+ stderr_handler.setLevel(log_level)
90
+ stderr_handler.addFilter(lambda record: record.levelno != STDOUT_LEVEL)
91
+ stderr_handler.setFormatter(ColoredFormatter("%(message)s"))
92
+ root_logger.addHandler(stderr_handler)
93
+
94
+ # Handler for stdout (only for STDOUT level)
95
+ stdout_handler = logging.StreamHandler(sys.stdout)
96
+ stdout_handler.setLevel(STDOUT_LEVEL)
97
+ stdout_handler.addFilter(lambda record: record.levelno == STDOUT_LEVEL)
98
+ # No formatter needed, just output the message
99
+ stdout_handler.setFormatter(logging.Formatter("%(message)s"))
100
+ root_logger.addHandler(stdout_handler)
101
+
102
+ # Suppress noisy third-party logs
103
+ logging.getLogger("azure.identity").setLevel(logging.WARNING)
104
+ logging.getLogger("azure.core").setLevel(logging.WARNING)
105
+ logging.getLogger("azure.mgmt").setLevel(logging.WARNING)
106
+ logging.getLogger("urllib3").setLevel(logging.WARNING)
107
+ logging.getLogger("urllib3.connectionpool").setLevel(logging.WARNING)
108
+ logging.getLogger("http.connectionpool").setLevel(logging.WARNING)
109
+ configured = True
110
+
111
+
112
+ def get_logger(name: str) -> CCLogger:
113
+ """
114
+ Get a properly typed CCLogger instance.
115
+
116
+ This should be called after configure_logging() has been called in main().
117
+
118
+ Args:
119
+ name: Logger name (usually __name__)
120
+
121
+ Returns:
122
+ CCLogger instance with success() method
123
+ """
124
+ configure_logging()
125
+ return cast(CCLogger, logging.getLogger(name))
File without changes