Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mesonium
gajim
Commits
c3578713
Commit
c3578713
authored
4 years ago
by
Philipp Hörist
Browse files
Options
Downloads
Patches
Plain Diff
Logging: Move logging setup methods to logging_helpers
Also check for GAJIM_DEBUG
parent
073cc613
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gajim/application.py
+1
-28
1 addition, 28 deletions
gajim/application.py
gajim/common/logging_helpers.py
+34
-0
34 additions, 0 deletions
gajim/common/logging_helpers.py
with
35 additions
and
28 deletions
gajim/application.py
+
1
−
28
View file @
c3578713
...
...
@@ -34,9 +34,7 @@
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
import
os
import
time
import
sys
from
datetime
import
datetime
from
urllib.parse
import
unquote
from
nbxmpp.namespaces
import
Namespace
...
...
@@ -358,14 +356,7 @@ def _handle_local_options(self,
if
options
.
contains
(
'
gdebug
'
):
os
.
environ
[
'
G_MESSAGES_DEBUG
'
]
=
'
all
'
if
app
.
get_debug_mode
():
# Redirect has to happen before logging init
self
.
_cleanup_debug_logs
()
self
.
_redirect_output
()
logging_helpers
.
init
()
logging_helpers
.
set_verbose
()
else
:
logging_helpers
.
init
()
logging_helpers
.
init
()
if
options
.
contains
(
'
quiet
'
):
logging_helpers
.
set_quiet
()
...
...
@@ -393,24 +384,6 @@ def warn_with_traceback(message, category, filename, lineno,
warnings
.
showwarning
=
warn_with_traceback
warnings
.
filterwarnings
(
action
=
"
always
"
)
@staticmethod
def
_redirect_output
():
debug_folder
=
configpaths
.
get
(
'
DEBUG
'
)
date
=
datetime
.
today
().
strftime
(
'
%d%m%Y-%H%M%S
'
)
filename
=
'
%s-debug.log
'
%
date
fd
=
open
(
debug_folder
/
filename
,
'
a
'
)
sys
.
stderr
=
sys
.
stdout
=
fd
@staticmethod
def
_cleanup_debug_logs
():
debug_folder
=
configpaths
.
get
(
'
DEBUG
'
)
debug_files
=
list
(
debug_folder
.
glob
(
'
*-debug.log*
'
))
now
=
time
.
time
()
for
file
in
debug_files
:
# Delete everything older than 3 days
if
file
.
stat
().
st_ctime
<
now
-
259200
:
file
.
unlink
()
def
add_actions
(
self
):
'''
Build Application Actions
'''
from
gajim
import
app_actions
...
...
This diff is collapsed.
Click to expand it.
gajim/common/logging_helpers.py
+
34
−
0
View file @
c3578713
...
...
@@ -17,7 +17,11 @@
import
logging
import
os
import
sys
import
time
from
datetime
import
datetime
from
gajim.common
import
app
from
gajim.common
import
configpaths
from
gajim.common.i18n
import
_
def
parseLogLevel
(
arg
):
...
...
@@ -136,6 +140,11 @@ def init():
"""
Iinitialize the logging system
"""
if
app
.
get_debug_mode
():
_cleanup_debug_logs
()
_redirect_output
()
use_color
=
False
if
os
.
name
!=
'
nt
'
:
use_color
=
sys
.
stderr
.
isatty
()
...
...
@@ -164,6 +173,12 @@ def init():
root_log
.
addHandler
(
consoleloghandler
)
root_log
.
propagate
=
False
# GAJIM_DEBUG is set only on Windows when using Gajim-Debug.exe
# Gajim-Debug.exe shows a command line prompt and we want to redirect
# log output to it
if
app
.
get_debug_mode
()
or
os
.
environ
.
get
(
'
GAJIM_DEBUG
'
,
False
):
set_verbose
()
def
set_loglevels
(
loglevels_string
):
parseAndSetLogLevels
(
loglevels_string
)
...
...
@@ -176,6 +191,25 @@ def set_quiet():
parseAndSetLogLevels
(
'
.nbxmpp=CRITICAL
'
)
def
_redirect_output
():
debug_folder
=
configpaths
.
get
(
'
DEBUG
'
)
date
=
datetime
.
today
().
strftime
(
'
%d%m%Y-%H%M%S
'
)
filename
=
'
%s-debug.log
'
%
date
fd
=
open
(
debug_folder
/
filename
,
'
a
'
)
sys
.
stderr
=
sys
.
stdout
=
fd
def
_cleanup_debug_logs
():
debug_folder
=
configpaths
.
get
(
'
DEBUG
'
)
debug_files
=
list
(
debug_folder
.
glob
(
'
*-debug.log*
'
))
now
=
time
.
time
()
for
file
in
debug_files
:
# Delete everything older than 3 days
if
file
.
stat
().
st_ctime
<
now
-
259200
:
file
.
unlink
()
# tests
if
__name__
==
'
__main__
'
:
init
()
...
...
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