This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from layconf import LayConf | |
# the default config file is cfg/default.ini unless specified other | |
# custom_config_file_path is an optional layer | |
# env_prefix is empty by default, which means that environment variable names will be | |
# mapped to {section}_{option} | |
LayConf.init_config(custom_config_file_path="cfg/staging.ini", env_prefix="example") | |
print("env_name:", LayConf.get("DATABASE", "env_name")) | |
print("console_enabled:", LayConf.getboolean("LOG", "console_enabled")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[LOG] | |
console_enabled = true | |
console_level = INFO | |
file_enabled = true | |
file_rotation_size_mb = 10 | |
file_backup_count = 1000 | |
[DATABASE] | |
endpoint = | |
env_name = default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[DATABASE] | |
env_name = staging | |
endpoint = staging:3001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
logger.info("Hello World") | |
logger.info("Request from {} handled in {:.3f} ms", socket.gethostname(), 11) | |
logger.info("Request from {} handled in {:.3f} ms", "127.0.0.1", 33.1) | |
logger.info("My favorite drinks are {}, {}, {}, {}", "milk", "wine", "tea", "beer") | |
logger.debug("this is a {} message", logging.getLevelName(logging.DEBUG)) | |
logger.info("this is a {} message", logging.getLevelName(logging.INFO)) | |
logger.warning("this is a {} message", logging.getLevelName(logging.WARNING)) | |
logger.error("this is a {} message", logging.getLevelName(logging.ERROR)) | |
logger.critical("this is a {} message", logging.getLevelName(logging.CRITICAL)) | |
logger.info("Does old-style formatting also work? %s it is, but no colors (yet)", True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from colargulog import ColorizedArgsFormatter | |
root_logger = logging.getLogger() | |
console_handler = logging.StreamHandler(stream=sys.stdout) | |
console_format = "%(asctime)s - %(levelname)-8s - %(name)-25s - %(message)s" | |
colored_formatter = ColorizedArgsFormatter(console_format) | |
console_handler.setFormatter(colored_formatter) | |
root_logger.addHandler(console_handler) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import socket | |
import sys | |
from colargulog import ColorizedArgsFormatter | |
from colargulog import BraceFormatStyleFormatter | |
def init_logging(): | |
root_logger = logging.getLogger() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service_filter = "service1" | |
priority=3 | |
batch_size_limit=1000 | |
def get_alert_list(): | |
return alerts_client.get_alerts_list( | |
service=service_filter, | |
priority=min_priority_level, | |
page=1, | |
pageSize=batch_size_limit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alerts = alerts_client.get_alerts_list( | |
service=service_filter, | |
priority=min_priority_level, | |
page=1, | |
pageSize=batch_size_limit) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grafana_server_url = "https://localhost:3000" | |
add_user_endpoint = grafana_server_url + "/api/admin/users/" | |
user_dict = { | |
"name": "David Ohana", | |
"email": "NotMyRealEmail@ibm.com", | |
"login": "NotMyRealEmail@ibm.com", | |
"password": "dummypass", | |
} | |
response = requests.post( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
permission_doc = {"isGrafanaAdmin": True} | |
grafana_server_url = "https://localhost:3000" | |
permission_end_point = "{}/api/admin/users/{}/permissions".format(grafana_server_url, user_id) | |
response = requests.put(permission_end_point, | |
json=permission_doc, | |
verify=False, | |
auth=('admin', grafana_admin_password)) |
OlderNewer