Commit 735fcfed authored by joe-narvaez's avatar joe-narvaez
Browse files

馃毀 build(config): setup config for envs. logging and error monitoring

parent 12dffdb8
Pipeline #550467444 passed with stage
in 3 minutes and 46 seconds
No preview for this file type
LOG_LEVEL=INFO
PYTHONPATH=sway
\ No newline at end of file
......@@ -24,6 +24,7 @@ mypy = "*"
black = "*"
json2python-models = "*"
pytest-cov = "*"
sentry-sdk = "*"
[scripts]
preflight = "bash -c 'gitlab-ci-lint --token $GITLAB_TOKEN && semantic-release -d'"
......
{
"_meta": {
"hash": {
"sha256": "49c6205e5bd0f80defb8dd7b31ce6a01480ae341beb70458b768391a175400e9"
"sha256": "6cb72fafa224a71e388860e6264fd2a63807f5fee92ca20d3ef53bf46cba3431"
},
"pipfile-spec": 6,
"requires": {
......@@ -37,7 +37,7 @@
"sha256:0f7569a4a6ff151958b64304071d370daa3243d15941a7beedf0c9fe5105603e",
"sha256:a851e51367fb93e9e1361732c1d60dab63eff98712e503ea7d92e6eccb109b4f"
],
"markers": "python_version >= '3.6' and python_version < '4.0'",
"markers": "python_version >= '3.6' and python_version < '4'",
"version": "==2.2.1"
},
"email-validator": {
......@@ -177,7 +177,7 @@
"sha256:44ece4d53fb1706f667c9bd1c648f5469a2ec925fcf3a776667042d645472c14",
"sha256:aabaf16477806a5e1dd19aa41f8c2b7950dd3c746362d7e3223dbe6de6ac448e"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4.0'",
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'",
"version": "==1.26.9"
},
"wcwidth": {
......@@ -242,6 +242,14 @@
"index": "pypi",
"version": "==22.3.0"
},
"certifi": {
"hashes": [
"sha256:9c5705e395cd70084351dd8ad5c41e65655e08ce46f2ec9cf6c2c08390f71eb7",
"sha256:f1d53542ee8cbedbe2118b5686372fb33c297fcd6379b050cca0ef13a597382a"
],
"markers": "python_version >= '3.6'",
"version": "==2022.5.18.1"
},
"click": {
"hashes": [
"sha256:7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e",
......@@ -638,6 +646,14 @@
"index": "pypi",
"version": "==6.0"
},
"sentry-sdk": {
"hashes": [
"sha256:259535ba66933eacf85ab46524188c84dcb4c39f40348455ce15e2c0aca68863",
"sha256:778b53f0a6c83b1ee43d3b7886318ba86d975e686cb2c7906ccc35b334360be1"
],
"index": "pypi",
"version": "==1.5.12"
},
"setuptools": {
"hashes": [
"sha256:68e45d17c9281ba25dc0104eadd2647172b3472d9e01f911efa57965e8d51a36",
......@@ -694,6 +710,14 @@
"markers": "python_version >= '3.5'",
"version": "==1.3.4"
},
"urllib3": {
"hashes": [
"sha256:44ece4d53fb1706f667c9bd1c648f5469a2ec925fcf3a776667042d645472c14",
"sha256:aabaf16477806a5e1dd19aa41f8c2b7950dd3c746362d7e3223dbe6de6ac448e"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'",
"version": "==1.26.9"
},
"wrapt": {
"hashes": [
"sha256:00b6d4ea20a906c0ca56d84f93065b398ab74b927a7a3dbd470f6fc503f95dc3",
......
......@@ -22,9 +22,3 @@ Commands:
update
```
```shell
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/sway.gpg --keyserver keyring.debian.org --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
echo "deb [signed-by=/usr/share/keyrings/sway.gpg] https://minio.sway.cx/deb stable main" | sudo tee /etc/apt/sources.list.d/sway.list
sudo apt-get update
sudo apt-get install k6
```
import logging
import os
from typing import Literal, Dict, Optional, cast
from pydantic import BaseModel, HttpUrl
class Config(BaseModel):
log_level: Optional[Literal["ERROR", "WARN", "INFO", "DEBUG"]] = None
sentry_url: Optional[HttpUrl] = None
log_file_path: str = "/dev/null"
Keys = Literal["local", "development", "beta", "production"]
ConfigMap = Dict[Keys, Config]
config_map: ConfigMap = {
"local": Config(),
"development": Config(),
"beta": Config(
log_level="INFO",
log_file_path="/var/log/sway.log",
# TODO: get a sentry url with an account from this project
sentry_url=cast(
HttpUrl,
"https://4ec782ec2e654c8ea3b6994f01c54882@o409017.ingest.sentry.io/5948203",
),
),
"production": Config(
log_level="INFO",
log_file_path="/var/log/sway.log",
sentry_url=cast(
HttpUrl,
"https://4ec782ec2e654c8ea3b6994f01c54882@o409017.ingest.sentry.io/5948203",
),
),
}
config = config_map[cast(Keys, os.getenv("PYTHON_ENV", "local"))]
def setup_logger(cfg: Config) -> None:
level = cfg.log_level
logging.basicConfig(
filename=cfg.log_file_path,
encoding="utf-8",
format="%(levelname)s: %(message)s",
level=level,
)
import click
import sentry_sdk
import screens
from config import config, setup_logger
@click.version_option()
@click.group()
def cli() -> None:
pass
sentry_sdk.init(config.sentry_url)
setup_logger(config)
@cli.group()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment