Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mentat-test
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
713
Mentat
mentat-test
Commits
72b7e4dc
Commit
72b7e4dc
authored
6 years ago
by
Jan Mach
Browse files
Options
Downloads
Patches
Plain Diff
Rewritten and enhanced the Hawat logging setup.
The logging setup is now more capable and configurable. (Redmine issue:
#4216
,
#3443
)
parent
2eab2e88
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
lib/hawat/app.py
+1
-1
1 addition, 1 deletion
lib/hawat/app.py
lib/hawat/config.py
+11
-6
11 additions, 6 deletions
lib/hawat/config.py
lib/hawat/const.py
+8
-0
8 additions, 0 deletions
lib/hawat/const.py
lib/hawat/log.py
+87
-21
87 additions, 21 deletions
lib/hawat/log.py
with
107 additions
and
28 deletions
lib/hawat/app.py
+
1
−
1
View file @
72b7e4dc
...
...
@@ -72,8 +72,8 @@ def _setup_app_logging(app):
:return: Modified Hawat application
:rtype: hawat.base.HawatApp
"""
hawat
.
log
.
setup_logging_default
(
app
)
hawat
.
log
.
setup_logging_file
(
app
)
if
not
app
.
debug
:
hawat
.
log
.
setup_logging_email
(
app
)
...
...
This diff is collapsed.
Click to expand it.
lib/hawat/config.py
+
11
−
6
View file @
72b7e4dc
...
...
@@ -86,6 +86,7 @@ class Config: # pylint: disable=locally-disabled,too-few-public-methods
MAIL_USERNAME
=
None
MAIL_PASSWORD
=
None
MAIL_DEFAULT_SENDER
=
'
mentat@{}
'
.
format
(
socket
.
getfqdn
())
MAIL_SUBJECT_PREFIX
=
'
[MyDojo]
'
# Babel configurations for application localization.
BABEL_DEFAULT_LOCALE
=
hawat
.
const
.
HAWAT_DEFAULT_LOCALE
...
...
@@ -103,12 +104,7 @@ class Config: # pylint: disable=locally-disabled,too-few-public-methods
# Hawat custom configurations.
#
ROLES
=
[
hawat
.
const
.
HAWAT_ROLE_USER
,
hawat
.
const
.
HAWAT_ROLE_DEVELOPER
,
hawat
.
const
.
HAWAT_ROLE_MAINTAINER
,
hawat
.
const
.
HAWAT_ROLE_ADMIN
]
ROLES
=
hawat
.
const
.
HAWAT_ROLES
"""
List of all user roles supported by the Hawat application.
"""
SUPPORTED_LOCALES
=
collections
.
OrderedDict
([(
'
en
'
,
'
English
'
),
(
'
cs
'
,
'
Česky
'
)])
...
...
@@ -215,9 +211,18 @@ class Config: # pylint: disable=locally-disabled,too-few-public-methods
HAWAT_ADMINS
=
[
'
root@{}
'
.
format
(
socket
.
getfqdn
())]
"""
List of system administrator emails.
"""
HAWAT_LOG_DEFAULT_LEVEL
=
'
info
'
"""
Default logging level, case insensitive. One of the values ``DEBUG``, ``INFO``, ``WARNING``, ``ERROR``, ``CRITICAL``.
"""
HAWAT_LOG_FILE
=
'
/var/mentat/log/mentat-hawat.py.log
'
"""
Log file settings for logging framework.
"""
HAWAT_LOG_FILE_LEVEL
=
'
info
'
"""
File logging level, case insensitive. One of the values ``DEBUG``, ``INFO``, ``WARNING``, ``ERROR``, ``CRITICAL``.
"""
HAWAT_LOG_EMAIL_LEVEL
=
'
error
'
"""
File logging level, case insensitive. One of the values ``DEBUG``, ``INFO``, ``WARNING``, ``ERROR``, ``CRITICAL``.
"""
HAWAT_LOCAL_DEVELOPER_LOGIN
=
'
account@local
'
"""
Developer account for local development login.
"""
...
...
This diff is collapsed.
Click to expand it.
lib/hawat/const.py
+
8
−
0
View file @
72b7e4dc
...
...
@@ -56,6 +56,14 @@ HAWAT_ROLE_MAINTAINER = 'maintainer'
HAWAT_ROLE_ADMIN
=
'
admin
'
"""
Name of the
'
admin
'
role.
"""
HAWAT_ROLES
=
[
HAWAT_ROLE_USER
,
HAWAT_ROLE_DEVELOPER
,
HAWAT_ROLE_MAINTAINER
,
HAWAT_ROLE_ADMIN
]
"""
List of valid user roles.
"""
HAWAT_ITEM_ACTION_CREATE
=
'
create
'
"""
Name of the item *create* action.
"""
...
...
This diff is collapsed.
Click to expand it.
lib/hawat/log.py
+
87
−
21
View file @
72b7e4dc
...
...
@@ -9,7 +9,7 @@
"""
This module contains
database access
functions for Hawat.
This module contains
logging
functions for Hawat
application
.
"""
...
...
@@ -18,25 +18,98 @@ __credits__ = "Pavel Kácha <pavel.kacha@cesnet.cz>, Andrea Kropáčová <andrea
import
logging
from
logging.handlers
import
SMTPHandler
,
WatchedFileHandler
from
logging.handlers
import
WatchedFileHandler
,
SMTPHandler
def
setup_logging_default
(
app
):
"""
Setup default application logging features.
"""
log_level_str
=
app
.
config
[
'
HAWAT_LOG_DEFAULT_LEVEL
'
].
upper
()
log_level
=
getattr
(
logging
,
log_level_str
,
None
)
if
not
isinstance
(
log_level
,
int
):
raise
ValueError
(
'
Invalid default log level: %s
'
%
log_level_str
)
app
.
logger
.
setLevel
(
log_level
)
app
.
logger
.
debug
(
'
Hawat: Default logging services successfully started with level %s
'
,
log_level_str
)
return
app
def
setup_logging_file
(
app
):
"""
Setup application logging via watched file (rotated by external command).
"""
log_level_str
=
app
.
config
[
'
HAWAT_LOG_FILE_LEVEL
'
].
upper
()
log_level
=
getattr
(
logging
,
log_level_str
,
None
)
if
not
isinstance
(
log_level
,
int
):
raise
ValueError
(
'
Invalid log file level: %s
'
%
log_level_str
)
file_handler
=
WatchedFileHandler
(
app
.
config
[
'
HAWAT_LOG_FILE
'
])
file_handler
.
setLevel
(
log_level
)
file_handler
.
setFormatter
(
logging
.
Formatter
(
'
%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]
'
)
)
app
.
logger
.
addHandler
(
file_handler
)
app
.
logger
.
debug
(
'
Hawat: File logging services successfully started to file %s with level %s
'
,
app
.
config
[
'
HAWAT_LOG_FILE
'
],
log_level_str
)
return
app
def
setup_logging_email
(
app
):
"""
Setup application logging via email.
"""
log_level_str
=
app
.
config
[
'
HAWAT_LOG_EMAIL_LEVEL
'
].
upper
()
log_level
=
getattr
(
logging
,
log_level_str
,
None
)
if
not
isinstance
(
log_level
,
int
):
raise
ValueError
(
'
Invalid log email level: %s
'
%
log_level_str
)
credentials
=
None
secure
=
None
if
app
.
config
[
'
MAIL_USERNAME
'
]
or
app
.
config
[
'
MAIL_PASSWORD
'
]:
credentials
=
(
app
.
config
[
'
MAIL_USERNAME
'
],
app
.
config
[
'
MAIL_PASSWORD
'
])
if
app
.
config
[
'
MAIL_USE_TLS
'
]:
secure
=
()
mail_handler
=
SMTPHandler
(
(
app
.
config
[
'
MAIL_SERVER
'
],
app
.
config
[
'
MAIL_PORT
'
]),
'
no-reply@
'
+
app
.
config
[
'
MAIL_SERVER
'
],
app
.
config
[
'
HAWAT_ADMINS
'
],
'
Hawat failure
'
,
credentials
)
mail_handler
.
setLevel
(
logging
.
ERROR
)
mail_handler
.
setFormatter
(
logging
.
Formatter
(
'''
mailhost
=
(
app
.
config
[
'
MAIL_SERVER
'
],
app
.
config
[
'
MAIL_PORT
'
]),
fromaddr
=
app
.
config
[
'
MAIL_DEFAULT_SENDER
'
],
toaddrs
=
app
.
config
[
'
HAWAT_ADMINS
'
],
subject
=
app
.
config
[
'
MAIL_SUBJECT_PREFIX
'
]
+
'
Application Error
'
,
credentials
=
credentials
,
secure
=
secure
)
mail_handler
.
setLevel
(
log_level
)
mail_handler
.
setFormatter
(
logging
.
Formatter
(
'''
Message type: %(levelname)s
Location: %(pathname)s:%(lineno)d
Module: %(module)s
...
...
@@ -49,16 +122,9 @@ Message:
'''
))
app
.
logger
.
addHandler
(
mail_handler
)
app
.
logger
.
debug
(
'
Hawat: Email logging services successfully started with level %s
'
,
log_level_str
)
def
setup_logging_file
(
app
):
"""
Setup application logging via watched file (rotated by external command).
"""
file_handler
=
WatchedFileHandler
(
app
.
config
[
'
HAWAT_LOG_FILE
'
])
file_handler
.
setLevel
(
logging
.
INFO
)
file_handler
.
setFormatter
(
logging
.
Formatter
(
'
%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]
'
))
app
.
logger
.
setLevel
(
logging
.
INFO
)
app
.
logger
.
addHandler
(
file_handler
)
app
.
logger
.
info
(
'
Hawat: Logging startup
'
)
return
app
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment