@@ -124,50 +124,6 @@ some_function()
124
124
# Caller Path: /path/to/example.py
125
125
````
126
126
127
- ### ` Colorization `
128
-
129
- The Colorization class provides functionality to colorize messages based on specified keywords and associated
130
- colorization options. It supports setting keyword-color mappings, retrieving mappings, checking if colorization is
131
- supported, and colorizing messages.
132
-
133
- #### Attributes
134
-
135
- - ` RESET ` : Represents the reset sequence to revert color and style changes.
136
-
137
- #### Methods
138
-
139
- - ` colorize_message(message: str) -> str ` : Colorizes the provided message based on keyword-color mappings.
140
- - ` get_keyword_color_mapping(name: str) -> dict ` : Retrieves the colorization mapping for the specified keyword.
141
- - ` get_keyword_color_mappings() -> dict ` : Retrieves all keyword-color mappings.
142
- - ` is_colorization_supported() -> bool ` : Checks if colorization is supported based on the current environment.
143
- - ` is_valid_mapping(name: str) -> bool ` : Checks if the specified keyword has a valid colorization mapping.
144
- - ` remove_keyword_color_mapping(name: str) -> None ` : Removes the colorization mapping for the specified keyword.
145
- - ` set_keyword_color_mapping(name: str, keywords: str | list[str], text_color: Optional[str] = None, text_background_color: Optional[str] = None, text_effect: Optional[str] = None) -> None ` :
146
- Sets the colorization mapping for the specified keyword.
147
-
148
- #### Usage
149
-
150
- ```` python
151
- # Import the Colorization class
152
- import pyloggermanager
153
- from pyloggermanager.textstyles import TextColor
154
-
155
- # Set up colorization mappings
156
- pyloggermanager.Colorization.set_keyword_color_mapping(
157
- name = ' ERROR' ,
158
- keywords = [' error' , ' exception' ],
159
- text_color = TextColor.RED
160
- )
161
-
162
- # Colorize a message
163
- message = ' An error occurred!'
164
- colorized_message = pyloggermanager.Colorization.colorize_message(message)
165
- print (colorized_message)
166
-
167
- # Output
168
- # An error occurred!
169
- ````
170
-
171
127
### ` FileMode `
172
128
173
129
The FileMode class represents file modes supported by the Python open() function for reading, writing, and appending to
@@ -847,7 +803,7 @@ list of all handlers.
847
803
848
804
#### Methods
849
805
850
- - ` __init__(name: str = None, level: int = 20, colorization: 'Colorization' = None, formatter: Formatter = DefaultFormatter()) ` -
806
+ - ` __init__(name: str = None, level: int = 20, colorization: pycolorecho.ColorMapper = None, formatter: Formatter = DefaultFormatter()) ` -
851
807
Initializes the handler with optional attributes.
852
808
- ` close() ` : Closes the handler.
853
809
- ` emit(record: 'Record', ignore_display: bool) -> None ` : Abstract method to emit a log record.
@@ -885,7 +841,7 @@ stream.
885
841
886
842
#### Methods
887
843
888
- - ` __init__(name: str = None, level: int = 20, colorization: 'Colorization' = None, formatter: Formatter = DefaultFormatter(), stream: Stream = TerminalStream()) ` -
844
+ - ` __init__(name: str = None, level: int = 20, colorization: pycolorecho.ColorMapper = None, formatter: Formatter = DefaultFormatter(), stream: Stream = TerminalStream()) ` -
889
845
Initializes a ConsoleHandler instance with optional attributes
890
846
- ` close() ` : Closes the stream if it has a close method.
891
847
- ` emit(record: 'Record', ignore_display: bool = True) -> None ` : Emits the log record by formatting it, colorizing the
@@ -927,7 +883,7 @@ methods to set the log level, formatter, and stream, as well as to emit log reco
927
883
928
884
#### Methods
929
885
930
- - ` __init__(name: str = None, level: int = 20, colorization: 'Colorization' = None, formatter: Formatter = DefaultFormatter(), stream: Stream = StdoutStream()) ` -
886
+ - ` __init__(name: str = None, level: int = 20, colorization: pycolorecho.ColorMapper = None, formatter: Formatter = DefaultFormatter(), stream: Stream = StdoutStream()) ` -
931
887
Initializes a StreamHandler instance with optional attributes.
932
888
- ` close() ` : Closes the stream if it has a close method.
933
889
- ` emit(record: 'Record', ignore_display: bool) -> None ` : Emits a log record to the stream.
@@ -970,7 +926,7 @@ customization of various parameters such as file name, file mode, encoding, etc.
970
926
971
927
#### Methods
972
928
973
- - ` __init__(name: str = None, level: int = 20, colorization: 'Colorization' = None, formatter: Formatter = DefaultFormatter(), file_name: str = 'default.log', file_mode: str = 'a', encoding: str = 'UTF-8') ` -
929
+ - ` __init__(name: str = None, level: int = 20, colorization: pycolorecho.ColorMapper = None, formatter: Formatter = DefaultFormatter(), file_name: str = 'default.log', file_mode: str = 'a', encoding: str = 'UTF-8') ` -
974
930
Initializes a FileHandler object with optional attributes.
975
931
- ` close() ` : Closes the file stream used for writing log records.
976
932
- ` emit(record: 'Record', ignore_display: bool) -> None ` : Emits a log record by writing it to the log file.
@@ -1125,183 +1081,17 @@ terminal_stream.flush()
1125
1081
# This is a message to the terminal
1126
1082
````
1127
1083
1128
- ## ` pyloggermanager.textstyles `
1129
-
1130
- The 'pyloggermanager.textstyles' package provides utilities for defining and applying text styles to log messages within
1131
- the logger manager framework. It includes classes for specifying text colors, background colors, and text effects,
1132
- allowing users to customize the appearance of log messages according to their preferences.
1084
+ # Text Styles
1133
1085
1134
- This package is designed to enhance the visual representation of log messages by providing a flexible and intuitive way
1135
- to apply various text styles. By incorporating these text styles into log messages, users can improve readability,
1136
- emphasize important information, and differentiate between different types of log entries .
1086
+ For text colorization and styling, this package utilizes the ` pycolorecho ` package. You can find additional details
1087
+ about its usage and features by following this
1088
+ link: [ pycolorecho ] ( https://github.com/coldsofttech/pycolorecho/blob/main/README.md ) package .
1137
1089
1138
- Overall, the 'pyloggermanager.textstyles' package complements the logger manager framework by offering tools for
1139
- creating visually appealing and informative log messages, contributing to a more effective logging experience.
1090
+ # License
1140
1091
1141
- ### TextBackgroundColor
1142
-
1143
- The TextBackgroundColor class represents text background color for styling console text. It provides methods to add
1144
- custom colors, retrieve color mappings, get color codes, and check if a color is valid.
1145
-
1146
- #### Attributes
1147
-
1148
- | Color | Name | Description |
1149
- | ------------------------------------------------------------------| -----------------| -----------------------------------------------|
1150
- | [ ![ Black] ( https://via.placeholder.com/15x15/000000?text=+ )] ( # ) | ` BLACK ` (str) | Constant representing the black color code. |
1151
- | [ ![ Red] ( https://via.placeholder.com/15x15/FF0000?text=+ )] ( # ) | ` RED ` (str) | Constant representing the red color code. |
1152
- | [ ![ Green] ( https://via.placeholder.com/15x15/00FF00?text=+ )] ( # ) | ` GREEN ` (str) | Constant representing the green color code. |
1153
- | [ ![ Yellow] ( https://via.placeholder.com/15x15/FFFF00?text=+ )] ( # ) | ` YELLOW ` (str) | Constant representing the yellow color code. |
1154
- | [ ![ Blue] ( https://via.placeholder.com/15x15/0000FF?text=+ )] ( # ) | ` BLUE ` (str) | Constant representing the blue color code. |
1155
- | [ ![ Magenta] ( https://via.placeholder.com/15x15/FF00FF?text=+ )] ( # ) | ` MAGENTA ` (str) | Constant representing the magenta color code. |
1156
- | [ ![ Cyan] ( https://via.placeholder.com/15x15/00FFFF?text=+ )] ( # ) | ` CYAN ` (str) | Constant representing the cyan color code. |
1157
- | [ ![ White] ( https://via.placeholder.com/15x15/FFFFFF?text=+ )] ( # ) | ` WHITE ` (str) | Constant representing the white color code. |
1158
-
1159
- #### Methods
1160
-
1161
- - ` add_color(name: str, code: str) -> None ` : Adds a custom color with the provided name and code.
1162
- - ` get_colors() -> dict ` : Returns a dictionary mapping color names to their corresponding codes, sorted alphabetically.
1163
- - ` get_color(color_str: str) -> str ` : Returns the color code for the provided color name or code string.
1164
- - ` is_valid_color(color: str) -> bool ` : Checks if the provided color name or code is valid.
1165
- - ` remove_color(name: str) -> None ` : Removes the color mapping for the specified color name.
1166
-
1167
- #### Usage
1168
-
1169
- ```` python
1170
- from pyloggermanager.textstyles import TextBackgroundColor
1171
-
1172
- # Add a custom color
1173
- TextBackgroundColor.add_color(" CUSTOM_COLOR" , " \033 [48;5;200m" )
1174
-
1175
- # Get color mappings
1176
- color_mappings = TextBackgroundColor.get_colors()
1177
- print (color_mappings)
1178
-
1179
- # Check if a color is valid
1180
- is_valid = TextBackgroundColor.is_valid_color(" YELLOW" )
1181
- print (is_valid) # Output: True
1182
-
1183
- # Remove a color
1184
- TextBackgroundColor.remove_color(" CUSTOM_COLOR" )
1185
-
1186
- # Output
1187
- # {
1188
- # 'BLACK': '\x1b[40m',
1189
- # 'BLUE': '\x1b[44m',
1190
- # 'CUSTOM_COLOR': '\x1b[48;5;200m',
1191
- # 'CYAN': '\x1b[46m',
1192
- # 'GREEN': '\x1b[42m',
1193
- # 'MAGENTA': '\x1b[45m',
1194
- # 'RED': '\x1b[41m',
1195
- # 'WHITE': '\x1b[47m',
1196
- # 'YELLOW': '\x1b[43m'
1197
- # }
1198
- ````
1092
+ Please refer to the [ MIT license] ( LICENSE ) within the project for more information.
1199
1093
1200
- ### TextColor
1094
+ # Contributing
1201
1095
1202
- The TextColor class represents text color for styling console text. It provides methods to add custom colors, retrieve
1203
- color mappings, get color codes, and check if a color is valid.
1204
-
1205
- #### Attributes
1206
-
1207
- | Color | Name | Description |
1208
- | ------------------------------------------------------------------| -----------------| -----------------------------------------------|
1209
- | [ ![ Black] ( https://via.placeholder.com/15x15/000000?text=+ )] ( # ) | ` BLACK ` (str) | Constant representing the black color code. |
1210
- | [ ![ Red] ( https://via.placeholder.com/15x15/FF0000?text=+ )] ( # ) | ` RED ` (str) | Constant representing the red color code. |
1211
- | [ ![ Green] ( https://via.placeholder.com/15x15/00FF00?text=+ )] ( # ) | ` GREEN ` (str) | Constant representing the green color code. |
1212
- | [ ![ Yellow] ( https://via.placeholder.com/15x15/FFFF00?text=+ )] ( # ) | ` YELLOW ` (str) | Constant representing the yellow color code. |
1213
- | [ ![ Blue] ( https://via.placeholder.com/15x15/0000FF?text=+ )] ( # ) | ` BLUE ` (str) | Constant representing the blue color code. |
1214
- | [ ![ Magenta] ( https://via.placeholder.com/15x15/FF00FF?text=+ )] ( # ) | ` MAGENTA ` (str) | Constant representing the magenta color code. |
1215
- | [ ![ Cyan] ( https://via.placeholder.com/15x15/00FFFF?text=+ )] ( # ) | ` CYAN ` (str) | Constant representing the cyan color code. |
1216
- | [ ![ White] ( https://via.placeholder.com/15x15/FFFFFF?text=+ )] ( # ) | ` WHITE ` (str) | Constant representing the white color code. |
1217
-
1218
- #### Methods
1219
-
1220
- - ` add_color(name: str, code: str) -> None ` : Adds a custom color with the provided name and code.
1221
- - ` get_colors() -> dict ` : Returns a dictionary mapping color names to their corresponding codes, sorted alphabetically.
1222
- - ` get_color(color_str: str) -> str ` : Returns the color code for the provided color name or code string.
1223
- - ` is_valid_color(color: str) -> bool ` : Checks if the provided color name or code is valid.
1224
- - ` remove_color(name: str) -> None ` : Removes the color mapping for the specified color name.
1225
-
1226
- #### Usage
1227
-
1228
- ```` python
1229
- from pyloggermanager.textstyles import TextColor
1230
-
1231
- # Add a custom color
1232
- TextColor.add_color(" CUSTOM_COLOR" , " \033 [38;5;200m" )
1233
-
1234
- # Get color mappings
1235
- color_mappings = TextColor.get_colors()
1236
- print (color_mappings)
1237
-
1238
- # Check if a color is valid
1239
- is_valid = TextColor.is_valid_color(" RED" )
1240
- print (is_valid) # Output: True
1241
-
1242
- # Remove a color
1243
- TextColor.remove_color(" CUSTOM_COLOR" )
1244
-
1245
- # Output
1246
- # {
1247
- # 'BLACK': '\x1b[30m',
1248
- # 'BLUE': '\x1b[34m',
1249
- # 'CUSTOM_COLOR': '\x1b[38;5;200m',
1250
- # 'CYAN': '\x1b[36m',
1251
- # 'GREEN': '\x1b[32m',
1252
- # 'MAGENTA': '\x1b[35m',
1253
- # 'RED': '\x1b[31m',
1254
- # 'WHITE': '\x1b[37m',
1255
- # 'YELLOW': '\x1b[33m'
1256
- # }
1257
- ````
1258
-
1259
- ### TextEffect
1260
-
1261
- The TextEffect class represents different text effects used in text formatting, such as bold, underline, and italics. It
1262
- provides methods to add custom text effects, get text effect mappings, check if a text effect is valid, and retrieve the
1263
- corresponding text effect for a given string representation.
1264
-
1265
- #### Attributes
1266
-
1267
- - ` BOLD ` (str): Constant representing the bold text effect.
1268
- - ` UNDERLINE ` (str): Constant representing the underline text effect.
1269
- - ` ITALIC ` (str): Constant representing the italic text effect.
1270
-
1271
- #### Methods
1272
-
1273
- - ` add_effect(name: str, code: str) -> None ` : Adds a custom text effect with the provided name and code.
1274
- - ` get_effects() -> dict ` : Returns a dictionary mapping text effect names to their corresponding codes, sorted
1275
- alphabetically.
1276
- - ` get_effect(effect_str: str) -> str ` : Returns the text effect name corresponding to the given text effect code or
1277
- name.
1278
- - ` is_valid_effect(effect: str) -> bool ` : Checks if the provided text effect is valid.
1279
- - ` remove_effect(name: str) -> None ` : Removes the text effect mapping for the specified effect name.
1280
-
1281
- #### Usage
1282
-
1283
- ```` python
1284
- from pyloggermanager.textstyles import TextEffect
1285
-
1286
- # Add a custom effect
1287
- TextEffect.add_effect(" CUSTOM_EFFECT" , " \033 [10m" )
1288
-
1289
- # Get effect mappings
1290
- effect_mappings = TextEffect.get_effects()
1291
- print (effect_mappings)
1292
-
1293
- # Check if an effect is valid
1294
- is_valid = TextEffect.is_valid_effect(" BOLD" )
1295
- print (is_valid) # Output: True
1296
-
1297
- # Remove an effect
1298
- TextEffect.remove_effect(" CUSTOM_EFFECT" )
1299
-
1300
- # Output
1301
- # {
1302
- # 'BOLD': '\x1b[1m',
1303
- # 'CUSTOM_EFFECT': '\x1b[10m',
1304
- # 'ITALIC': '\x1b[3m',
1305
- # 'UNDERLINE': '\x1b[4m'
1306
- # }
1307
- ````
1096
+ We welcome contributions from the community! Whether you have ideas for new features, bug fixes, or enhancements, feel
1097
+ free to open an issue or submit a pull request on [ GitHub] ( https://github.com/coldsofttech/pyloggermanager ) .
0 commit comments