mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-16 15:19:06 +00:00
format log (#7441)
* format log * update * optimize --------- Co-authored-by: 孙永强 <11704063+s-yongqiang@user.noreply.gitee.com>
This commit is contained in:
@@ -24,8 +24,7 @@ from seahub.utils import (get_site_name, get_user_activities_by_timestamp,
|
|||||||
from seahub.utils.timeutils import utc_to_local
|
from seahub.utils.timeutils import utc_to_local
|
||||||
|
|
||||||
# Get an instance of a logger
|
# Get an instance of a logger
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger('file_updates_sender')
|
||||||
|
|
||||||
|
|
||||||
# Utility Functions
|
# Utility Functions
|
||||||
def td(con):
|
def td(con):
|
||||||
@@ -65,10 +64,11 @@ class Command(BaseCommand):
|
|||||||
label = "notifications_send_file_updates"
|
label = "notifications_send_file_updates"
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
logger.debug('Start sending file updates emails...')
|
logger.info('Start sending file updates emails...')
|
||||||
|
|
||||||
self.stdout.write('[%s] Start sending file updates emails...' % str(datetime.now()))
|
self.stdout.write('[%s] Start sending file updates emails...' % str(datetime.now()))
|
||||||
self.do_action()
|
self.do_action()
|
||||||
logger.debug('Finish sending file updates emails.\n')
|
logger.info('Finish sending file updates emails.\n')
|
||||||
self.stdout.write('[%s] Finish sending file updates emails.\n\n' % str(datetime.now()))
|
self.stdout.write('[%s] Finish sending file updates emails.\n\n' % str(datetime.now()))
|
||||||
|
|
||||||
def get_avatar(self, username):
|
def get_avatar(self, username):
|
||||||
@@ -192,7 +192,7 @@ class Command(BaseCommand):
|
|||||||
emails.append(ele.email)
|
emails.append(ele.email)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
self.stderr.write('[%s]: %s' % (str(datetime.now()), e))
|
self.stderr.write('[%s] [INFO]: %s' % (str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')), e))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
user_last_emailed_time_dict = {}
|
user_last_emailed_time_dict = {}
|
||||||
@@ -204,7 +204,7 @@ class Command(BaseCommand):
|
|||||||
ele.option_val, "%Y-%m-%d %H:%M:%S")
|
ele.option_val, "%Y-%m-%d %H:%M:%S")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
self.stderr.write('[%s]: %s' % (str(datetime.now()), e))
|
self.stderr.write('[%s] [ERROR]: %s' % (str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')), e))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for (username, interval_val) in user_file_updates_email_intervals:
|
for (username, interval_val) in user_file_updates_email_intervals:
|
||||||
@@ -214,10 +214,11 @@ class Command(BaseCommand):
|
|||||||
# get and active user language
|
# get and active user language
|
||||||
user_language = self.get_user_language(username)
|
user_language = self.get_user_language(username)
|
||||||
translation.activate(user_language)
|
translation.activate(user_language)
|
||||||
logger.debug('Set language code to %s for user: %s' % (
|
logger.info('Set language code to %s for user: %s' % (
|
||||||
user_language, username))
|
user_language, username))
|
||||||
self.stdout.write('[%s] Set language code to %s for user: %s' % (
|
|
||||||
str(datetime.now()), user_language, username))
|
self.stdout.write('[%s] [INFO] Set language code to %s for user: %s' % (
|
||||||
|
str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')), user_language, username))
|
||||||
|
|
||||||
# get last_emailed_time if any, defaults to today 00:00:00
|
# get last_emailed_time if any, defaults to today 00:00:00
|
||||||
last_emailed_time = user_last_emailed_time_dict.get(username, None)
|
last_emailed_time = user_last_emailed_time_dict.get(username, None)
|
||||||
@@ -255,13 +256,14 @@ class Command(BaseCommand):
|
|||||||
ele.op_user_link = a_tag(email2nickname(ele.op_user),
|
ele.op_user_link = a_tag(email2nickname(ele.op_user),
|
||||||
user_info_url(ele.op_user))
|
user_info_url(ele.op_user))
|
||||||
ele.operation, ele.op_details = self.format_file_operation(ele)
|
ele.operation, ele.op_details = self.format_file_operation(ele)
|
||||||
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('Failed to format mail content for user: %s' %
|
logger.error('Failed to format mail content for user: %s' %
|
||||||
username)
|
username)
|
||||||
logger.error(e, exc_info=True)
|
logger.error(e, exc_info=True)
|
||||||
self.stderr.write('[%s] Failed to format mail content for user: %s' %
|
self.stderr.write('[%s] [ERROR] Failed to format mail content for user: %s' %
|
||||||
(str(datetime.now()), username))
|
(str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')), username))
|
||||||
self.stderr.write('[%s]: %s' % (str(datetime.now()), e))
|
self.stderr.write('[%s] [ERROR]: %s' % (str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')), e))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
nickname = email2nickname(username)
|
nickname = email2nickname(username)
|
||||||
@@ -279,13 +281,13 @@ class Command(BaseCommand):
|
|||||||
None, [contact_email])
|
None, [contact_email])
|
||||||
# set new last_emailed_time
|
# set new last_emailed_time
|
||||||
UserOptions.objects.set_file_updates_last_emailed_time(username, now)
|
UserOptions.objects.set_file_updates_last_emailed_time(username, now)
|
||||||
self.stdout.write('[%s] Successful to send email to %s' %
|
self.stdout.write('[%s] [INFO] Successful to send email to %s' %
|
||||||
(str(datetime.now()), contact_email))
|
(str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')), contact_email))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('Failed to send email to %s, error detail: %s' %
|
logger.error('Failed to send email to %s, error detail: %s' %
|
||||||
(contact_email, e))
|
(contact_email, e))
|
||||||
self.stderr.write('[%s] Failed to send email to %s, error '
|
self.stderr.write('[%s] [ERROR] Failed to send email to %s, error '
|
||||||
'detail: %s' % (str(datetime.now()), contact_email, e))
|
'detail: %s' % (str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')), contact_email, e))
|
||||||
finally:
|
finally:
|
||||||
# reset lang
|
# reset lang
|
||||||
translation.activate(cur_language)
|
translation.activate(cur_language)
|
||||||
|
@@ -31,8 +31,7 @@ from seahub.notifications.utils import gen_sdoc_smart_link
|
|||||||
from seahub.utils.auth import VIRTUAL_ID_EMAIL_DOMAIN
|
from seahub.utils.auth import VIRTUAL_ID_EMAIL_DOMAIN
|
||||||
|
|
||||||
# Get an instance of a logger
|
# Get an instance of a logger
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger('seahub_email_sender')
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = 'Send Email notifications to user if he/she has an unread notices every period of seconds .'
|
help = 'Send Email notifications to user if he/she has an unread notices every period of seconds .'
|
||||||
@@ -377,10 +376,10 @@ class Command(BaseCommand):
|
|||||||
# get and active user language
|
# get and active user language
|
||||||
user_language = self.get_user_language(to_user)
|
user_language = self.get_user_language(to_user)
|
||||||
translation.activate(user_language)
|
translation.activate(user_language)
|
||||||
logger.debug('Set language code to %s for user: %s' % (
|
logger.info('Set language code to %s for user: %s' % (
|
||||||
user_language, to_user))
|
user_language, to_user))
|
||||||
self.stdout.write('[%s] Set language code to %s for user: %s' % (
|
self.stdout.write('[%s] [INFO] Set language code to %s for user: %s' % (
|
||||||
str(datetime.datetime.now()), user_language, to_user))
|
str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')), user_language, to_user))
|
||||||
|
|
||||||
# format mail content and send
|
# format mail content and send
|
||||||
notices = []
|
notices = []
|
||||||
@@ -465,10 +464,10 @@ class Command(BaseCommand):
|
|||||||
# set new last_emailed_time
|
# set new last_emailed_time
|
||||||
UserOptions.objects.set_collaborate_last_emailed_time(to_user, now)
|
UserOptions.objects.set_collaborate_last_emailed_time(to_user, now)
|
||||||
logger.info('Successfully sent email to %s' % contact_email)
|
logger.info('Successfully sent email to %s' % contact_email)
|
||||||
self.stdout.write('[%s] Successfully sent email to %s' % (str(datetime.datetime.now()), contact_email))
|
self.stdout.write('[%s] [INFO] Successfully sent email to %s' % (str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')), contact_email))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('Failed to send email to %s, error detail: %s' % (contact_email, e))
|
logger.error('Failed to send email to %s, error detail: %s' % (contact_email, e))
|
||||||
self.stderr.write('[%s] Failed to send email to %s, error detail: %s' % (str(datetime.datetime.now()), contact_email, e))
|
self.stderr.write('[%s] [ERROR] Failed to send email to %s, error detail: %s' % (str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')), contact_email, e))
|
||||||
|
|
||||||
# restore current language
|
# restore current language
|
||||||
translation.activate(cur_language)
|
translation.activate(cur_language)
|
||||||
|
@@ -694,6 +694,20 @@ if seafile_log_to_stdout:
|
|||||||
'level': 'ERROR',
|
'level': 'ERROR',
|
||||||
'filters': ['require_debug_false'],
|
'filters': ['require_debug_false'],
|
||||||
'class': 'django.utils.log.AdminEmailHandler'
|
'class': 'django.utils.log.AdminEmailHandler'
|
||||||
|
},
|
||||||
|
'file_updates_sender_handler': {
|
||||||
|
'level': 'INFO',
|
||||||
|
'filters': ['require_debug_true'],
|
||||||
|
'class': 'logging.StreamHandler',
|
||||||
|
'formatter': 'standard',
|
||||||
|
'stream': sys.stdout,
|
||||||
|
},
|
||||||
|
'seahub_email_sender_handler': {
|
||||||
|
'level': 'INFO',
|
||||||
|
'filters': ['require_debug_true'],
|
||||||
|
'class': 'logging.StreamHandler',
|
||||||
|
'formatter': 'standard',
|
||||||
|
'stream': sys.stdout,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'loggers': {
|
'loggers': {
|
||||||
@@ -717,6 +731,16 @@ if seafile_log_to_stdout:
|
|||||||
'level': 'INFO',
|
'level': 'INFO',
|
||||||
'propagate': False
|
'propagate': False
|
||||||
},
|
},
|
||||||
|
'file_updates_sender': {
|
||||||
|
'handlers': ['file_updates_sender_handler', ],
|
||||||
|
'level': 'INFO',
|
||||||
|
'propagate': False
|
||||||
|
},
|
||||||
|
'seahub_email_sender': {
|
||||||
|
'handlers': ['seahub_email_sender_handler', ],
|
||||||
|
'level': 'INFO',
|
||||||
|
'propagate': False
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
@@ -769,6 +793,22 @@ else:
|
|||||||
'level': 'ERROR',
|
'level': 'ERROR',
|
||||||
'filters': ['require_debug_false'],
|
'filters': ['require_debug_false'],
|
||||||
'class': 'django.utils.log.AdminEmailHandler'
|
'class': 'django.utils.log.AdminEmailHandler'
|
||||||
|
},
|
||||||
|
'file_updates_sender_handler': {
|
||||||
|
'level': 'INFO',
|
||||||
|
'class': 'logging.handlers.RotatingFileHandler',
|
||||||
|
'filename': os.path.join(LOG_DIR, 'file_updates_sender.log'),
|
||||||
|
'maxBytes': 1024*1024*100, # 100 MB
|
||||||
|
'backupCount': 5,
|
||||||
|
'formatter': 'standard',
|
||||||
|
},
|
||||||
|
'seahub_email_sender_handler': {
|
||||||
|
'level': 'INFO',
|
||||||
|
'class': 'logging.handlers.RotatingFileHandler',
|
||||||
|
'filename': os.path.join(LOG_DIR, 'seahub_email_sender.log'),
|
||||||
|
'maxBytes': 1024*1024*100, # 100 MB
|
||||||
|
'backupCount': 5,
|
||||||
|
'formatter': 'standard',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'loggers': {
|
'loggers': {
|
||||||
@@ -792,6 +832,16 @@ else:
|
|||||||
'level': 'INFO',
|
'level': 'INFO',
|
||||||
'propagate': False
|
'propagate': False
|
||||||
},
|
},
|
||||||
|
'file_updates_sender': {
|
||||||
|
'handlers': ['file_updates_sender_handler', ],
|
||||||
|
'level': 'INFO',
|
||||||
|
'propagate': False
|
||||||
|
},
|
||||||
|
'seahub_email_sender': {
|
||||||
|
'handlers': ['seahub_email_sender_handler', ],
|
||||||
|
'level': 'INFO',
|
||||||
|
'propagate': False
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user