Coverage for src/ezplog/config/_defaults.py: 78.85%

46 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-10-16 19:04 +0000

1# /////////////////////////////////////////////////////////////// 

2# EZPL - Default Configuration 

3# Project: ezpl 

4# /////////////////////////////////////////////////////////////// 

5 

6""" 

7Default configuration values for Ezpl logging framework. 

8 

9This module defines all default configuration values used throughout the application. 

10""" 

11 

12from __future__ import annotations 

13 

14# /////////////////////////////////////////////////////////////// 

15# IMPORTS 

16# /////////////////////////////////////////////////////////////// 

17# Standard library imports 

18import os 

19import sys 

20from pathlib import Path 

21from typing import Any 

22 

23# /////////////////////////////////////////////////////////////// 

24# FUNCTIONS 

25# /////////////////////////////////////////////////////////////// 

26 

27 

28def _get_app_data_dir() -> Path: 

29 """ 

30 Get the application data directory (cross-platform). 

31 

32 Returns: 

33 - Windows: %APPDATA% (Roaming) 

34 - Linux: ~/.local/share 

35 - macOS: ~/Library/Application Support 

36 """ 

37 if sys.platform == "win32": 37 ↛ 39line 37 didn't jump to line 39 because the condition on line 37 was never true

38 # Windows: Use APPDATA (Roaming) 

39 appdata = os.getenv("APPDATA") 

40 if appdata: 

41 return Path(appdata) / "ezpl" 

42 # Fallback to user home 

43 return Path.home() / "AppData" / "Local" / "ezpl" 

44 elif sys.platform == "darwin": 44 ↛ 46line 44 didn't jump to line 46 because the condition on line 44 was never true

45 # macOS: ~/Library/Application Support 

46 return Path.home() / "Library" / "Application Support" / "ezpl" 

47 else: 

48 # Linux: ~/.local/share 

49 return Path.home() / ".local" / "share" / "ezpl" 

50 

51 

52# /////////////////////////////////////////////////////////////// 

53# CLASSES 

54# /////////////////////////////////////////////////////////////// 

55 

56 

57class DefaultConfiguration: 

58 """ 

59 Default configuration values for Ezpl. 

60 

61 This class provides centralized access to all default configuration values. 

62 """ 

63 

64 # /////////////////////////////////////////////////////////////// 

65 # LOGGING DEFAULTS 

66 # /////////////////////////////////////////////////////////////// 

67 

68 LOG_LEVEL = "INFO" 

69 LOG_FILE = "ezpl.log" 

70 # Use cross-platform app data directory for logs if no path specified 

71 LOG_DIR = _get_app_data_dir() / "logs" 

72 

73 # /////////////////////////////////////////////////////////////// 

74 # PRINTER DEFAULTS 

75 # /////////////////////////////////////////////////////////////// 

76 

77 PRINTER_LEVEL = "INFO" 

78 INDENT_STEP = 3 

79 INDENT_SYMBOL = ">" 

80 BASE_INDENT_SYMBOL = "~" 

81 

82 # /////////////////////////////////////////////////////////////// 

83 # FILE LOGGER DEFAULTS 

84 # /////////////////////////////////////////////////////////////// 

85 

86 FILE_LOGGER_LEVEL = "INFO" 

87 _LOG_FORMAT = "{time:YYYY-MM-DD HH:mm:ss} | {level:<10} | {module}:{function}:{line} - {message}" 

88 

89 # Rotation settings (optional - None means no rotation) 

90 LOG_ROTATION = None # e.g., "10 MB", "1 day", "500 KB", "12:00", "1 week" 

91 LOG_RETENTION = None # e.g., "7 days", "1 month", or 10 (keep 10 files) 

92 LOG_COMPRESSION = None # e.g., "zip", "gz", "tar.gz" 

93 

94 # Traceback settings 

95 LOG_BACKTRACE = True 

96 # Defaults to False unlike loguru: diagnose=True writes local variable 

97 # values (passwords, tokens, PII) into the log file. 

98 LOG_DIAGNOSE = False 

99 

100 # /////////////////////////////////////////////////////////////// 

101 # CONFIGURATION DEFAULTS 

102 # /////////////////////////////////////////////////////////////// 

103 

104 CONFIG_DIR = Path.home() / ".ezpl" 

105 CONFIG_FILE = CONFIG_DIR / "config.json" 

106 

107 # /////////////////////////////////////////////////////////////// 

108 # EXPORT DEFAULTS 

109 # /////////////////////////////////////////////////////////////// 

110 

111 _EXPORT_BATCH_FILE = "export_env.bat" # Windows 

112 _EXPORT_SHELL_FILE = "export_env.sh" # Unix/Linux/macOS 

113 

114 # /////////////////////////////////////////////////////////////// 

115 # CLASS METHODS 

116 # /////////////////////////////////////////////////////////////// 

117 

118 @classmethod 

119 def get_all_defaults(cls) -> dict[str, Any]: 

120 """ 

121 Get all default configuration values as a dictionary. 

122 

123 Returns: 

124 Dictionary containing all default configuration values 

125 """ 

126 return { 

127 "log-level": cls.LOG_LEVEL, 

128 "log-file": cls.LOG_FILE, 

129 "log-dir": str( 

130 cls.LOG_DIR 

131 ), # Convert Path to string for JSON serialization 

132 "printer-level": cls.PRINTER_LEVEL, 

133 "indent-step": cls.INDENT_STEP, 

134 "indent-symbol": cls.INDENT_SYMBOL, 

135 "base-indent-symbol": cls.BASE_INDENT_SYMBOL, 

136 "file-logger-level": cls.FILE_LOGGER_LEVEL, 

137 "log-format": cls._LOG_FORMAT, 

138 "log-rotation": cls.LOG_ROTATION, 

139 "log-retention": cls.LOG_RETENTION, 

140 "log-compression": cls.LOG_COMPRESSION, 

141 "log-backtrace": cls.LOG_BACKTRACE, 

142 "log-diagnose": cls.LOG_DIAGNOSE, 

143 } 

144 

145 @classmethod 

146 def get_logging_defaults(cls) -> dict[str, Any]: 

147 """ 

148 Get logging-specific default values. 

149 

150 Returns: 

151 Dictionary containing logging default values 

152 """ 

153 return { 

154 "log-level": cls.LOG_LEVEL, 

155 "log-file": cls.LOG_FILE, 

156 "log-dir": cls.LOG_DIR, 

157 } 

158 

159 @classmethod 

160 def get_printer_defaults(cls) -> dict[str, Any]: 

161 """ 

162 Get printer-specific default values. 

163 

164 Returns: 

165 Dictionary containing printer default values 

166 """ 

167 return { 

168 "printer-level": cls.PRINTER_LEVEL, 

169 "indent-step": cls.INDENT_STEP, 

170 "indent-symbol": cls.INDENT_SYMBOL, 

171 "base-indent-symbol": cls.BASE_INDENT_SYMBOL, 

172 } 

173 

174 @classmethod 

175 def get_file_logger_defaults(cls) -> dict[str, Any]: 

176 """ 

177 Get file logger-specific default values. 

178 

179 Returns: 

180 Dictionary containing file logger default values 

181 """ 

182 return { 

183 "file-logger-level": cls.FILE_LOGGER_LEVEL, 

184 "log-format": cls._LOG_FORMAT, 

185 "log-rotation": cls.LOG_ROTATION, 

186 "log-retention": cls.LOG_RETENTION, 

187 "log-compression": cls.LOG_COMPRESSION, 

188 "log-backtrace": cls.LOG_BACKTRACE, 

189 "log-diagnose": cls.LOG_DIAGNOSE, 

190 } 

191 

192 

193# /////////////////////////////////////////////////////////////// 

194# PUBLIC API 

195# /////////////////////////////////////////////////////////////// 

196 

197__all__ = [ 

198 "DefaultConfiguration", 

199]