@@ -55,8 +55,7 @@ class API:
55
55
"""
56
56
57
57
# dictates whether the user wants to see terminal log statements or not
58
- _verbose : bool = True
59
- logger : logging .Logger = None # type: ignore
58
+ _logger : logging .Logger = None # type: ignore
60
59
61
60
_host : str = ""
62
61
_api_token : str = ""
@@ -77,7 +76,7 @@ class API:
77
76
# trunk-ignore-end(cspell)
78
77
79
78
@beartype
80
- def __init__ (self , host : Union [str , None ] = None , api_token : Union [str , None ] = None , storage_token : Union [str , None ] = None , config_file_path : Union [str , Path ] = "" ):
79
+ def __init__ (self , host : Union [str , None ] = None , api_token : Union [str , None ] = None , storage_token : Union [str , None ] = None , config_file_path : Union [str , Path ] = "" , default_log_level = logging . INFO ):
81
80
"""
82
81
Initialize CRIPT API client with host and token.
83
82
Additionally, you can use a config.json file and specify the file path.
@@ -220,8 +219,8 @@ def __init__(self, host: Union[str, None] = None, api_token: Union[str, None] =
220
219
self ._check_initial_host_connection ()
221
220
222
221
# set a logger instance to use for the class logs
223
- self ._set_logger ( )
224
- self ._db_schema = DataSchema (self .host )
222
+ self ._init_logger ( default_log_level )
223
+ self ._db_schema = DataSchema (self .host , self . logger )
225
224
226
225
def __str__ (self ) -> str :
227
226
"""
@@ -244,15 +243,15 @@ def __str__(self) -> str:
244
243
"""
245
244
return f"CRIPT API Client - Host URL: '{ self .host } '"
246
245
247
- def _set_logger (self , verbose : bool = True ) -> None :
246
+ def _init_logger (self , log_level = logging . INFO ) -> None :
248
247
"""
249
248
Prepare and configure the logger for the API class.
250
249
251
250
This function creates and configures a logger instance associated with the current module (class).
252
251
253
252
Parameters
254
253
----------
255
- verbose: bool default True
254
+ log_level: logging.LEVEL default logging.INFO
256
255
set if you want `cript.API` to give logs to console or not
257
256
258
257
Returns
@@ -263,11 +262,7 @@ def _set_logger(self, verbose: bool = True) -> None:
263
262
# Create a logger instance associated with the current module
264
263
logger = logging .getLogger (__name__ )
265
264
266
- # Set the logger's level based on the verbose flag
267
- if verbose :
268
- logger .setLevel (logging .INFO ) # Display INFO logs
269
- else :
270
- logger .setLevel (logging .CRITICAL ) # Display no logs
265
+ logger .setLevel (log_level )
271
266
272
267
# Create a console handler
273
268
console_handler = logging .StreamHandler ()
@@ -282,58 +277,11 @@ def _set_logger(self, verbose: bool = True) -> None:
282
277
logger .addHandler (console_handler )
283
278
284
279
# set logger for the class
285
- self .logger = logger
280
+ self ._logger = logger
286
281
287
282
@property
288
- def verbose (self ) -> bool :
289
- """
290
- A boolean flag that controls whether verbose logging is enabled or not.
291
-
292
- When `verbose` is set to `True`, the class will provide additional detailed logging
293
- to the terminal. This can be useful for debugging and understanding the internal
294
- workings of the class.
295
-
296
- ```bash
297
- INFO: Validating Project graph...
298
- ```
299
-
300
- When `verbose` is set to `False`, the class will only provide essential logging information,
301
- making the terminal output less cluttered and more user-friendly.
302
-
303
- Examples
304
- --------
305
- >>> import cript
306
- >>> with cript.API(
307
- ... host="https://api.criptapp.org/",
308
- ... api_token=os.getenv("CRIPT_TOKEN"),
309
- ... storage_token=os.getenv("CRIPT_STORAGE_TOKEN")
310
- ... ) as api:
311
- ... # turn off the terminal logs
312
- ... api.verbose = False
313
-
314
- Returns
315
- -------
316
- bool
317
- verbose boolean value
318
- """
319
- return self ._verbose
320
-
321
- @verbose .setter
322
- def verbose (self , new_verbose_value : bool ) -> None :
323
- """
324
- sets the verbose value and then sets a new logger for the class
325
-
326
- Parameters
327
- ----------
328
- new_verbose_value: bool
329
- new verbose value to turn the logging ON or OFF
330
-
331
- Returns
332
- -------
333
- None
334
- """
335
- self ._verbose = new_verbose_value
336
- self ._set_logger (verbose = new_verbose_value )
283
+ def logger (self ):
284
+ return self ._logger
337
285
338
286
@beartype
339
287
def _prepare_host (self , host : str ) -> str :
@@ -932,7 +880,7 @@ def delete(self, node) -> None:
932
880
933
881
Notes
934
882
-----
935
- After the node has been successfully deleted, a log is written to the terminal if `cript.API.verbose = True`
883
+ After the node has been successfully deleted, a log is written to the terminal
936
884
937
885
```bash
938
886
INFO: Deleted 'Material' with UUID of '80bfc642-157e-4692-a547-97c470725397' from CRIPT API.
@@ -1010,7 +958,7 @@ def delete_node_by_uuid(self, node_type: str, node_uuid: str) -> None:
1010
958
1011
959
Notes
1012
960
-----
1013
- After the node has been successfully deleted, a log is written to the terminal if `cript.API.verbose = True`
961
+ After the node has been successfully deleted, a log is written
1014
962
1015
963
```bash
1016
964
INFO: Deleted 'Material' with UUID of '80bfc642-157e-4692-a547-97c470725397' from CRIPT API.
0 commit comments