@@ -69,140 +69,26 @@ pip install git+https://github.com/MPCodeWriter21/log21
6969Changelog
7070---------
7171
72- ### v3.1 .0
72+ ### v3.2 .0
7373
74- Change the way ` argumentify ` handles function parameters to argument-parser arguments
75- conversion .
74+ Add ` file_mode ` and ` file_encoding ` parameters to ` get_logger ` for finer control over
75+ the way a simple logger handles files .
7676
77- + ` POSITIONAL_ONLY ` and ` VAR_POSITIONAL ` parameters will be positional arguments.
78- + ` POSITIONAL_OR_KEYWORD ` and ` KEYWORD_ONLY ` parameters have flags assigned to them.
79- + ` POSITIONAL_OR_KEYWORD ` parameters will be required if at least one ` KEYWORD_ONLY `
80- parameter is there, otherwise they are optional.
81- + ` VAR_KEYWORD ` parameters are still not supported.
77+ For even more control you can still define Logger, Handlers, and Formatters manually.
8278
83- #### Example 1
79+ #### Example
8480
8581``` python
86- def main (path : Path, / , output : Path, * , verbose : bool = False ):
87- """ Process a file.
82+ import log21
8883
89- :param path: The input file path
90- :param output: The output file
91- :param verbose: Write more logs to the standard output.
92- """
93- ...
94-
95-
96- if __name__ == " __main__" :
97- argumentify(main)
98- ```
99-
100- The help looks like this:
101-
102- ``` help
103- usage: test.py [-h] --output OUTPUT [--verbose] path
104-
105- Process a file.
106-
107- positional arguments:
108- path The input file path
109-
110- options:
111- -h, --help
112- show this help message and exit
113- --output OUTPUT, -o OUTPUT
114- The output file
115- --verbose, -v
116- Write more logs to the standard output.
117-
118- ```
119-
120- _ Note that ` path ` and ` output ` are required._
121-
122- #### Example 2
123-
124- ``` python
125- def main (output : Path, / , * inputs : Path):
126- """ Process multiple files into one.
127-
128- :param output: The output file
129- :param inputs: The path to the input files
130- """
131- # Since `inputs` is a VAR_POSITIONAL, while being a positional argument, it can have
132- # zero length which is in many cases not intended.
133- # You might want to add a check for its length and raise an ArgumentError if it does
134- # not match your needs
135-
136- # Check if at least one input has been passed and mark the argument as required
137- # if len(inputs) < 1:
138- # raise RequiredArgumentError("inputs")
139-
140- # Raise an error unless at least two inputs are present
141- if len (inputs) < 2 :
142- raise ArgumentError(message = " You need to pass at least two files as input." )
143- ...
144- ```
145-
146- The help looks like this:
147-
148- ``` help
149- usage: test.py [-h] output [inputs ...]
150-
151- Process multiple files into one.
152-
153- positional arguments:
154- output The output file
155- inputs The path to the input files
156-
157- options:
158- -h, --help
159- show this help message and exit
84+ logger = log21.get_logger(
85+ " My File Logger" , show_level = False , show_time = True , file = " myapp.log" , file_mode = " a" ,
86+ file_encoding = " utf-8"
87+ )
16088
89+ logger.info(" Hello World!" )
16190```
16291
163- #### Example 3
164-
165- ``` python
166- def main (first_name : str , last_name : str , output : Path, verbose : bool = False ):
167- """ Write a greeting message.
168-
169- :param first_name: The first name of the user to greet (optional)
170- :param last_name: The last name of the user to greet (optional)
171- :param output: The output file (stdout if none is provided)
172- :param verbose: If provided, will write the debug logs to stdout
173- """
174- ...
175-
176-
177- if __name__ == " __main__" :
178- argumentify(main)
179- ```
180-
181- The help looks like this:
182-
183- ``` help
184- usage: test.py [-h] [--first-name FIRST_NAME] [--last-name LAST_NAME] [--output OUTPUT]
185- [--verbose]
186-
187- Write a greeting message.
188-
189- options:
190- -h, --help
191- show this help message and exit
192- --first-name FIRST_NAME, -f FIRST_NAME
193- The first name of the user to greet (optional)
194- --last-name LAST_NAME, -l LAST_NAME
195- The last name of the user to greet (optional)
196- --output OUTPUT, -o OUTPUT
197- The output file (stdout if none is provided)
198- --verbose, -v
199- If provided, will write the debug logs to stdout
200-
201- ```
202-
203- _ Note that all the options are optional and default to None. ` verbose ` is False by
204- default since a default value is provided for it in function definition._
205-
20692[ Full CHANGELOG] ( https://github.com/MPCodeWriter21/log21/blob/master/CHANGELOG.md )
20793
20894Usage Examples
0 commit comments