Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
gajim
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
210
Issues
210
List
Boards
Labels
Service Desk
Milestones
Merge Requests
22
Merge Requests
22
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gajim
gajim
Commits
a68337a4
Commit
a68337a4
authored
Feb 14, 2021
by
Philipp Hörist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Logging: Move logging setup methods to logging_helpers
Also check for GAJIM_DEBUG
parent
ae2d2f10
Pipeline
#7321
passed with stages
in 9 minutes and 53 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
28 deletions
+35
-28
gajim/application.py
gajim/application.py
+1
-28
gajim/common/logging_helpers.py
gajim/common/logging_helpers.py
+34
-0
No files found.
gajim/application.py
View file @
a68337a4
...
...
@@ -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
...
...
gajim/common/logging_helpers.py
View file @
a68337a4
...
...
@@ -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
()
...
...
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