feat(logs): formatte joliement la sortie

master
François Poulain 2 years ago
parent cb563ffca5
commit 08cc965af4
  1. 12
      drupal2spip_lal/base/convert.py
  2. 57
      drupal2spip_lal/settings/base.py
  3. 51
      drupal2spip_lal/settings/production.py
  4. 4
      requirements/base.txt

@ -1,3 +1,4 @@
import logging
import os
import re
from datetime import datetime
@ -20,6 +21,9 @@ from drupal2spip_lal.spip import models as spip
# - convertir en format SPIP ?
logger = logging.getLogger('drupal2spip_lal')
def convert_timestamp(timestamp):
return make_aware(datetime.fromtimestamp(timestamp))
@ -159,14 +163,18 @@ def convert_node(node, options):
]
spip.Urls.objects.bulk_create(urls)
print('Article {} created from node {}.'.format(article.pk, node.pk))
logger.info(
'Article {} created from node {}.'.format(article.pk, node.pk)
)
elif update:
article = spip.Articles(
pk=spip_urls.last().id_objet, **article_attributes
)
article.save()
print('Article {} updated from node {}.'.format(article.pk, node.pk))
logger.info(
'Article {} updated from node {}.'.format(article.pk, node.pk)
)
if article:
user_attributes = {

@ -248,6 +248,63 @@ SESSION_COOKIE_PATH = APP_LOCATION
# https://docs.djangoproject.com/en/stable/ref/settings/#csrf-cookie-path
CSRF_COOKIE_PATH = APP_LOCATION
# LOGGING
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/stable/topics/logging/
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '%(asctime)s - %(levelname)s - %(module)s: %(message)s',
},
'colored': {
'()': 'colorlog.ColoredFormatter',
'format': (
'%(log_color)s%(asctime)s - '
'%(levelname)s - %(name)s: %(message)s'
),
'log_colors': {
'DEBUG': 'bold_cyan',
'INFO': 'green',
'WARNING': 'yellow',
'ERROR': 'red',
'CRITICAL': 'bold_red',
},
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'colored',
},
'file': {
'level': 'INFO',
'class': 'logging.handlers.TimedRotatingFileHandler',
'filename': var_dir('log/drupal2spip_lal.log'),
'formatter': 'verbose',
'when': 'midnight',
'interval': 1,
'backupCount': 30,
},
},
'loggers': {
'django': {
'level': 'WARNING',
'handlers': ['file', 'console'],
'propagate': True,
},
'drupal2spip_lal': {
'level': 'DEBUG',
'handlers': ['file', 'console'],
'propagate': True,
},
},
}
if not os.path.isdir(var_dir('log')):
os.mkdir(var_dir('log'), mode=0o750)
# ------------------------------------------------------------------------------
# APPLICATION AND 3RD PARTY LIBRARY SETTINGS
# ------------------------------------------------------------------------------

@ -6,12 +6,10 @@ Production settings.
- load secret key from environment variables
- set other production configurations
"""
import os
from django.core.exceptions import ImproperlyConfigured
from .base import * # noqa
from .base import TEMPLATES, env, var_dir
from .base import TEMPLATES, env
# CONFIGURATION VALIDATION
# ------------------------------------------------------------------------------
@ -54,53 +52,6 @@ TEMPLATES[0]['OPTIONS']['loaders'] = [
)
]
# LOGGING
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/stable/topics/logging/
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '%(asctime)s - %(levelname)s - %(module)s: %(message)s'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler',
},
'file': {
'level': 'DEBUG',
'class': 'logging.handlers.TimedRotatingFileHandler',
'filename': var_dir('log/drupal2spip_lal.log'),
'formatter': 'verbose',
'when': 'midnight',
'interval': 1,
'backupCount': 30,
},
},
'loggers': {
'django': {
'level': 'WARNING',
'handlers': ['file'],
'propagate': True,
},
'django.request': {
'level': 'WARNING',
'handlers': ['file', 'mail_admins'],
'propagate': True,
},
'drupal2spip_lal': {
'level': 'INFO',
'handlers': ['file', 'mail_admins'],
'propagate': True,
},
},
}
if not os.path.isdir(var_dir('log')):
os.mkdir(var_dir('log'), mode=0o750)
# ------------------------------------------------------------------------------
# APPLICATION AND 3RD PARTY LIBRARY SETTINGS
# ------------------------------------------------------------------------------

@ -11,3 +11,7 @@ phpserialize
# ------------------------------------------------------------------------------
request
beautifulsoup4
# Logs
# ------------------------------------------------------------------------------
colorlog

Loading…
Cancel
Save