Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
7d5a40bb
Commit
7d5a40bb
authored
Apr 12, 2015
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make logging more readable by removing noisy prefixes on filenames.
parent
41773d2f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
4 deletions
+36
-4
debug-test.c++
c++/src/kj/debug-test.c++
+3
-1
debug.c++
c++/src/kj/debug.c++
+1
-1
exception-test.c++
c++/src/kj/exception-test.c++
+4
-0
exception.c++
c++/src/kj/exception.c++
+24
-2
exception.h
c++/src/kj/exception.h
+4
-0
No files found.
c++/src/kj/debug-test.c++
View file @
7d5a40bb
...
...
@@ -182,6 +182,8 @@ public:
#endif
std
::
string
fileLine
(
std
::
string
file
,
int
line
)
{
file
=
trimSourceFilename
(
file
.
c_str
()).
cStr
();
file
+=
':'
;
char
buffer
[
32
];
sprintf
(
buffer
,
"%d"
,
line
);
...
...
@@ -266,7 +268,7 @@ TEST(Debug, Exception) {
int
line
=
__LINE__
;
Exception
exception
=
KJ_EXCEPTION
(
DISCONNECTED
,
"foo"
,
i
);
EXPECT_EQ
(
Exception
::
Type
::
DISCONNECTED
,
exception
.
getType
());
EXPECT_
STREQ
(
__FILE__
,
exception
.
getFile
(
));
EXPECT_
TRUE
(
kj
::
StringPtr
(
__FILE__
).
endsWith
(
exception
.
getFile
()
));
EXPECT_EQ
(
line
,
exception
.
getLine
());
EXPECT_EQ
(
"foo; i = 123"
,
exception
.
getDescription
());
}
...
...
c++/src/kj/debug.c++
View file @
7d5a40bb
...
...
@@ -268,7 +268,7 @@ static String makeDescriptionImpl(DescriptionStyle style, const char* code, int
void
Debug
::
logInternal
(
const
char
*
file
,
int
line
,
LogSeverity
severity
,
const
char
*
macroArgs
,
ArrayPtr
<
String
>
argValues
)
{
getExceptionCallback
().
logMessage
(
severity
,
file
,
line
,
0
,
getExceptionCallback
().
logMessage
(
severity
,
trimSourceFilename
(
file
).
cStr
()
,
line
,
0
,
makeDescriptionImpl
(
LOG
,
nullptr
,
0
,
macroArgs
,
argValues
));
}
...
...
c++/src/kj/exception-test.c++
View file @
7d5a40bb
...
...
@@ -27,6 +27,10 @@ namespace kj {
namespace
_
{
// private
namespace
{
TEST
(
Exception
,
TrimSourceFilename
)
{
EXPECT_EQ
(
trimSourceFilename
(
__FILE__
),
"kj/exception-test.c++"
);
}
TEST
(
Exception
,
RunCatchingExceptions
)
{
bool
recovered
=
false
;
Maybe
<
Exception
>
e
=
kj
::
runCatchingExceptions
([
&
]()
{
...
...
c++/src/kj/exception.c++
View file @
7d5a40bb
...
...
@@ -207,6 +207,28 @@ void printStackTraceOnCrash() {
#endif
}
kj
::
StringPtr
trimSourceFilename
(
kj
::
StringPtr
filename
)
{
// Removes noisy prefixes from source code file name.
static
constexpr
const
char
*
PREFIXES
[]
=
{
"../"
,
"/ekam-provider/canonical/"
,
"/ekam-provider/c++header/"
,
"src/"
,
"tmp/"
};
retry
:
for
(
const
char
*
prefix
:
PREFIXES
)
{
if
(
filename
.
startsWith
(
prefix
))
{
filename
=
filename
.
slice
(
strlen
(
prefix
));
goto
retry
;
}
}
return
filename
;
}
StringPtr
KJ_STRINGIFY
(
Exception
::
Type
type
)
{
static
const
char
*
TYPE_STRINGS
[]
=
{
"failed"
,
...
...
@@ -253,12 +275,12 @@ String KJ_STRINGIFY(const Exception& e) {
}
Exception
::
Exception
(
Type
type
,
const
char
*
file
,
int
line
,
String
description
)
noexcept
:
file
(
file
),
line
(
line
),
type
(
type
),
description
(
mv
(
description
))
{
:
file
(
trimSourceFilename
(
file
).
cStr
()
),
line
(
line
),
type
(
type
),
description
(
mv
(
description
))
{
traceCount
=
kj
::
getStackTrace
(
trace
).
size
();
}
Exception
::
Exception
(
Type
type
,
String
file
,
int
line
,
String
description
)
noexcept
:
ownFile
(
kj
::
mv
(
file
)),
file
(
ownFile
.
cStr
()),
line
(
line
),
type
(
type
),
:
ownFile
(
kj
::
mv
(
file
)),
file
(
trimSourceFilename
(
ownFile
)
.
cStr
()),
line
(
line
),
type
(
type
),
description
(
mv
(
description
))
{
traceCount
=
kj
::
getStackTrace
(
trace
).
size
();
}
...
...
c++/src/kj/exception.h
View file @
7d5a40bb
...
...
@@ -307,6 +307,10 @@ void printStackTraceOnCrash();
// a stack trace. You should call this as early as possible on program startup. Programs using
// KJ_MAIN get this automatically.
kj
::
StringPtr
trimSourceFilename
(
kj
::
StringPtr
filename
);
// Given a source code file name, trim off noisy prefixes like "src/" or
// "/ekam-provider/canonical/".
}
// namespace kj
#endif // KJ_EXCEPTION_H_
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