Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
00c9a6d5
Commit
00c9a6d5
authored
Feb 08, 2012
by
Antony Chazapis
Browse files
Change logging mechanism.
Refs #2016
parent
fba1c49d
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
astakos/lib/dictconfig.py
0 → 100644
View file @
00c9a6d5
This diff is collapsed.
Click to expand it.
astakos/middleware/log.py
View file @
00c9a6d5
...
...
@@ -34,17 +34,31 @@
from
django.conf
import
settings
from
django.core.exceptions
import
MiddlewareNotUsed
from
astakos.lib.dictconfig
import
dictConfig
import
logging
class
NullHandler
(
logging
.
Handler
):
def
emit
(
self
,
record
):
pass
class
LoggingConfigMiddleware
:
def
__init__
(
self
):
'''Initialise the logging setup from settings, called on first request.'''
args
=
{}
args
[
'level'
]
=
logging
.
DEBUG
if
getattr
(
settings
,
'DEBUG'
,
False
)
else
logging
.
INFO
if
settings
.
LOGFILE
:
args
[
'filename'
]
=
settings
.
LOGFILE
args
[
'format'
]
=
'%(asctime)s [%(levelname)s] %(name)s %(message)s'
args
[
'datefmt'
]
=
'%Y-%m-%d %H:%M:%S'
logging
.
basicConfig
(
**
args
)
logging_setting
=
getattr
(
settings
,
'LOGGING_SETUP'
,
None
)
if
logging_setting
:
# Disable handlers that are not used by any logger.
active_handlers
=
set
()
loggers
=
logging_setting
.
get
(
'loggers'
,
{})
for
logger
in
loggers
.
values
():
active_handlers
.
update
(
logger
.
get
(
'handlers'
,
[]))
handlers
=
logging_setting
.
get
(
'handlers'
,
{})
for
handler
in
handlers
:
if
handler
not
in
active_handlers
:
handlers
[
handler
]
=
{
'class'
:
'logging.NullHandler'
}
logging
.
NullHandler
=
NullHandler
dictConfig
(
logging_setting
)
raise
MiddlewareNotUsed
(
'Logging setup only.'
)
astakos/settings.py
View file @
00c9a6d5
...
...
@@ -100,8 +100,34 @@ AUTHENTICATION_BACKENDS = ('astakos.im.auth_backends.EmailBackend',
CUSTOM_USER_MODEL
=
'astakos.im.AstakosUser'
# Use to log to a file.
LOGFILE
=
None
# Setup logging (use this name for the setting to avoid conflicts with django > 1.2.x).
LOGGING_SETUP
=
{
'version'
:
1
,
'disable_existing_loggers'
:
True
,
'formatters'
:
{
'simple'
:
{
'format'
:
'%(message)s'
},
'verbose'
:
{
'format'
:
'%(asctime)s [%(levelname)s] %(name)s %(message)s'
},
},
'handlers'
:
{
'null'
:
{
'class'
:
'logging.NullHandler'
,
},
'console'
:
{
'class'
:
'logging.StreamHandler'
,
'formatter'
:
'verbose'
},
},
'loggers'
:
{
'astakos'
:
{
'handlers'
:
[
'console'
],
'level'
:
'DEBUG'
if
DEBUG
else
'INFO'
},
}
}
# The server is behind a proxy (apache and gunicorn setup).
USE_X_FORWARDED_HOST
=
False
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment