Skip to content

Commit 201cbc0

Browse files
committedNov 13, 2016
Rewrite of logging
1 parent 4713c9a commit 201cbc0

File tree

8 files changed

+36
-93
lines changed

8 files changed

+36
-93
lines changed
 

‎config.defaults.ini

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
;; DEFAULT congig for nichtparasoup
2-
1+
;; DEFAULT config for nichtparasoup
32

43
;; DO
54
;; NOT
65
;; TOUCH
76

8-
97
[General]
108
Port: 5000
119
IP: 0.0.0.0
@@ -15,7 +13,8 @@ Useragent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10) AppleWebKit/600.1.25 (K
1513
Images_min_limit: 15
1614

1715
[Logging]
18-
Log_name: nichtparasoup
16+
;; possible destinations: file syslog
17+
Destination: file
1918
File: nichtparasoup.log
2019
;; verbosity levels: CRITICAL ERROR WARNING INFO DEBUG NOTSET
2120
Verbosity: ERROR

‎config.ini

-25
This file was deleted.

‎configs/demo.ini

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
1-
; congig for nichtparasoup
2-
31
[General]
42
Port: 5006
5-
IP: 0.0.0.0
6-
Useragent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10) AppleWebKit/600.1.25 (KHTML, like Gecko) Version/8.0 Safari/600.1.25
7-
8-
[Cache]
9-
Images_min_limit: 15
103

114
[Logging]
12-
Log_name: nichtparasoup
13-
File: logs/nichtparasoup.log
14-
; verbosity levels: CRITICAL ERROR WARNING INFO DEBUG NOTSET
15-
Verbosity: NOTSET
5+
Destination: syslog
6+
Verbosity: WARNING
167

178
[Sites]
18-
; set to false or remove a Crawler, to disable it
199
SoupIO: false
2010
Pr0gramm: top*5.0
2111
Reddit: gifs*6.0,pics*4.0,aww_gifs,reactiongifs,FoodPorn*1.0,cats,EarthPorn

‎configs/kadsen.ini

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
1-
; congig for nichtparasoup
2-
31
[General]
42
Port: 5003
5-
IP: 0.0.0.0
6-
Useragent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10) AppleWebKit/600.1.25 (KHTML, like Gecko) Version/8.0 Safari/600.1.25
7-
8-
[Cache]
9-
Images_min_limit: 15
103

114
[Logging]
12-
Log_name: nichtparasoup
13-
File: logs/nichtparasoup.log
14-
; verbosity levels: CRITICAL ERROR WARNING INFO DEBUG NOTSET
15-
Verbosity: NOTSET
5+
Destination: syslog
6+
Verbosity: WARNING
167

178
[Sites]
18-
; set to false or remove a Crawler, to disable it
199
Reddit: aww_gifs,aww,cats

‎configs/nsfw.ini

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
1-
; congig for nichtparasoup
2-
31
[General]
42
Port: 5002
5-
IP: 0.0.0.0
6-
Useragent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10) AppleWebKit/600.1.25 (KHTML, like Gecko) Version/8.0 Safari/600.1.25
7-
8-
[Cache]
9-
Images_min_limit: 15
103

114
[Logging]
12-
Log_name: nichtparasoup
13-
File: logs/nichtparasoup.log
14-
; verbosity levels: CRITICAL ERROR WARNING INFO DEBUG NOTSET
15-
Verbosity: NOTSET
5+
Destination: Syslog
6+
Verbosity: WARNING
167

178
[Sites]
18-
; set to false or remove a Crawler, to disable it
199
SoupIO: everyone*5.0
2010
Pr0gramm: top*9.0,new*0.5
2111
Reddit: nsfw,gifs,pics,nsfw_gifs,aww_gifs*0.3,reactiongifs,wtf*3.0

‎configs/pr0.ini

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
1-
; congig for nichtparasoup
2-
31
[General]
42
Port: 5004
5-
IP: 0.0.0.0
6-
Useragent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10) AppleWebKit/600.1.25 (KHTML, like Gecko) Version/8.0 Safari/600.1.25
7-
8-
[Cache]
9-
Images_min_limit: 15
103

114
[Logging]
12-
Log_name: nichtparasoup
13-
File: logs/nichtparasoup.log
14-
; verbosity levels: CRITICAL ERROR WARNING INFO DEBUG NOTSET
15-
Verbosity: NOTSET
5+
Destination: syslog
6+
Verbosity: WARNING
167

178
[Sites]
18-
; set to false or remove a Crawler, to disable it
199
Pr0gramm: top*9.0,new*0.8

‎configs/sfw.ini

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
1-
; congig for nichtparasoup
2-
31
[General]
42
Port: 5000
5-
IP: 0.0.0.0
6-
Useragent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10) AppleWebKit/600.1.25 (KHTML, like Gecko) Version/8.0 Safari/600.1.25
7-
8-
[Cache]
9-
Images_min_limit: 15
103

114
[Logging]
12-
Log_name: nichtparasoup
13-
File: logs/nichtparasoup.log
14-
; verbosity levels: CRITICAL ERROR WARNING INFO DEBUG NOTSET
15-
Verbosity: NOTSET
5+
Destination: syslog
6+
Verbosity: warning
167

178
[Sites]
18-
; set to false or remove a Crawler, to disable it
199
SoupIO: false
2010
Pr0gramm: false
2111
Reddit: gifs*6.0,pics*4.0,aww_gifs,reactiongifs,photoshopbattles*3.0,earthporn*0.5,diy,engineeringporn,mechanical_gifs,cableporn,shittylifehacks*3.0,perfecttiming

‎nichtparasoup.py

+23-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from os import path
55
import random
66
import logging
7+
import logging.handlers
78
import time
89
import threading
910
import argparse
@@ -23,6 +24,8 @@
2324
from werkzeug.exceptions import HTTPException, NotFound
2425
from werkzeug.serving import run_simple
2526

27+
28+
2629
## import templates
2730
import templates as tmpl
2831

@@ -40,26 +43,42 @@
4043
dest="config_file")
4144
args = arg_parser.parse_args()
4245

43-
## configuration
46+
### configuration
47+
# init config parser
4448
config = RawConfigParser()
49+
50+
# read defaults
4551
config.read(path.join(_file_path, 'config.defaults.ini'))
4652
try:
4753
config.read_file(args.config_file) # py3
4854
except AttributeError:
4955
config.readfp(args.config_file) # py2
5056
args.config_file.close()
5157

58+
# get actual config items
5259
nps_port = config.getint("General", "Port")
5360
nps_bindip = config.get("General", "IP")
61+
5462
min_cache_imgs_before_refill = config.getint("Cache", "Images_min_limit")
5563
user_agent = config.get("General", "Useragent")
64+
65+
# crawler logging config
5666
logverbosity = config.get("Logging", "Verbosity")
57-
logger = logging.getLogger(config.get("Logging", "Log_name"))
58-
hdlr = logging.FileHandler(config.get("Logging", "File"))
59-
hdlr.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s'))
67+
logger = logging.getLogger("nichtparasoup")
68+
69+
if config.get("Logging", "Destination").lower() == 'syslog':
70+
hdlr = logging.handlers.SysLogHandler()
71+
else:
72+
hdlr = logging.FileHandler(config.get("Logging", "File"))
73+
hdlr.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s'))
74+
6075
logger.addHandler(hdlr)
6176
logger.setLevel(logverbosity.upper())
6277

78+
# werkzeug logging config
79+
log = logging.getLogger('werkzeug')
80+
log.setLevel(logging.CRITICAL)
81+
6382
try:
6483
urlpath = config.get("General", "Urlpath")
6584
except:

0 commit comments

Comments
 (0)
Please sign in to comment.