subhash kumar singh | e310e43 | 2021-08-03 00:23:32 +0530 | [diff] [blame^] | 1 | .. |
| 2 | .. Copyright (c) 2019 AT&T Intellectual Property. |
| 3 | .. |
| 4 | .. Copyright (c) 2019 Nokia. |
| 5 | .. |
| 6 | .. Copyright (c) 2021 Samsung |
| 7 | .. |
| 8 | .. Licensed under the Creative Commons Attribution 4.0 International |
| 9 | .. |
| 10 | .. Public License (the "License"); you may not use this file except |
| 11 | .. |
| 12 | .. in compliance with the License. You may obtain a copy of the License at |
| 13 | .. |
| 14 | .. |
| 15 | .. https://creativecommons.org/licenses/by/4.0/ |
| 16 | .. |
| 17 | .. |
| 18 | .. Unless required by applicable law or agreed to in writing, documentation |
| 19 | .. |
| 20 | .. distributed under the License is distributed on an "AS IS" BASIS, |
| 21 | .. |
| 22 | .. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 23 | .. |
| 24 | .. See the License for the specific language governing permissions and |
| 25 | .. |
| 26 | .. limitations under the License. |
| 27 | .. |
| 28 | .. This source code is part of the near-RT RIC (RAN Intelligent Controller) |
| 29 | .. |
| 30 | .. platform project (RICP). |
| 31 | .. |
| 32 | |
| 33 | MDCLogger |
| 34 | ========= |
| 35 | |
| 36 | |
| 37 | Usage |
| 38 | ----- |
| 39 | |
| 40 | The library can be used in as shown below. |
| 41 | |
| 42 | |
| 43 | .. code:: bash |
| 44 | |
| 45 | ```python |
| 46 | from ricappframe.logger.mdclogger import MDCLogger |
| 47 | my_logger = MDCLogger() |
| 48 | my_logger.mdclog_format_init(configmap_monitor=True) |
| 49 | my_logger.error("This is an error log") |
| 50 | ``` |
| 51 | |
| 52 | A program can create several logger instances. |
| 53 | |
| 54 | mdclog_format_init() Adds the MDC log format with HostName, PodName, ContainerName, ServiceName,PID,CallbackNotifyforLogFieldChange |
| 55 | |
| 56 | Pass configmap_monitor = False in mdclog_format_init() function to stop dynamic log level change based on configmap. |
| 57 | |
| 58 | Logging Levels |
| 59 | -------------- |
| 60 | .. code:: bash |
| 61 | |
| 62 | """Severity levels of the log messages.""" |
| 63 | DEBUG = 10 |
| 64 | INFO = 20 |
| 65 | WARNING = 30 |
| 66 | ERROR = 40 |
| 67 | |
| 68 | mdcLogger API's |
| 69 | --------------- |
| 70 | |
| 71 | 1. Set current logging level |
| 72 | |
| 73 | .. code:: bash |
| 74 | |
| 75 | def set_level(self, level: Level): |
| 76 | |
| 77 | Keyword arguments: |
| 78 | level -- logging level. Log messages with lower severity will be filtered. |
| 79 | |
| 80 | 2. Return the current logging level |
| 81 | |
| 82 | .. code:: bash |
| 83 | |
| 84 | def get_level(self) -> Level: |
| 85 | |
| 86 | 3. Add a logger specific MDC |
| 87 | |
| 88 | .. code:: bash |
| 89 | |
| 90 | def add_mdc(self, key: str, value: Value): |
| 91 | |
| 92 | Keyword arguments: |
| 93 | key -- MDC key |
| 94 | value -- MDC value |
| 95 | |
| 96 | 4. Return logger's MDC value with the given key or None |
| 97 | |
| 98 | .. code:: bash |
| 99 | |
| 100 | def get_mdc(self, key: str) -> Value: |
| 101 | |
| 102 | 5. Remove logger's MDC with the given key |
| 103 | |
| 104 | .. code:: bash |
| 105 | |
| 106 | def remove_mdc(self, key: str): |
| 107 | |
| 108 | 6. Remove all MDCs of the logger instance. |
| 109 | |
| 110 | .. code:: bash |
| 111 | |
| 112 | def clean_mdc(self): |
| 113 | |
| 114 | |
| 115 | 7. Initialise Logging format: |
| 116 | |
| 117 | This api Initialzes mdclog print format using MDC Dictionary by extracting the environment variables in the calling process for “SYSTEM_NAME”, “HOST_NAME”, “SERVICE_NAME”, “CONTAINER_NAME”, “POD_NAME” & “CONFIG_MAP_NAME” mapped to HostName, ServiceName, ContainerName, Podname and Configuration-file-name of the services respectively. |
| 118 | |
| 119 | |
| 120 | .. code:: bash |
| 121 | |
| 122 | def mdclog_format_init(configmap_monitor=False): |
| 123 | |
| 124 | Keyword arguments: |
| 125 | configmap_monitor -- Enables/Disables Dynamic log level change based on configmap |
| 126 | -- Boolean values True/False can be passed as per requirement. |
| 127 | |
| 128 | |