Skip to content

Commit

Permalink
Allow logging.ini for custom logger setup
Browse files Browse the repository at this point in the history
  • Loading branch information
dormant-user committed Aug 11, 2024
1 parent 174c1c0 commit 7b1ea5e
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ PyNinja.egg-info/
doc_gen/_*

temp.py

# work in progress
samples/
logging.ini
*.log
5 changes: 5 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ <h1>Welcome to PyNinja’s documentation!<a class="headerlink" href="#welcome-to
<dt class="sig sig-object py" id="pyninja.main.start">
<span class="sig-prename descclassname"><span class="pre">pyninja.main.</span></span><span class="sig-name descname"><span class="pre">start</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">env_file</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="headerlink" href="#pyninja.main.start" title="Permalink to this definition"></a></dt>
<dd><p>Starter function for the API, which uses uvicorn server as trigger.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>env_file</strong> – Filepath for the <code class="docutils literal notranslate"><span class="pre">.env</span></code> file.</p>
</dd>
</dl>
</dd></dl>

</section>
Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions pyninja/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

import click

from pyninja.main import start # noqa: F401

version = "0.0.0"
from pyninja.main import start, version # noqa: F401


@click.command()
Expand Down
18 changes: 14 additions & 4 deletions pyninja/main.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
import os
import platform

import uvicorn
from fastapi import FastAPI

from pyninja import routers, squire

version = "0.0.0"


def start(env_file: str = None) -> None:
"""Starter function for the API, which uses uvicorn server as trigger."""
"""Starter function for the API, which uses uvicorn server as trigger.
Args:
env_file: Filepath for the ``.env`` file.
"""
squire.env = squire.env_loader(
env_file or os.environ.get("env_file") or os.environ.get("ENV_FILE") or ".env"
)
app = FastAPI(
routes=routers.routes,
title=f"Service monitor for {platform.uname().node}",
title="PyNinja",
description="Light weight OS agnostic service monitoring API",
version=version,
)
uvicorn.run(
kwargs = dict(
host=squire.env.ninja_host,
port=squire.env.ninja_port,
workers=squire.env.workers,
app=app,
)
if os.path.isfile("logging.ini"):
kwargs["log_config"] = os.path.join(os.getcwd(), "logging.ini")
uvicorn.run(**kwargs)
3 changes: 1 addition & 2 deletions pyninja/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

from pyninja import auth, exceptions, service, squire

logging.getLogger("uvicorn.access").disabled = True
LOGGER = logging.getLogger("uvicorn.error")
LOGGER = logging.getLogger("uvicorn")


async def service_status(payload: squire.StatusPayload):
Expand Down
1 change: 1 addition & 0 deletions pyninja/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERSION = "0.0.0"

0 comments on commit 7b1ea5e

Please sign in to comment.