Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
e258f862
Commit
e258f862
authored
Jun 27, 2014
by
Gavin Bisesi
Browse files
Merge pull request #121 from woogerboy21/serverlog-filtering
Server log filtering
parents
fb7de2ad
f685bd2a
Changes
2
Show whitespace changes
Inline
Side-by-side
servatrice/servatrice.ini.example
View file @
e258f862
...
@@ -5,6 +5,8 @@ logfile=server.log
...
@@ -5,6 +5,8 @@ logfile=server.log
name="My Cockatrice server"
name="My Cockatrice server"
id=1
id=1
number_pools=1
number_pools=1
writelog=1
logfilters=""
[servernetwork]
[servernetwork]
active=0
active=0
...
...
servatrice/src/server_logger.cpp
View file @
e258f862
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
#include
<QFile>
#include
<QFile>
#include
<QTextStream>
#include
<QTextStream>
#include
<QDateTime>
#include
<QDateTime>
#include
<QSettings>
#include
<iostream>
#include
<iostream>
#ifdef Q_OS_UNIX
#ifdef Q_OS_UNIX
# include <sys/types.h>
# include <sys/types.h>
...
@@ -44,13 +45,36 @@ void ServerLogger::logMessage(QString message, void *caller)
...
@@ -44,13 +45,36 @@ void ServerLogger::logMessage(QString message, void *caller)
if
(
!
logFile
)
if
(
!
logFile
)
return
;
return
;
bufferMutex
.
lock
();
QString
callerString
;
QString
callerString
;
if
(
caller
)
if
(
caller
)
callerString
=
QString
::
number
((
qulonglong
)
caller
,
16
)
+
" "
;
callerString
=
QString
::
number
((
qulonglong
)
caller
,
16
)
+
" "
;
//filter out all log entries based on values in configuration file
QSettings
*
settings
=
new
QSettings
(
"servatrice.ini"
,
QSettings
::
IniFormat
);
bool
shouldWeWriteLog
=
settings
->
value
(
"server/writelog"
).
toBool
();
QString
logFilters
=
settings
->
value
(
"server/logfilters"
).
toString
();
QStringList
listlogFilters
=
logFilters
.
split
(
","
,
QString
::
SkipEmptyParts
);
bool
shouldWeSkipLine
=
false
;
if
(
!
shouldWeWriteLog
)
return
;
if
(
!
logFilters
.
trimmed
().
isEmpty
()){
shouldWeSkipLine
=
true
;
foreach
(
QString
logFilter
,
listlogFilters
){
if
(
message
.
contains
(
logFilter
,
Qt
::
CaseInsensitive
)){
shouldWeSkipLine
=
false
;
break
;
}
}
}
if
(
shouldWeSkipLine
)
return
;
bufferMutex
.
lock
();
buffer
.
append
(
QDateTime
::
currentDateTime
().
toString
()
+
" "
+
callerString
+
message
);
buffer
.
append
(
QDateTime
::
currentDateTime
().
toString
()
+
" "
+
callerString
+
message
);
bufferMutex
.
unlock
();
bufferMutex
.
unlock
();
emit
sigFlushBuffer
();
emit
sigFlushBuffer
();
}
}
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment