-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
30 lines (23 loc) · 774 Bytes
/
Copy pathutils.py
File metadata and controls
30 lines (23 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# -*- coding: utf-8 -*-
import logging
import os
import random
from time import sleep
logger = logging.getLogger('sns.utils')
_format = '%(asctime)s [%(name)s] [%(filename)s:%(lineno)s] [%(levelname)s] %(message)s'
def init_loggers():
logger = logging.getLogger('sns') # type: logging.Logger
level = logging.INFO
if os.getenv('LOG_LEVEL'):
level = logging.getLevelName(os.getenv('LOG_LEVEL'))
try:
logger.setLevel(level)
except:
logger.setLevel(logging.INFO)
# Stream
ch = logging.StreamHandler()
ch.setFormatter(logging.Formatter(_format))
logger.addHandler(ch)
def random_sleep(self, min_seconds=0.5, max_seconds=2):
wait = random.random() * (max_seconds - min_seconds) + min_seconds
sleep(wait)