feat(logging): add logging setup
This commit is contained in:
Vendored
+2
-1
@@ -14,7 +14,8 @@
|
|||||||
"request": "launch",
|
"request": "launch",
|
||||||
"cwd": "${workspaceFolder}",
|
"cwd": "${workspaceFolder}",
|
||||||
"console": "integratedTerminal",
|
"console": "integratedTerminal",
|
||||||
"program": "${workspaceFolder}\\.venv\\Scripts\\logwatcher.exe"
|
"module": "logwatcher.app",
|
||||||
|
//"program": "${workspaceFolder}\\.venv\\Scripts\\logwatcher.exe"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
+1
-1
@@ -9,7 +9,7 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
logwatcher = "logwatcher.main:main"
|
logwatcher = "logwatcher.app:app"
|
||||||
|
|
||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
dev = [
|
dev = [
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
def main() -> None:
|
from logwatcher.logging import setup_logging
|
||||||
print("Hello from logwatcher!")
|
|
||||||
|
logger = setup_logging()
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
from logwatcher.app import app
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
app()
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
from logwatcher import logger
|
||||||
|
from logwatcher.parser import parser
|
||||||
|
|
||||||
|
|
||||||
|
def app():
|
||||||
|
logger.info("logwatcher starts its work.")
|
||||||
|
parser()
|
||||||
|
logger.info('logwatcher has finished its task.')
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app()
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
# output path
|
||||||
|
OUTPUT_PATH = Path("output")
|
||||||
|
RESULT_PATH = OUTPUT_PATH / "results"
|
||||||
|
LOGGING_PATH = OUTPUT_PATH / "logs"
|
||||||
|
|
||||||
|
# fixture path
|
||||||
|
FIXTURE_PATH = Path.cwd() / "fixtures"
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import logging
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
def setup_formatter(
|
||||||
|
format: str = '[%(asctime)s] - %(levelname)s: %(message)s',
|
||||||
|
datefmt: str = '%d/%m/%Y %H:%M:%S'
|
||||||
|
) -> logging.Formatter:
|
||||||
|
return logging.Formatter(fmt=format, datefmt=datefmt)
|
||||||
|
|
||||||
|
|
||||||
|
def setup_file_handler(formatter: logging.Formatter, level: int , filename: Path | None = None) -> logging.Handler:
|
||||||
|
handler: logging.Handler
|
||||||
|
if filename:
|
||||||
|
handler = logging.FileHandler(filename=filename, encoding='utf-8')
|
||||||
|
else:
|
||||||
|
handler = logging.StreamHandler()
|
||||||
|
handler.setLevel(level)
|
||||||
|
handler.setFormatter(formatter)
|
||||||
|
return handler
|
||||||
|
|
||||||
|
|
||||||
|
def setup_logging() -> logging.Logger:
|
||||||
|
"""
|
||||||
|
Create a new instance of Logger named 'logger' customized for the logwatcher package.
|
||||||
|
The format display in order the time, the level of log and the log message
|
||||||
|
The logs are only redirect in the standard output.
|
||||||
|
"""
|
||||||
|
logger = logging.getLogger("logwatcher_log")
|
||||||
|
|
||||||
|
formatter = setup_formatter()
|
||||||
|
|
||||||
|
standard_output = setup_file_handler(formatter, logging.ERROR)
|
||||||
|
|
||||||
|
file_path = Path('output/logs/logwatcher.log')
|
||||||
|
file_output = setup_file_handler(formatter, logging.DEBUG, file_path)
|
||||||
|
|
||||||
|
|
||||||
|
logger.addHandler(standard_output)
|
||||||
|
logger.addHandler(file_output)
|
||||||
|
|
||||||
|
return logger
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
from logwatcher.parser import parser
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
parser()
|
|
||||||
Reference in New Issue
Block a user