5
5
License: MIT
6
6
"""
7
7
import logging
8
- import random
9
8
import secrets
10
-
9
+ import threading
11
10
from loguru import logger
12
11
from tqdm import tqdm
13
-
14
12
from dsg_lib .common_functions import logging_config
15
13
14
+ # Configure logging as before
16
15
logging_config .config_log (
17
- logging_directory = 'log' , # Directory where logs will be stored
18
- log_name = 'log' , # Name of the log file
19
- logging_level = 'DEBUG' , # Logging level
20
- log_rotation = '500 MB' , # Log rotation size
21
- log_retention = '10 days' , # Log retention period
22
- log_backtrace = True , # Enable backtrace
23
- # log_format="<green>{time:YYYY-MM-DD HH:mm:ss.SSSSSS}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>", # Log format
24
- log_serializer = False , # Disable log serialization
25
- log_diagnose = True , # Enable diagnose
26
- app_name = 'my_app' , # Application name
27
- append_app_name = True , # Append application name to the log file name
16
+ logging_directory = 'log' ,
17
+ log_name = 'log' ,
18
+ logging_level = 'DEBUG' ,
19
+ log_rotation = '1 MB' ,
20
+ log_retention = '10 days' ,
21
+ log_backtrace = True ,
22
+ log_serializer = False ,
23
+ log_diagnose = True ,
24
+ # app_name='my_app',
25
+ # append_app_name=True,
26
+ file_sink = True ,
27
+ intercept_standard_logging = True ,
28
+ enqueue = False
28
29
)
29
30
30
- # after configuring logging
31
- # user loguru to log messages
32
- logger .debug ('This is a debug message' )
33
- logger .info ('This is an info message' )
34
- logger .error ('This is an error message' )
35
- logger .warning ('This is a warning message' )
36
- logger .critical ('This is a critical message' )
37
-
38
- # will intercept all standard logging messages also
39
- logging .debug ('This is a debug message' )
40
- logging .info ('This is an info message' )
41
- logging .error ('This is an error message' )
42
- logging .warning ('This is a warning message' )
43
- logging .critical ('This is a critical message' )
44
-
45
31
46
32
def div_zero (x , y ):
47
33
try :
@@ -56,12 +42,43 @@ def div_zero_two(x, y):
56
42
return x / y
57
43
58
44
59
- a = div_zero (x = 1 , y = 0 )
60
- b = div_zero_two (x = 1 , y = 0 )
61
45
62
- for _ in tqdm (range (5000 ), ascii = True ):
63
- big_string = ''
64
- for _ in range (random .randint (275 , 1000 )):
65
- big_string += f'{ secrets .token_urlsafe (random .randint (1 ,5 ))} '
66
- # log a lot of data
67
- logging .debug (f'Lets make this a big message { big_string } ' )
46
+ def log_big_string (_ ):
47
+ big_string = secrets .token_urlsafe (256 )
48
+ for _ in range (100 ):
49
+ logging .debug (f'Lets make this a big message { big_string } ' )
50
+ div_zero (x = 1 , y = 0 )
51
+ div_zero_two (x = 1 , y = 0 )
52
+ # after configuring logging
53
+ # user loguru to log messages
54
+ logger .debug ('This is a debug message' )
55
+ logger .info ('This is an info message' )
56
+ logger .error ('This is an error message' )
57
+ logger .warning ('This is a warning message' )
58
+ logger .critical ('This is a critical message' )
59
+
60
+ # will intercept all standard logging messages also
61
+ logging .debug ('This is a debug message' )
62
+ logging .info ('This is an info message' )
63
+ logging .error ('This is an error message' )
64
+ logging .warning ('This is a warning message' )
65
+ logging .critical ('This is a critical message' )
66
+
67
+
68
+
69
+ def worker ():
70
+ for _ in tqdm (range (100 ), ascii = True ): # Adjusted for demonstration
71
+ log_big_string (None )
72
+
73
+ def main ():
74
+ threads = []
75
+ for _ in range (4 ): # Create x threads
76
+ t = threading .Thread (target = worker )
77
+ threads .append (t )
78
+ t .start ()
79
+
80
+ for t in threads :
81
+ t .join ()
82
+
83
+ if __name__ == "__main__" :
84
+ main ()
0 commit comments