From 63ad7e278ed61b30f12ddd6d961bed26f032e15b Mon Sep 17 00:00:00 2001 From: MissterHao Date: Fri, 10 Feb 2023 16:30:15 +0800 Subject: [PATCH 1/3] Update README.md --- README.md | 29 ++++++++++++++---- .../dysession-beautiful-error-log-example.png | Bin 0 -> 18965 bytes tests/test_aws_dynamodb.py | 2 +- 3 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 asset/dysession-beautiful-error-log-example.png diff --git a/README.md b/README.md index 047d2b7..8e2e5a4 100644 --- a/README.md +++ b/README.md @@ -36,15 +36,16 @@ DynamoDB is Fast, flexible NoSQL database service for single-digit millisecond p Using DynamoDB for session storage alleviates issues that occur with session handling in a distributed web application by moving sessions off of the local file system and into a shared location. [[1]] -+ Easy to use! All you need is add two lines of Code! -+ Support ttl attribute ++ Easy to use! All you need is add **2 lines** of Code! ++ Support **TTL(Time to Live) attribute** Django's default session won't delete expired session data. By using DynamoDB, we can take advantage of DynamoDB's ttl attrubute to auto delete expired session data. -+ Taking advantage of AWS serverless service! ( No more effort to maintain and autoscale ) ++ No more effort to maintain and autoscale your session database ( Taking advantage of AWS serverless service! ) ++ Provide beautiful, clearful and colorful error log ## Requirements -django-dysession use `boto3` to communicate with DynamoDB. +**django-dysession** use [boto3](https://aws.amazon.com/tw/sdk-for-python/) to interact with AWS DynamoDB. Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK) for Python, which allows Python developers to write software that makes use of services like **DynamoDB**. + Django >= 3.2 @@ -52,9 +53,9 @@ Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK) for Python ## Installation -Install from PyPI ( or manually download from PyPI): +Install from PyPI ( or manually download from [PyPI](https://pypi.org/project/django-dysession/#files) ): ```bash -pip install django-dysession +pip install -U django-dysession ``` ## Getting Started @@ -137,3 +138,19 @@ DYSESSION = { | CACHE_PERIOD | 3600 | Define how long should be the cache live in DynamoDB's table | | DYNAMODB_REGION | ap-northeast-1 | The region of the DynamoDB table | + +## Logging + +Django-Dysession support three kinds of logging. + +1. Colorful TTY-based Console Log + + Support colorful and beautiful log when django-dysession interacting with AWS Dysession. + ![](/asset/dysession-beautiful-error-log-example.png) +2. Default logging stream + + Django-Dysession use python core library `logging.StreamHandler` +3. Default File Stream + + Django-Dysession use python core library `logging.FileHandler` + diff --git a/asset/dysession-beautiful-error-log-example.png b/asset/dysession-beautiful-error-log-example.png new file mode 100644 index 0000000000000000000000000000000000000000..03eb14f22e5c3530b6e85dd733b42cb056e6140a GIT binary patch literal 18965 zcmc$`WmsEX_pe*0En3_uQrz7sQlwas;!bgQ0s)G<6}M2_CAbDBCAd4my+Cm1!1Mn1 zKF_7$JerN-#l&; zrr@@ZPtTo{rNo|<4-xM?zIkOPDlhu%88{mG*6{V?`*-%znoiH2VLCrOo-dh_xj%a* zQ!FDPs_L%ychN!4cs7IP+Kz_qf>S}=z94*dx-!A>*eL&%%$kVU-E#mY6@5J8KAL%6 zaRHKM3XJjgd99)bVc{qThm}a6QRYCLeHjQq`PqU}zE+Zb);EPQ4@Fww2x(o0njqOS zS*F=^>aS)YCuE;ck*Jvzx1L?LTothUZy(@3tfObhX6aflO=7> z$pbLN-u`Pt2$XEW`ma3!7|Pf#%pd-beS_=yJx*624l2XZ#hjn(9%v$bF&x<%m(krm zHoHnwtRDK>$pa_CcQe=xjY#8OPL{UZXaee~ras^kLt#z`WXDxn7S(t(2^M;Rb*gWC z42sMToav)<3tpAvbr{OoVYnzrO@wYTlD`cPzOVPb`S+Bm& zM)>ZqMJA-Z`o{|^@PjYhhrG^#{pNj}T}emV)nAt7s*URX@q)|C95eT=){CQ?KK(Tz z7d+h+Q+CeiXbh+u`wO3F^dKbt-k}Aonbpf5wJ&g+7HChzRo`y}?zTj|FLa7DEG)yl zk?qaYrk`s~-YvtkX+tr~R^TYV&-?Icqhp{-53Mjg0T22a<3hV6Cghbpw4S2w*NH?w zSB1p|8Sy^x#>T}n4Q;ddT9>aVQBM|^$Kk!MJdWWf$}@+?ugZ&T&BZgahUoat#QpB? z62`*5AI;*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by>nR z_E~ip<=^Fe{B7^z*MTS{h2qjlGCNJWkA7|Wm0ZL=vB~_I<>qfwH(2&v&ENtaMzcCr z_O4UcjX4L7oUuyk{G#Nz+%dn>1GHNIMDU8mX~MgIB#S-z zVyv1kDHl!>WcgL&p7&$2@u~+L>mF~daFQsAOR9gKR$qQ*PDOfv>vM^;s;r*@`ghDy zUI35OKuWMhQ@+gdPCxgI#i>T5=W3_j{BK)}Py7rDyt`sezR8K_JH1^5?9yeu3wAu% z9m?$u+?>bxDgq@>CC&S6U*zerzI-zD@RzKqd)Y1&?%E}0^8U1{a@`k^xF5^UObN8g zkli_Dw_cD|S8JeoTKUoEpJ9zNwsm(=*Px3O{Bzgi-2Co#M2Ff2`TlO*CrN^@4S(7^ zU!C09t@@FP)1@g7-4(mIjf+rP2f)H`%DY27z-Bj+Z-J%IQY_2c1wZ^}o)q+9tJzw+ SH^8Hu7(8A5T-G@yGywqnnwS;< literal 0 HcmV?d00001 diff --git a/tests/test_aws_dynamodb.py b/tests/test_aws_dynamodb.py index 732f7e8..c2d4787 100644 --- a/tests/test_aws_dynamodb.py +++ b/tests/test_aws_dynamodb.py @@ -21,7 +21,7 @@ class AWSDynamoDBTestCase(TestCase): def setUp(self): - logging.disable(logging.CRITICAL) + logging.disable(logging.NOTSET) def tearDown(self): logging.disable(logging.NOTSET) From ec31caef17cfcfc2ba4ba9353f715ab3ba5346c6 Mon Sep 17 00:00:00 2001 From: MissterHao Date: Fri, 10 Feb 2023 16:56:07 +0800 Subject: [PATCH 2/3] feat: add logging configuration to settings.py --- README.md | 21 +++++++++++++-------- dysession/logger/__init__.py | 18 ++++++++++++++++-- dysession/settings.py | 3 +++ tests/test_aws_dynamodb.py | 15 +++++---------- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 8e2e5a4..f5e8abf 100644 --- a/README.md +++ b/README.md @@ -126,17 +126,22 @@ DYSESSION = { "TTL_ATTRIBUTE_NAME": "ttl", "CACHE_PERIOD": 3600, "DYNAMODB_REGION": "ap-northeast-1", + "LOGGING": { + "TYPE": "CONSOLE", + }, } ``` - -| Argument | Default | Description | -| ------------------ | -------------- | ------------------------------------------------------------ | -| DYNAMODB_TABLENAME | sessions | DynamoDB table name | -| PARTITION_KEY_NAME | PK | Partition key name | -| TTL_ATTRIBUTE_NAME | ttl | Time to live attribute name | -| CACHE_PERIOD | 3600 | Define how long should be the cache live in DynamoDB's table | -| DYNAMODB_REGION | ap-northeast-1 | The region of the DynamoDB table | +| Argument | Default | Description | +|----------------------|----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| DYNAMODB_TABLENAME | sessions | DynamoDB table name | +| PARTITION_KEY_NAME | PK | Partition key name | +| TTL_ATTRIBUTE_NAME | ttl | Time to live attribute name | +| CACHE_PERIOD | 3600 | Define how long should be the cache live in DynamoDB's table | +| DYNAMODB_REGION | ap-northeast-1 | The region of the DynamoDB table | +| LOGGING | Dict | Configuration of Logging | +| LOGGING["TYPE"] | CONSOLE | Only accept two kinds of parameters: `CONSOLE`, `FILE`. If this set to `CONSOLE`, django-dysession will use `StreamHandler` to stream to the console. If this set to `FILE`, django-dysession will use `FileHandler` to stream to `LOGGING["FILE_PATH"]`. | +| LOGGING["FILE_PATH"] | session.log | The file path to save logs of session managements. | ## Logging diff --git a/dysession/logger/__init__.py b/dysession/logger/__init__.py index ccac192..334b77c 100644 --- a/dysession/logger/__init__.py +++ b/dysession/logger/__init__.py @@ -4,6 +4,8 @@ from functools import lru_cache from typing import Literal +from dysession.settings import get_config + from .handler.colorful_console import ColorfulConsoleLoggerHandler @@ -23,7 +25,7 @@ def is_tty() -> bool: def get_logger( logger_name: str = "dysession", - logger_type: Literal[LoggingType.CONSOLE, LoggingType.FILE] = LoggingType.CONSOLE, + logger_type: Literal[None, LoggingType.CONSOLE, LoggingType.FILE] = None, level: int = logging.DEBUG, ) -> logging.Logger: """ @@ -40,6 +42,17 @@ def get_logger( ``` """ + if logger_type is None: + try: + logger_type = LoggingType[get_config()["LOGGING"]["TYPE"]] + if ( + logger_type == LoggingType.PLAINTEXT_CONSOLE + or logger_type == LoggingType.COLOR_CONSOLE + ): + raise KeyError + except KeyError: + raise KeyError("logger_type only accept 'CONSOLE' and 'FILE'") + logger = logging.getLogger(logger_name) format = logging.Formatter( "[%(asctime)-s] [%(levelname)-8s] %(name)s %(message)s ... ( %(filename)s:%(levelno)s )" @@ -53,7 +66,8 @@ def get_logger( else: handler = logging.StreamHandler() elif logger_type == LoggingType.FILE: - handler = logging.FileHandler("session.log", "a", encoding="utf-8") + filepath = get_config()["LOGGING"].get("FILE_PATH", "session.log") + handler = logging.FileHandler(filepath, "a", encoding="utf-8") handler.setFormatter(format) logger.addHandler(handler) diff --git a/dysession/settings.py b/dysession/settings.py index 40a76a3..d255252 100644 --- a/dysession/settings.py +++ b/dysession/settings.py @@ -12,6 +12,9 @@ "TTL_ATTRIBUTE_NAME": "ttl", "CACHE_PERIOD": 3600, "DYNAMODB_REGION": "ap-northeast-1", + "LOGGING": { + "TYPE": "CONSOLE", + }, } diff --git a/tests/test_aws_dynamodb.py b/tests/test_aws_dynamodb.py index c2d4787..ade3c3d 100644 --- a/tests/test_aws_dynamodb.py +++ b/tests/test_aws_dynamodb.py @@ -5,15 +5,10 @@ from moto import mock_dynamodb from parameterized import parameterized -from dysession.aws.dynamodb import ( - check_dynamodb_table_exists, - create_dynamodb_table, - delete_session_item, - destory_dynamodb_table, - get_item, - insert_session_item, - key_exists, -) +from dysession.aws.dynamodb import (check_dynamodb_table_exists, + create_dynamodb_table, delete_session_item, + destory_dynamodb_table, get_item, + insert_session_item, key_exists) from dysession.aws.error import DynamodbItemNotFound, DynamodbTableNotFound from dysession.backends.model import SessionDataModel from dysession.settings import get_config @@ -21,7 +16,7 @@ class AWSDynamoDBTestCase(TestCase): def setUp(self): - logging.disable(logging.NOTSET) + logging.disable(logging.CRITICAL) def tearDown(self): logging.disable(logging.NOTSET) From aaea2ed604ad295754aada8cfd0a3c106e634435 Mon Sep 17 00:00:00 2001 From: MissterHao Date: Mon, 13 Feb 2023 13:44:50 +0800 Subject: [PATCH 3/3] feat: documentation and type hint --- README.md | 2 +- dysession/backends/db.py | 7 +++---- dysession/backends/model.py | 6 +++--- dysession/logger/__init__.py | 1 + dysession/logger/handler/colorful_console.py | 3 ++- dysession/settings.py | 3 +++ dysession/version.txt | 2 +- 7 files changed, 14 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f5e8abf..a8eb96b 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ DYSESSION = { | DYNAMODB_REGION | ap-northeast-1 | The region of the DynamoDB table | | LOGGING | Dict | Configuration of Logging | | LOGGING["TYPE"] | CONSOLE | Only accept two kinds of parameters: `CONSOLE`, `FILE`. If this set to `CONSOLE`, django-dysession will use `StreamHandler` to stream to the console. If this set to `FILE`, django-dysession will use `FileHandler` to stream to `LOGGING["FILE_PATH"]`. | -| LOGGING["FILE_PATH"] | session.log | The file path to save logs of session managements. | +| LOGGING["FILE_PATH"] | session.log | Optional. Only use this configuration when LOGGING["TYPE"] is set to `FILE`. The file path to save logs of session managements. | ## Logging diff --git a/dysession/backends/db.py b/dysession/backends/db.py index 8a57f46..6860b3a 100644 --- a/dysession/backends/db.py +++ b/dysession/backends/db.py @@ -58,7 +58,7 @@ def _get_session(self, no_load=False) -> SessionDataModel: def key_salt(self): return "dysession.backends." + self.__class__.__qualname__ - def is_empty(self): + def is_empty(self) -> bool: "Return True when there is no session_key and the session is empty." try: return not self._session_key and not self._session_cache.is_empty @@ -69,10 +69,10 @@ def clear(self): super().clear() self._session_cache = SessionDataModel() - def items(self): + def items(self) -> Dict[str, Any]: return self._session.items() - def __str__(self): + def __str__(self) -> str: return str(self._get_session()) # Methods that subclass must implement @@ -124,7 +124,6 @@ def delete(self, session_key=None): if session_key is None: session_key = self._session_key - try: self.db.delete(self._get_session()) except DeleteSessionError: diff --git a/dysession/backends/model.py b/dysession/backends/model.py index 261ca6f..a3a1309 100644 --- a/dysession/backends/model.py +++ b/dysession/backends/model.py @@ -48,12 +48,12 @@ def __delitem__(self, key): def __iter__(self): return iter(self.__variables_names) - def __is_empty(self): + def __is_empty(self) -> bool: return len(self.__variables_names) == 0 is_empty = property(__is_empty) - def get(self, key, default=...): + def get(self, key, default=...) -> Any: try: return self[key] except AttributeError: @@ -61,7 +61,7 @@ def get(self, key, default=...): raise return default - def pop(self, key, default=...): + def pop(self, key, default=...) -> Any: try: ret = self[key] del self[key] diff --git a/dysession/logger/__init__.py b/dysession/logger/__init__.py index 334b77c..60863c6 100644 --- a/dysession/logger/__init__.py +++ b/dysession/logger/__init__.py @@ -10,6 +10,7 @@ class LoggingType(Enum): + """Enum of python logger type.""" PLAINTEXT_CONSOLE = auto() COLOR_CONSOLE = auto() diff --git a/dysession/logger/handler/colorful_console.py b/dysession/logger/handler/colorful_console.py index 1139523..298e981 100644 --- a/dysession/logger/handler/colorful_console.py +++ b/dysession/logger/handler/colorful_console.py @@ -1,8 +1,9 @@ import logging +from typing import Dict from .ansi import ANSIColor -LOGLEVEL_TRANSFORM = { +LOGLEVEL_TRANSFORM: Dict[int, str] = { logging.DEBUG: ANSIColor.DEBUG.value, logging.INFO: ANSIColor.OKCYAN.value, logging.WARNING: ANSIColor.WARNING.value, diff --git a/dysession/settings.py b/dysession/settings.py index d255252..4dcbb7e 100644 --- a/dysession/settings.py +++ b/dysession/settings.py @@ -29,6 +29,9 @@ def get_config() -> Dict[str, Union[str, int]]: * TTL_ATTRIBUTE_NAME * CACHE_PERIOD * DYNAMODB_REGION + * LOGGING + * TYPE + * FILE_PATH Returns: Dict[str, Union[str, int]] diff --git a/dysession/version.txt b/dysession/version.txt index 1cc5f65..8cfbc90 100644 --- a/dysession/version.txt +++ b/dysession/version.txt @@ -1 +1 @@ -1.1.0 \ No newline at end of file +1.1.1 \ No newline at end of file