Skip to content

Commit

Permalink
create logs in temp directory (#51)
Browse files Browse the repository at this point in the history
* log dir is created in tempdir based on service name

* bump Version 2.2.0

---------

Co-authored-by: lindakladivova <[email protected]>
  • Loading branch information
landam and lindakladivova authored Oct 5, 2023
1 parent 92bc86b commit 44b27f5
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 23 deletions.
12 changes: 10 additions & 2 deletions docs/notebooks/cenove_udaje_dle_ku_json_zip.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@
"execution_count": 2,
"id": "b71f2fbd",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"generujCenoveUdajeDleKu - INFO - Logovaci zpravy ulozeny v adresari: /tmp/generujCenoveUdajeDleKu\n"
]
}
],
"source": [
"creds_test = [\"WSTEST\", \"WSHESLO\"]\n",
"cen_udaje = GenerujCenoveUdajeDleKu(creds_test, trial=True)"
Expand Down Expand Up @@ -247,7 +255,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
38 changes: 36 additions & 2 deletions docs/notebooks/ctios_db.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@
"execution_count": 2,
"id": "6a289697",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"ctiOS - INFO - Logovaci zpravy ulozeny v adresari: /tmp/ctiOS\n"
]
}
],
"source": [
"creds_test = [\"WSTEST\", \"WSHESLO\"]\n",
"ctios = CtiOS(creds_test, trial=True)"
Expand Down Expand Up @@ -75,6 +83,32 @@
")"
]
},
{
"cell_type": "markdown",
"id": "0cf876bf",
"metadata": {},
"source": [
"Pokud chceme změnit cestu k logovacímu adresáři, uděláme to následovně:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "b1f71745",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"ctiOS - INFO - Logovaci adresar nastaven na cestu: /home/linduska/pywsdp/logs\n"
]
}
],
"source": [
"ctios.log_adresar = \"/home/linduska/pywsdp/logs\""
]
},
{
"cell_type": "markdown",
"id": "f52cd569",
Expand Down Expand Up @@ -220,7 +254,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
14 changes: 11 additions & 3 deletions docs/notebooks/ctios_json_csv.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@
"execution_count": 2,
"id": "b71f2fbd",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"ctiOS - INFO - Logovaci zpravy ulozeny v adresari: /tmp/ctiOS\n"
]
}
],
"source": [
"creds_test = [\"WSTEST\", \"WSHESLO\"]\n",
"ctios = CtiOS(creds_test, trial=True)"
Expand All @@ -61,7 +69,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"id": "654c8be8",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -255,7 +263,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
12 changes: 10 additions & 2 deletions docs/notebooks/spravuj_sestavy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@
"execution_count": 2,
"id": "b71f2fbd",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"generujCenoveUdajeDleKu - INFO - Logovaci zpravy ulozeny v adresari: /tmp/generujCenoveUdajeDleKu\n"
]
}
],
"source": [
"creds_test = [\"WSTEST\", \"WSHESLO\"]\n",
"cen_udaje = GenerujCenoveUdajeDleKu(creds_test, trial=True)"
Expand Down Expand Up @@ -189,7 +197,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
21 changes: 7 additions & 14 deletions pywsdp/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@

import os
import json
import tempfile
from pathlib import Path

from pywsdp.clients.factory import pywsdp
from pywsdp.base.logger import WSDPLogger
from pywsdp.base.exceptions import WSDPError

__version__ = "2.1.0"
__version__ = "2.2.0"


class WSDPBase:
Expand Down Expand Up @@ -63,7 +64,8 @@ def pristupove_udaje(self) -> dict:

@property
def log_adresar(self) -> str:
"""Vypise cestu k adresari, ve kterem se budou vytvaret log soubory."""
"""Vypise cestu k adresari, ve kterem se budou vytvaret log soubory.
Zaroven funguje i jako setter pro nastaveni vlastniho logovaciho adresare."""
return self._log_adresar

@log_adresar.setter
Expand All @@ -77,6 +79,7 @@ def log_adresar(self, log_adresar: str):
os.makedirs(log_adresar)
self.logger.set_directory(log_adresar)
self._log_adresar = log_adresar
self.logger.info("Logovaci adresar nastaven na cestu: {}".format(log_adresar))

@property
def testovaci_mod(self) -> bool:
Expand All @@ -99,21 +102,11 @@ def posli_pozadavek(self, slovnik_identifikatoru: dict) -> dict:
def _set_default_log_dir(self) -> str:
"""Privatni metoda pro nasteveni logovaciho adresare."""

def is_run_by_jupyter():
import __main__ as main

return not hasattr(main, "__file__")

if is_run_by_jupyter():
module_dir = os.path.abspath(os.path.join("../../"))
else:
module_dir = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "..")
)
log_dir = os.path.join(module_dir, "logs")
log_dir = os.path.join(tempfile.gettempdir(), self.nazev_sluzby)
if not os.path.exists(log_dir):
os.makedirs(log_dir)
self.logger.set_directory(log_dir)
self.logger.info("Logovaci zpravy ulozeny v adresari: {}".format(log_dir))
return log_dir


Expand Down

0 comments on commit 44b27f5

Please sign in to comment.