代码拉取完成,页面将自动刷新
同步操作将从 sincher/flask-blog 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
# coding=utf-8
# from flask import Flask
# from redis import StrictRedis
from werkzeug.routing import BaseConverter
import os
import sys
from flask_session import Session
BASE_DIR=os.path.dirname(os.path.abspath(__file__))
class HTMLConverter(BaseConverter):
regex = '.*'
# 路由正则
class RegexConverter(BaseConverter):
def __init__(self, url_map, *items):
super(RegexConverter, self).__init__(url_map)
self.regex = items[0]
#log配置,实现日志自动按日期生成日志文件
def make_log():
import logging
from logging.handlers import RotatingFileHandler
import time
from configparser import ConfigParser
cfg = ConfigParser()
cfg.read('config/config.ini', encoding='utf-8')
make_dir_path = cfg.get('log','path')
path = make_dir_path.strip()
if not os.path.exists(path):
os.makedirs(path)
log_file_name = 'logger-' + time.strftime('%Y-%m-%d', time.localtime(time.time())) + '.log'
log_file_folder = path + os.sep + log_file_name
# log_file_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) + os.sep + log_dir_name
# make_dir(log_file_folder)
logging.basicConfig(level=logging.DEBUG)
# log_file_str = log_file_folder + os.sep + log_file_name
# log_level = logging.DEBUG
handler = RotatingFileHandler(os.path.join(BASE_DIR, log_file_folder), maxBytes=1024 * 1024 * 100,backupCount=10)
# handler = logging.FileHandler(log_file_str, encoding='UTF-8')
logging_format = logging.Formatter(
'%(asctime)s - %(levelname)s - %(filename)s - %(funcName)s - %(lineno)s - %(message)s')
handler.setFormatter(logging_format)
logging.getLogger().addHandler(handler)
def console_out(logFilename):
''' Output log to file and console '''
# Define a Handler and set a format which output to file
import logging
from logging.handlers import RotatingFileHandler
# logging.basicConfig(
# level = logging.DEBUG, # 定义输出到文件的log级别,
# format = '%(asctime)s %(filename)s : %(levelname)s %(message)s', # 定义输出log的格式
# datefmt = '%Y-%m-%d %A %H:%M:%S', # 时间
# filename = logFilename, # log文件名
# filemode = 'w') # 写入模式“w”或“a”
# Define a Handler and set a format which output to console
logging.basicConfig(level=logging.DEBUG)
console = RotatingFileHandler(os.path.join(BASE_DIR, logFilename), maxBytes=1024 * 1024 * 100,backupCount=10)
# console = logging.StreamHandler() # 定义console handler
# console.setLevel(logging.INFO) # 定义该handler级别
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(filename)s - %(funcName)s - %(lineno)s - %(message)s') #定义该handler格式
console.setFormatter(formatter)
# Create an instance
logging.getLogger().addHandler(console) # 实例化添加handler
def create_app(app,config):
# app=Flask(__name__)
app.config.from_object(config)
app.url_map.converters['html']=HTMLConverter
app.url_map.converters['regex'] = RegexConverter
#session初始化,将session存储到redis中
# Session(app)
# 创建redis存储对象
# redis_store = StrictRedis(host=config.REDIS_HOST, port=config.REDIS_PORT)
# app.redis = redis_store
# 日志处理
# import logging
# from logging.handlers import RotatingFileHandler
# logging.basicConfig(level=logging.DEBUG)
# file_log_handler = RotatingFileHandler(os.path.join(BASE_DIR, "logs/myblog.log"), maxBytes=1024 * 1024 * 100,backupCount=10)
# formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(filename)s - %(funcName)s - %(lineno)s - %(message)s')
# file_log_handler.setFormatter(formatter)
# logging.getLogger().addHandler(file_log_handler)
# console_out('logs/logging.log')
make_log()
return app
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。