Repository: sepandhaghighi/pyrgg

Issue:
Logger enhancement
#### Description
Optimize logger function
#### Expected Behavior
```
2020-09-09 16:58:02
Filename : test2.gr
Vertices : 2
Total Edges : 4
Max Edge: x
Min Edge: x
Directed: True/False
Signed: True/False
Multigraph: True/False
Self Loop: True/False
Weighted: True/False
Max Weight: x
Min Weight: x
Elapsed Time : 00 days, 00 hour, 00 minutes, 20 seconds
```
#### Actual Behavior
```
2020-09-09 16:58:02.103878
Filename : test2.gr
Vertices : 2
Edges : 4
Elapsed Time : 00 days, 00 hour, 00 minutes, 20 seconds
```
#### Operating System
Windows 10
#### Python Version
3.5.2
#### Pyrgg Version
0.8

Comments:

Patch:
diff --git a/AUTHORS.md b/AUTHORS.md
index 6cf988f..1c4ab2d 100644
--- a/AUTHORS.md
+++ b/AUTHORS.md
@@ -7,4 +7,4 @@
 # Other Contributors #
 ----------
 - [ivanovmg](https://github.com/ivanovmg)
-
+- Ahmad Salimi - Sharif University of Technology ([@ahmadsalimi](https://github.com/ahmadsalimi)) ([ahsa9978@gmail.com](mailto:ahsa9978@gmail.com))
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d06a231..174d61d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
 and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
 
 ## [Unreleased]
+### Changed
+- The `logger` function enhanced.
+- Time format in the `logger` changed to `%Y-%m-%d %H:%M:%S`
+
 ## [0.9] - 2020-10-07
 ### Added
 - GEXF format
diff --git a/pyrgg/__main__.py b/pyrgg/__main__.py
index 60b34f1..329d6aa 100644
--- a/pyrgg/__main__.py
+++ b/pyrgg/__main__.py
@@ -35,6 +35,7 @@ def run():
     input_dict = get_input()
     first_time = time.perf_counter()
     file_name = input_dict["file_name"]
+    weight = input_dict["weight"]
     min_weight = input_dict["min_weight"]
     max_weight = input_dict["max_weight"]
     vertices_number = input_dict["vertices"]
@@ -68,9 +69,18 @@ def run():
     print("Graph Generated in " + elapsed_time_format)
     print("Where --> " + SOURCE_DIR)
     logger(
+        file_name + ".gr",
         vertices_number,
         edge_number,
-        file_name + ".gr",
+        max_edge,
+        min_edge,
+        direct,
+        sign,
+        multigraph,
+        self_loop,
+        weight,
+        max_weight,
+        min_weight,
         elapsed_time_format)
 
 
diff --git a/pyrgg/functions.py b/pyrgg/functions.py
index 0ba22e8..d023182 100644
--- a/pyrgg/functions.py
+++ b/pyrgg/functions.py
@@ -120,28 +120,68 @@ def filesize(fileaddr):  # pragma: no cover
     print("Graph File Size : " + convert_bytes(file_size))
 
 
-def logger(vertices_number, edge_number, file_name, elapsed_time):
+def logger(
+        file_name, 
+        vertices_number, 
+        edge_number, 
+        max_edge, 
+        min_edge, 
+        directed, 
+        signed, 
+        multigraph, 
+        self_loop, 
+        weighted, 
+        max_weight, 
+        min_weight, 
+        elapsed_time):
     """
     Save generated graphs log.
 
+    :param file_name: file name
+    :type file_name: str
     :param vertices_number: number of vertices
     :type vertices_number:int
     :param edge_number: number of edges
     :type edge_number: int
-    :param file_name: file name
-    :type file_name: str
+    :param max_edge: maximum number of edges
+    :type max_edge: int
+    :param min_edge: minimum number of edges
+    :type min_edge: int
+    :param directed: directed
+    :type directed: int
+    :param signed: weight sign flag
+    :type signed: int
+    :param multigraph: multigraph flag
+    :type multigraph: int
+    :param self_loop: self loop flag
+    :type self_loop: int
+    :param weighted: weighted flag
+    :type weighted: int
+    :param max_weight: maximum weight
+    :type max_weight: int
+    :param min_weight: minimum weight
+    :type min_weight: int
     :param elapsed_time: elapsed time
     :type elapsed_time : str
     :return:  None
     """
     try:
         with open("logfile.log", "a") as file:
-            file.write(str(datetime.datetime.now()) + "\n")
-            file.write("Filename : " + file_name + "\n")
-            file.write("Vertices : " + str(vertices_number) + "\n")
-            file.write("Edges : " + str(edge_number) + "\n")
-            file.write("Elapsed Time : " + str(elapsed_time) + "\n")
-            file.write("-------------------------------\n")
+            file.write(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + "\n" +
+                "Filename : " + file_name + "\n" +
+                "Vertices : " + str(vertices_number) + "\n" +
+                "Total Edges : " + str(edge_number) + "\n" +
+                "Max Edge : " + str(max_edge) + "\n" +
+                "Min Edge : " + str(min_edge) + "\n" +
+                "Directed : " + str(bool(directed)) + "\n" +
+                "Signed : " + str(bool(signed)) + "\n" +
+                "Multigraph : " + str(bool(multigraph)) + "\n" +
+                "Self Loop : " + str(bool(self_loop)) + "\n" +
+                "Weighted : " + str(bool(weighted)) + "\n" +
+                "Max Weight : " + str(max_weight) + "\n" +
+                "Min Weight : " + str(min_weight) + "\n" +
+                "Elapsed Time : " + elapsed_time + "\n" +
+                "-------------------------------\n")
     except Exception:
         print(PYRGG_LOGGER_ERROR_MESSAGE)
 


Test patch:
diff --git a/pyrgg/test.py b/pyrgg/test.py
index ef15bc1..7084bb3 100644
--- a/pyrgg/test.py
+++ b/pyrgg/test.py
@@ -25,7 +25,7 @@ False
 True
 >>> is_float(None)
 False
->>> logger(2,2,2,2)
+>>> logger(2,2,2,2,2,2,2,2,2,2,2,2,2)
 [Error] Logger Failed!
 >>> result = input_filter({"file_name": "test","vertices": 5,"max_weight": 1000,"min_weight":455,"min_edge": -45,"max_edge": -11,"sign": 5,"output_format": 19, "direct": 2,"self_loop": 1,"multigraph":1})
 >>> result == {'output_format': 1, 'min_weight': 455, 'min_edge': 5, 'max_edge': 5, 'file_name': 'test', 'vertices': 5, 'max_weight': 1000, 'sign': 2, "direct": 2,"self_loop": 1,"multigraph":1}
@@ -39,7 +39,22 @@ True
 >>> result = input_filter({"file_name": "test2","vertices": 23,"max_weight": 2,"min_weight": 80,"min_edge": 23,"max_edge": 1,"sign": 1,"output_format": 1, "direct": 2,"self_loop": 10,"multigraph":10})
 >>> result == {'min_weight': 2, 'vertices': 23, 'file_name': 'test2', 'max_edge': 23, 'min_edge': 1, 'max_weight': 80, 'output_format': 1, 'sign': 1, "direct": 2,"self_loop": 1,"multigraph":1}
 True
->>> logger(100,50,'test','2min')
+>>> logger('test',100,50,1000,10,1,0,0,1,1,20,1,'2min')
+>>> file=open('logfile.log','r')
+>>> print("\n".join(file.read().splitlines()[1:-1]))
+Filename : test
+Vertices : 100
+Total Edges : 50
+Max Edge : 1000
+Min Edge : 10
+Directed : True
+Signed : False
+Multigraph : False
+Self Loop : True
+Weighted : True
+Max Weight : 20
+Min Weight : 1
+Elapsed Time : 2min
 >>> convert_bytes(200)
 '200.0 bytes'
 >>> convert_bytes(6000)
diff --git a/test/functions_test.py b/test/functions_test.py
index 446d310..a8df990 100644
--- a/test/functions_test.py
+++ b/test/functions_test.py
@@ -2,7 +2,7 @@
 """
 >>> from pyrgg.functions import *
 >>> import random
->>> logger(2,2,2,2)
+>>> logger(2,2,2,2,2,2,2,2,2,2,2,2,2)
 [Error] Logger Failed!
 >>> description_print()
 Webpage : https://www.pyrgg.ir
@@ -37,7 +37,22 @@ True
 >>> result = input_filter({"file_name": "test2","vertices": 23,"max_weight": 2,"min_weight": 80,"min_edge": 23,"max_edge": 1,"sign": 1,"output_format": 1, "direct": 2,"self_loop": 10,"multigraph":10})
 >>> result == {'min_weight': 2, 'vertices': 23, 'file_name': 'test2', 'max_edge': 23, 'min_edge': 1, 'max_weight': 80, 'output_format': 1, 'sign': 1, "direct": 2,"self_loop": 1,"multigraph":1}
 True
->>> logger(100,50,'test','2min')
+>>> logger('test',100,50,1000,10,1,0,0,1,1,20,1,'2min')
+>>> file=open('logfile.log','r')
+>>> print("\\n".join(file.read().splitlines()[1:-1]))
+Filename : test
+Vertices : 100
+Total Edges : 50
+Max Edge : 1000
+Min Edge : 10
+Directed : True
+Signed : False
+Multigraph : False
+Self Loop : True
+Weighted : True
+Max Weight : 20
+Min Weight : 1
+Elapsed Time : 2min
 >>> convert_bytes(200)
 '200.0 bytes'
 >>> convert_bytes(6000)