separated spotframework from web front, centralized logging init

This commit is contained in:
aj 2019-09-05 12:20:21 +01:00
parent ad9c40ea27
commit 20090d14b5
7 changed files with 43 additions and 44 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
env venv
__pycache__ __pycache__
*.csv *.csv
.idea .idea

View File

@ -10,14 +10,22 @@ import logging
logger = logging.getLogger('spotframework') logger = logging.getLogger('spotframework')
log_format = '%(asctime)s %(levelname)s %(name)s:%(funcName)s - %(message)s' file_log_format = '%(asctime)s %(levelname)s %(name)s:%(funcName)s - %(message)s'
file_handler = logging.FileHandler(".spot/alarm.log") file_handler = logging.FileHandler(".spot/alarm.log")
formatter = logging.Formatter(log_format) file_formatter = logging.Formatter(file_log_format)
file_handler.setFormatter(formatter) file_handler.setFormatter(file_formatter)
logger.addHandler(file_handler) logger.addHandler(file_handler)
stream_log_format = '%(levelname)s %(name)s:%(funcName)s - %(message)s'
stream_formatter = logging.Formatter(stream_log_format)
stream_handler = logging.StreamHandler()
stream_handler.setFormatter(stream_formatter)
logger.addHandler(stream_handler)
def check_phone(): def check_phone():

View File

@ -19,6 +19,14 @@ if __name__ == '__main__':
logger.addHandler(file_handler) logger.addHandler(file_handler)
stream_log_format = '%(levelname)s %(name)s:%(funcName)s - %(message)s'
stream_formatter = logging.Formatter(stream_log_format)
stream_handler = logging.StreamHandler()
stream_handler.setFormatter(stream_formatter)
logger.addHandler(stream_handler)
try: try:
network = Network(NetworkUser(os.environ['SPOTCLIENT'], network = Network(NetworkUser(os.environ['SPOTCLIENT'],

View File

@ -5,7 +5,7 @@ import spotframework.io.json as json
import spotframework.util.monthstrings as monthstrings import spotframework.util.monthstrings as monthstrings
from spotframework.engine.playlistengine import PlaylistEngine from spotframework.engine.playlistengine import PlaylistEngine
from spotframework.engine.filter.shuffle import Shuffle from spotframework.engine.filter.shuffle import Shuffle
from spotframework.engine.filter.sort import SortReverseReleaseDate from spotframework.engine.filter.sort import SortReleaseDate
from spotframework.engine.filter.deduplicate import DeduplicateByID, DeduplicateByName from spotframework.engine.filter.deduplicate import DeduplicateByID, DeduplicateByName
import os import os
@ -26,6 +26,14 @@ file_handler.setFormatter(formatter)
logger.addHandler(file_handler) logger.addHandler(file_handler)
stream_log_format = '%(levelname)s %(name)s:%(funcName)s - %(message)s'
stream_formatter = logging.Formatter(stream_log_format)
stream_handler = logging.StreamHandler()
stream_handler.setFormatter(stream_formatter)
logger.addHandler(stream_handler)
def update_super_playlist(engine, data_dict): def update_super_playlist(engine, data_dict):
@ -37,9 +45,9 @@ def update_super_playlist(engine, data_dict):
if data_dict['shuffle'] is True: if data_dict['shuffle'] is True:
processors.append(Shuffle()) processors.append(Shuffle())
else: else:
processors.append(SortReverseReleaseDate()) processors.append(SortReleaseDate(reverse=True))
else: else:
processors.append(SortReverseReleaseDate()) processors.append(SortReleaseDate(reverse=True))
tracks = engine.make_playlist(data_dict['playlists'], processors) tracks = engine.make_playlist(data_dict['playlists'], processors)
@ -72,7 +80,7 @@ def update_recents_playlist(engine, data):
for exclusion in data['recents']['exclude']: for exclusion in data['recents']['exclude']:
recent_parts.remove(exclusion) recent_parts.remove(exclusion)
processors = [DeduplicateByName(), SortReverseReleaseDate()] processors = [DeduplicateByName(), SortReleaseDate(reverse=True)]
recent_tracks = engine.get_recent_playlist(boundary_date, recent_parts, processors) recent_tracks = engine.get_recent_playlist(boundary_date, recent_parts, processors)
engine.execute_playlist(recent_tracks, recents_id) engine.execute_playlist(recent_tracks, recents_id)

View File

@ -2,6 +2,16 @@ from spotframework.net.user import NetworkUser
from spotframework.net.network import Network from spotframework.net.network import Network
import os import os
import logging
logger = logging.getLogger('spotframework')
stream_log_format = '%(levelname)s %(name)s:%(funcName)s - %(message)s'
stream_formatter = logging.Formatter(stream_log_format)
stream_handler = logging.StreamHandler()
stream_handler.setFormatter(stream_formatter)
logger.addHandler(stream_handler)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -1,19 +1,6 @@
cachetools==3.1.1
certifi==2019.6.16 certifi==2019.6.16
chardet==3.0.4 chardet==3.0.4
google-api-core==1.14.2
google-auth==1.6.3
google-cloud-core==1.0.3
google-cloud-firestore==1.4.0
google-cloud-logging==1.12.1
googleapis-common-protos==1.6.0
grpcio==1.22.0
idna==2.8 idna==2.8
protobuf==3.9.1
pyasn1==0.4.6
pyasn1-modules==0.2.6
pytz==2019.2
requests==2.22.0 requests==2.22.0
rsa==4.0 tabulate==0.8.3
six==1.12.0
urllib3==1.25.3 urllib3==1.25.3

View File

@ -1,26 +1,4 @@
import logging import logging
import os
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logger.setLevel('DEBUG') logger.setLevel('DEBUG')
if os.environ.get('DEPLOY_DESTINATION', None) == 'PROD':
from google.cloud import logging as glogging
log_format = '%(funcName)s - %(message)s'
formatter = logging.Formatter(log_format)
client = glogging.Client()
handler = client.get_default_handler()
handler.setFormatter(formatter)
logger.addHandler(handler)
else:
log_format = '%(levelname)s %(name)s:%(funcName)s - %(message)s'
formatter = logging.Formatter(log_format)
stream_handler = logging.StreamHandler()
stream_handler.setFormatter(formatter)
logger.addHandler(stream_handler)