Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Rewrite of logging
  • Loading branch information
noqqe committed Nov 13, 2016
1 parent 4713c9a commit 201cbc0
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 93 deletions.
7 changes: 3 additions & 4 deletions config.defaults.ini
@@ -1,11 +1,9 @@
;; DEFAULT congig for nichtparasoup

;; DEFAULT config for nichtparasoup

;; DO
;; NOT
;; TOUCH


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

[Logging]
Log_name: nichtparasoup
;; possible destinations: file syslog
Destination: file
File: nichtparasoup.log
;; verbosity levels: CRITICAL ERROR WARNING INFO DEBUG NOTSET
Verbosity: ERROR
Expand Down
25 changes: 0 additions & 25 deletions config.ini

This file was deleted.

14 changes: 2 additions & 12 deletions configs/demo.ini
@@ -1,21 +1,11 @@
; congig for nichtparasoup

[General]
Port: 5006
IP: 0.0.0.0
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

[Cache]
Images_min_limit: 15

[Logging]
Log_name: nichtparasoup
File: logs/nichtparasoup.log
; verbosity levels: CRITICAL ERROR WARNING INFO DEBUG NOTSET
Verbosity: NOTSET
Destination: syslog
Verbosity: WARNING

[Sites]
; set to false or remove a Crawler, to disable it
SoupIO: false
Pr0gramm: top*5.0
Reddit: gifs*6.0,pics*4.0,aww_gifs,reactiongifs,FoodPorn*1.0,cats,EarthPorn
Expand Down
14 changes: 2 additions & 12 deletions configs/kadsen.ini
@@ -1,19 +1,9 @@
; congig for nichtparasoup

[General]
Port: 5003
IP: 0.0.0.0
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

[Cache]
Images_min_limit: 15

[Logging]
Log_name: nichtparasoup
File: logs/nichtparasoup.log
; verbosity levels: CRITICAL ERROR WARNING INFO DEBUG NOTSET
Verbosity: NOTSET
Destination: syslog
Verbosity: WARNING

[Sites]
; set to false or remove a Crawler, to disable it
Reddit: aww_gifs,aww,cats
14 changes: 2 additions & 12 deletions configs/nsfw.ini
@@ -1,21 +1,11 @@
; congig for nichtparasoup

[General]
Port: 5002
IP: 0.0.0.0
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

[Cache]
Images_min_limit: 15

[Logging]
Log_name: nichtparasoup
File: logs/nichtparasoup.log
; verbosity levels: CRITICAL ERROR WARNING INFO DEBUG NOTSET
Verbosity: NOTSET
Destination: Syslog
Verbosity: WARNING

[Sites]
; set to false or remove a Crawler, to disable it
SoupIO: everyone*5.0
Pr0gramm: top*9.0,new*0.5
Reddit: nsfw,gifs,pics,nsfw_gifs,aww_gifs*0.3,reactiongifs,wtf*3.0
Expand Down
14 changes: 2 additions & 12 deletions configs/pr0.ini
@@ -1,19 +1,9 @@
; congig for nichtparasoup

[General]
Port: 5004
IP: 0.0.0.0
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

[Cache]
Images_min_limit: 15

[Logging]
Log_name: nichtparasoup
File: logs/nichtparasoup.log
; verbosity levels: CRITICAL ERROR WARNING INFO DEBUG NOTSET
Verbosity: NOTSET
Destination: syslog
Verbosity: WARNING

[Sites]
; set to false or remove a Crawler, to disable it
Pr0gramm: top*9.0,new*0.8
14 changes: 2 additions & 12 deletions configs/sfw.ini
@@ -1,21 +1,11 @@
; congig for nichtparasoup

[General]
Port: 5000
IP: 0.0.0.0
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

[Cache]
Images_min_limit: 15

[Logging]
Log_name: nichtparasoup
File: logs/nichtparasoup.log
; verbosity levels: CRITICAL ERROR WARNING INFO DEBUG NOTSET
Verbosity: NOTSET
Destination: syslog
Verbosity: warning

[Sites]
; set to false or remove a Crawler, to disable it
SoupIO: false
Pr0gramm: false
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
Expand Down
27 changes: 23 additions & 4 deletions nichtparasoup.py
Expand Up @@ -4,6 +4,7 @@
from os import path
import random
import logging
import logging.handlers
import time
import threading
import argparse
Expand All @@ -23,6 +24,8 @@
from werkzeug.exceptions import HTTPException, NotFound
from werkzeug.serving import run_simple



## import templates
import templates as tmpl

Expand All @@ -40,26 +43,42 @@
dest="config_file")
args = arg_parser.parse_args()

## configuration
### configuration
# init config parser
config = RawConfigParser()

# read defaults
config.read(path.join(_file_path, 'config.defaults.ini'))
try:
config.read_file(args.config_file) # py3
except AttributeError:
config.readfp(args.config_file) # py2
args.config_file.close()

# get actual config items
nps_port = config.getint("General", "Port")
nps_bindip = config.get("General", "IP")

min_cache_imgs_before_refill = config.getint("Cache", "Images_min_limit")
user_agent = config.get("General", "Useragent")

# crawler logging config
logverbosity = config.get("Logging", "Verbosity")
logger = logging.getLogger(config.get("Logging", "Log_name"))
hdlr = logging.FileHandler(config.get("Logging", "File"))
hdlr.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s'))
logger = logging.getLogger("nichtparasoup")

if config.get("Logging", "Destination").lower() == 'syslog':
hdlr = logging.handlers.SysLogHandler()
else:
hdlr = logging.FileHandler(config.get("Logging", "File"))
hdlr.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s'))

logger.addHandler(hdlr)
logger.setLevel(logverbosity.upper())

# werkzeug logging config
log = logging.getLogger('werkzeug')
log.setLevel(logging.CRITICAL)

try:
urlpath = config.get("General", "Urlpath")
except:
Expand Down

0 comments on commit 201cbc0

Please sign in to comment.