Esempio n. 1
0
def inject_logging(quiet):
    """Injects logging"""
    null_handler = NullHandler(level='DEBUG')
    null_handler.push_application()  # Discard any message lesser than INFO
    log_handler = MonitoringFileHandler(os.path.join(LOG_DIR, 'thekraken.log'),
                                        level='INFO')
    log_handler.push_application()
    if not quiet:
        console_handler = StreamHandler(sys.stdout, level='DEBUG', bubble=True)
        console_handler.push_application()
    def main(self):
        logbook.set_datetime_format("local")
        StreamHandler(sys.stdout,
                      level=self.config["loglevel"]).push_application()
        MonitoringFileHandler(
            self.config["logpath"],
            mode='a',
            encoding='utf-8',
            bubble=True,
            level=self.config["loglevel"]).push_application()
        self.logger = Logger('monitord_socket.py')

        self.logger.info("starting...")
        connectionErrorCount = 0
        while True:
            self.logger.info('Connection to {}:{}'.format(
                self.config["host"], self.config["port"]))
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            try:
                s.connect((self.config["host"], self.config["port"]))
            except:
                connectionErrorCount += 1
                self.reportConnectionError(connectionErrorCount)
                time.sleep(10)
                continue
            connectionErrorCount = 0
            try:
                while True:
                    data = s.recv(1024)
                    if data:
                        self.logger.debug('Received => ' + repr(data))
                        self.startNewDataThread(data.decode('ascii'))
                    else:
                        self.logger.warning('Connection lost! Restarting...')
                        break
            except KeyboardInterrupt:
                print("\nShutting down...")
                self.logger.warning('Shutting down...')
                exit()
            s.close()
            time.sleep(5)
Esempio n. 3
0
"""Repo sync module"""
import os
from subprocess import Popen, PIPE
from logbook import Logger, MonitoringFileHandler

import sys
path = os.path.dirname(os.path.dirname(
    os.path.abspath(os.path.dirname(__file__).replace('\\', '/'))))
sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'kitchen.settings'

from kitchen.settings import (REPO, REPO_BASE_PATH, SYNCDATE_FILE, LOG_FILE,
                              DEBUG)
from kitchen.backends import lchef as chef

file_log_handler = MonitoringFileHandler(LOG_FILE, bubble=DEBUG)
file_log_handler.push_application()
log = Logger("kitchen.backends.sync")


class SyncRepo():
    """A Task that syncs the git kitchen repository"""
    REPO_ROOT = os.path.join(REPO_BASE_PATH, REPO['NAME'])

    def run(self):
        """Syncs the git repository"""
        log.debug("Synching repo")
        if os.path.exists(self.REPO_ROOT):
            self._update()
        else:
            self._clone()
Esempio n. 4
0
# -*- coding: UTF-8 -*-
from flask import Flask
from flask.ext.login import LoginManager
from logbook import MonitoringFileHandler, NullHandler

from sayit.settings import DEBUG, LOG_FILE, SECRET_KEY


# Set up logs
if DEBUG:
    LEVEL = 'DEBUG'
else:
    LEVEL = 'INFO'
    null_handler = NullHandler()
    null_handler.push_application()

log_handler = MonitoringFileHandler(LOG_FILE, level=LEVEL)
log_handler.push_application()

app = Flask(__name__)
app.config['SECRET_KEY'] = SECRET_KEY

login_manager = LoginManager()
login_manager.setup_app(app)
login_manager.login_view = "login"
login_manager.refresh_view = "reauth"

import views