Merge lp:~facundo/magicicada-server/better-settings-local into lp:magicicada-server

Proposed by Facundo Batista
Status: Merged
Approved by: Natalia Bidart
Approved revision: 84
Merged at revision: 83
Proposed branch: lp:~facundo/magicicada-server/better-settings-local
Merge into: lp:magicicada-server
Diff against target: 42 lines (+6/-6)
1 file modified
magicicada/settings/__init__.py (+6/-6)
To merge this branch: bzr merge lp:~facundo/magicicada-server/better-settings-local
Reviewer Review Type Date Requested Status
Natalia Bidart Approve
Review via email: mp+323667@code.launchpad.net

Commit message

Better handling of broken local settings, and allow changing values.

Description of the change

Better handling of broken local settings, and allow changing values.

IOW, I converted the simple "import local and pass if broken" to the following sequence:

- try to import * from local settings

- if broken, inform how!

- if all went ok, also try to import a pre-defined function

- if the function is not there, just pass (it's ok, this new function is optional)

- if the function is there, execute it.

The idea of this new function is to allow the local settings to *modify* a generic settings (not only overwrite it). For an example of how this would be useful, check what I'm doing in my local settings: http://linkode.org/RRo7cFNKgY95YeZyP4b3r6

To post a comment you must log in.
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Hum, I really really don't like the fix_settings function. But if you feel very strong about it, could you please at least call it "override_settings"?

For needs like this, what I would propose is using a more "traditional" approach with env vars. Something like:

* in magicicada/settings/__init__.py:

    173 LOGGING = {
    ...
    204 'loggers': {
    205 'django': {
    206 'handlers': ['file'],
    207 'level': os.getenv('MAGICICADA_LOG_LEVEL', 'INFO'),
    208 'propagate': True,
    209 },
    ...
    221 }

And then just export the env var to the value you desire, or execute the server with:

MAGICICADA_LOG_LEVEL=DEBUG make start

Or alternatively, we could define a "debug" policy, a little big more "global", such as this:

LOG_LEVEL = 'INFO' if bool(os.getenv('MAGICICADA_DEBUG', None)) else 'DEBUG'
    173 LOGGING = {
    ...
    204 'loggers': {
    205 'django': {
    206 'handlers': ['file'],
    207 'level': LOG_LEVEL,
    208 'propagate': True,
    209 },
    ...
    221 }

What do you think?

84. By Facundo Batista

Better log level setting.

Revision history for this message
Facundo Batista (facundo) wrote :

Fixed as suggested

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'magicicada/settings/__init__.py'
--- magicicada/settings/__init__.py 2017-04-22 21:07:36 +0000
+++ magicicada/settings/__init__.py 2017-06-28 01:37:23 +0000
@@ -1,5 +1,5 @@
1# Copyright 2008-2015 Canonical1# Copyright 2008-2015 Canonical
2# Copyright 2015-2016 Chicharreros (https://launchpad.net/~chicharreros)2# Copyright 2015-2017 Chicharreros (https://launchpad.net/~chicharreros)
3#3#
4# This program is free software: you can redistribute it and/or modify4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU Affero General Public License as5# it under the terms of the GNU Affero General Public License as
@@ -27,7 +27,7 @@
27https://docs.djangoproject.com/en/1.8/ref/settings/27https://docs.djangoproject.com/en/1.8/ref/settings/
28"""28"""
2929
30from __future__ import unicode_literals30from __future__ import unicode_literals, print_function
3131
32# Build paths inside the project like this: os.path.join(BASE_DIR, ...)32# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
33import logging33import logging
@@ -204,12 +204,12 @@
204 'loggers': {204 'loggers': {
205 'django': {205 'django': {
206 'handlers': ['file'],206 'handlers': ['file'],
207 'level': 'INFO',207 'level': os.getenv('MAGICICADA_LOG_LEVEL', 'INFO'),
208 'propagate': True,208 'propagate': True,
209 },209 },
210 'magicicada.server': {210 'magicicada.server': {
211 'handlers': ['server'],211 'handlers': ['server'],
212 'level': 'DEBUG',212 'level': os.getenv('MAGICICADA_LOG_LEVEL', 'DEBUG'),
213 'propagate': False,213 'propagate': False,
214 },214 },
215 'magicicada.metrics': {215 'magicicada.metrics': {
@@ -263,5 +263,5 @@
263263
264try:264try:
265 from magicicada.settings.local import * # noqa265 from magicicada.settings.local import * # noqa
266except ImportError:266except ImportError as err:
267 pass267 print("ERROR importing local settings:", err)

Subscribers

People subscribed via source and target branches

to all changes: