-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
206 additions
and
70 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ atlas_client/test/ | |
atlas_client/__pycache__/ | ||
.idea/ | ||
log | ||
my_secrets | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
__version__ = '0.2.2' | ||
|
||
|
||
# Set default logging handler to avoid "No handler found" warnings. | ||
import logging | ||
logging.getLogger('atlaspyapi').addHandler(logging.NullHandler()) |
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,37 @@ | ||
import logging | ||
import sys | ||
from logging.handlers import TimedRotatingFileHandler | ||
from pathlib import Path | ||
|
||
FORMATTER = logging.Formatter("%(asctime)s — %(name)s — %(levelname)s — %(message)s") | ||
LOG_FILE = "../log/atlas_client.log" | ||
|
||
class LogManager: | ||
|
||
def get_console_handler(): | ||
console_handler = logging.StreamHandler(sys.stdout) | ||
console_handler.setFormatter(FORMATTER) | ||
return console_handler | ||
def __init__(self, logger_name: str, enable_file_handler=False, log_propagate=False, | ||
log_format="%(asctime)s — %(name)s — %(levelname)s — %(message)s", | ||
log_file_path="~/atlas_client_log"): | ||
self.logger_name = logger_name | ||
self.enable_file_handler = enable_file_handler | ||
self.log_propagate = log_propagate | ||
self.log_file_path = log_file_path | ||
self.formatter = logging.Formatter(log_format) | ||
|
||
def get_console_handler(self): | ||
console_handler = logging.StreamHandler(sys.stdout) | ||
console_handler.setFormatter(self.formatter) | ||
return console_handler | ||
|
||
def get_file_handler(): | ||
file_handler = TimedRotatingFileHandler(LOG_FILE, when='midnight') | ||
file_handler.setFormatter(FORMATTER) | ||
return file_handler | ||
def get_file_handler(self): | ||
Path(self.log_file_path).mkdir(parents=True, exist_ok=True) | ||
file_handler = TimedRotatingFileHandler(f"{self.log_file_path}/app.log", when='midnight') | ||
file_handler.setFormatter(self.formatter) | ||
return file_handler | ||
|
||
|
||
def get_logger(logger_name): | ||
logger = logging.getLogger(logger_name) | ||
logger.setLevel(logging.DEBUG) # better to have too much log than not enough | ||
logger.addHandler(get_console_handler()) | ||
logger.addHandler(get_file_handler()) | ||
# with this pattern, it's rarely necessary to propagate the error up to parent | ||
logger.propagate = False | ||
return logger | ||
def get_logger(self): | ||
logger = logging.getLogger(self.logger_name) | ||
logger.setLevel(logging.DEBUG) # better to have too much log than not enough | ||
logger.addHandler(self.get_console_handler()) | ||
if self.enable_file_handler: | ||
logger.addHandler(self.get_file_handler()) | ||
# with this pattern, it's rarely necessary to propagate the error up to parent | ||
logger.propagate = self.log_propagate | ||
return logger |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
[tool.poetry] | ||
name = "atlas_client" | ||
version = "0.1.0" | ||
name = "atlaspyapi" | ||
version = "0.2.0" | ||
description = "" | ||
authors = ["pengfei <[email protected]>"] | ||
keywords = ["keyword", "another_keyword"] | ||
readme = "README.md" | ||
license = "Apache License 2.0" | ||
homepage = "https://github.com/pengfei99/AtlasPyApi" | ||
repository = "https://github.com/pengfei99/AtlasPyApi" | ||
include = [ | ||
"LICENSE", | ||
] | ||
|
||
|
||
[tool.poetry.dependencies] | ||
python = "^3.8" | ||
Jinja2 = "^3.0.3" | ||
six = "^1.16.0" | ||
click = "^8.0.4" | ||
requests = "^2.27.1" | ||
twine = "^3.8.0" | ||
apache-atlas = "^0.0.11" | ||
|
||
|
||
|
||
[tool.poetry.dev-dependencies] | ||
|
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
Oops, something went wrong.