Logger
Copyright 2023 Infoblox
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
1 | |
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
increase_log_level(handler_type='both')
Increase the logging level of the root logger and specific handlers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler_type
|
str
|
Specify the type of handlers to increase the logging level for. Can be 'both' (default), 'console', or 'file'. |
'both'
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Example:
Increase Log Level
Source code in src/ibx_sdk/logger/ibx_logger.py
init_console_logger(level=None, log_format=None)
Initialize a colored console logger with optional custom logging level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
str
|
Specify a string value of the logging level. This field is case-insensitive and will default to 'INFO' if not provided. |
None
|
log_format
|
str
|
Specify the format for the log messages. This field has a default value. |
None
|
Example:
Initialize Colored console logger with a custom logging level
Source code in src/ibx_sdk/logger/ibx_logger.py
init_logger(logfile_name, logfile_mode='w', console_log=None, log_format=None, max_size=None, num_logs=None, level=None)
Create and return a custom file/console logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logfile_name
|
str
|
The name of the log file. |
required |
logfile_mode
|
str
|
Specify the mode for the log file. 'a' for append or 'w' for write mode for basic file logging. |
'w'
|
console_log
|
bool
|
If True, create a colored console log. |
None
|
log_format
|
str
|
Specify the format for the log messages. |
None
|
max_size
|
int
|
Specify the maximum size for the log file (in bytes) if you want to use a rotating log file handler instead of a standard log file handler. |
None
|
num_logs
|
int
|
Specify the number of log files to keep if you want to use a rotating log file handler instead of a standard log file handler. |
None
|
level
|
str
|
Specify a string value for the logging level. This field is case-insensitive and will default to 'INFO' if not provided. |
None
|
Returns:
| Type | Description |
|---|---|
Logger
|
logging.Logger: The root logger. |
Example:
Basic FileHandler
Advanced RotatingFileHandler
Source code in src/ibx_sdk/logger/ibx_logger.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
set_log_level(level, handler_type='both')
Set the logging level for the root logger and specific handlers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
str
|
The desired logging level, e.g., 'DEBUG', 'INFO', 'WARNING'. This field is case-insensitive. |
required |
handler_type
|
str
|
Specify the type of handlers to set the logging level for. Can be 'both' (default), 'console', or 'file'. |
'both'
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Example:
Set the logging level for both console and file handlers to 'DEBUG'