Skip to content

Commit 99fac03

Browse files
committed
updates configs
1 parent 41d50e5 commit 99fac03

File tree

3 files changed

+31
-36
lines changed

3 files changed

+31
-36
lines changed

app/utils/logging.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
logger_formatter = logging.Formatter(log_fmt)
2828

2929
# Sets up rotating file handler for file output
30-
file_logger = RotatingFileHandler(log_file_path, maxBytes=1024*1024*10,
31-
backupCount=5)
30+
file_logger = RotatingFileHandler(log_file_path, maxBytes=1024*1024*10,backupCount=5)
3231
file_logger.setLevel(logging.DEBUG)
3332
file_logger.setFormatter(logger_formatter)
3433

config.py

+29-33
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,7 @@
77
import logging
88

99

10-
class Config:
11-
# API configurations
12-
SECRET_KEY = env_conf("SECRET_KEY")
13-
# Database configurations
14-
SQLALCHEMY_TRACK_MODIFICATIONS = False
15-
SQLALCHEMY_RECORD_QUERIES = True
16-
17-
@staticmethod
18-
def init_app(app):
19-
pass
20-
21-
22-
class LocalPSQLConfig(Config):
10+
class LocalPSQLConfig:
2311
# To initate the local config. Basically adds bunch of logger handlers with
2412
# a postgre sql setup
2513

@@ -31,9 +19,13 @@ class LocalPSQLConfig(Config):
3119
SQLALCHEMY_DATABASE_URI = 'postgresql+psycopg2://{}:{}@{}:{}/{}'.\
3220
format(DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME)
3321

22+
SQLALCHEMY_TRACK_MODIFICATIONS = False
23+
SQLALCHEMY_RECORD_QUERIES = True
24+
25+
SECRET_KEY = env_conf("SECRET_KEY", cast=str, default="12345")
26+
3427
@classmethod
3528
def init_app(cls, app):
36-
Config.init_app(app)
3729
# The default Flask logger level is set at ERROR, so if you want to see
3830
# INFO level or DEBUG level logs, you need to lower the main loggers
3931
# level first.
@@ -42,31 +34,35 @@ def init_app(cls, app):
4234
app.logger.addHandler(client_logger)
4335

4436

45-
class DockerPSQLConfig(Config):
46-
# To initate the docker config. Basically adds bunch of logger handlers and
47-
# sets the database host configurations to run with the docker setup.
48-
DB_USER = 'deploy'
49-
DB_PASSWORD = 'docker'
50-
DB_HOST = 'db'
51-
DB_PORT = 5432
52-
DB_NAME = 'ftemplate'
53-
SQLALCHEMY_DATABASE_URI = 'postgresql+psycopg2://{}:{}@{}:{}/{}'.\
54-
format(DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME)
37+
class Develop:
38+
"""Development config geared towards docker."""
39+
# Database configurations
40+
DB_USER = "deploy"
41+
DB_PASSWORD = "docker"
42+
DB_HOST = "db"
43+
DB_PORT = "5432"
44+
DB_NAME = "stories"
45+
SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://{}:{}@{}:{}/{}".format(
46+
DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME)
5547

56-
@classmethod
57-
def init_app(cls, app):
58-
Config.init_app(app)
59-
# The default Flask logger level is set at ERROR, so if you want to see
60-
# INFO level or DEBUG level logs, you need to lower the main loggers
61-
# level first.
48+
SQLALCHEMY_TRACK_MODIFICATIONS = False
49+
SQLALCHEMY_RECORD_QUERIES = True
50+
51+
# DEBUG = True
52+
# API configurations
53+
SECRET_KEY = env_conf("SECRET_KEY", cast=str, default="12345")
54+
55+
@staticmethod
56+
def init_app(app):
57+
"""Initiates application."""
6258
app.logger.setLevel(logging.DEBUG)
63-
app.logger.addHandler(file_logger)
6459
app.logger.addHandler(client_logger)
60+
app.logger.addHandler(file_logger)
6561

6662

6763
# Create a config dictionary which is used while initiating the application.
6864
# Config that is going to be used will be specified in the .env file
6965
config_dict = {
70-
'local': LocalPSQLConfig,
71-
'docker': DockerPSQLConfig,
66+
'localpsql': LocalPSQLConfig,
67+
'develop': Develop,
7268
}

stories.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# Config to be used is read from the .env file, and then used for initiaing the
1010
# application with the preconfigured create_app method.
11-
env_config = config('ENV', cast=str)
11+
env_config = config("ENV", cast=str, default="develop")
1212

1313
app = create_app(env_config)
1414
migrate = Migrate(app, db)

0 commit comments

Comments
 (0)