Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
ACGL
acgl
Commits
f96584a2
Commit
f96584a2
authored
Feb 12, 2013
by
Robert Menzel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added simple message mirroring to a file and fixed a bug in long debug outputs
parent
0f4206e9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
1 deletion
+43
-1
include/ACGL/Utils/Log.hh
include/ACGL/Utils/Log.hh
+13
-0
src/ACGL/Utils/Log.cc
src/ACGL/Utils/Log.cc
+30
-1
No files found.
include/ACGL/Utils/Log.hh
View file @
f96584a2
...
...
@@ -62,6 +62,8 @@ public:
~
CoutLikeStreamBuffer
();
void
setPrefix
(
const
std
::
string
&
_prefix
);
void
setFilename
(
const
std
::
string
&
_filename
);
private:
//virtual std::streamsize xsputn(const base_type::char_type* s, std::streamsize n)
...
...
@@ -74,6 +76,7 @@ private:
// for each endl:
virtual
int
sync
();
void
mirrorToFile
(
const
std
::
string
&
_token
);
private:
char
*
mBuffer
;
std
::
string
mPrefix
;
...
...
@@ -81,6 +84,8 @@ private:
size_t
mBufferMaxSize
;
// size of the buffer
bool
mNewLineIsAboutToStart
;
bool
mMirrorToFile
;
std
::
string
mFilename
;
#ifdef __ANDROID__
android_LogPriority
mAndroidPriority
;
...
...
@@ -138,6 +143,14 @@ public:
mStreamBuffer
->
setPrefix
(
_prefix
);
}
}
//! a filename of a text file to mirror all outputs into
//! set a filename of "" to disable this
void
setFilename
(
const
std
::
string
&
_filename
)
{
if
(
mStreamBuffer
)
{
mStreamBuffer
->
setFilename
(
_filename
);
}
}
void
mute
()
{
rdbuf
(
NULL
);
}
void
unmute
()
{
rdbuf
(
mStreamBuffer
);
}
private:
...
...
src/ACGL/Utils/Log.cc
View file @
f96584a2
...
...
@@ -8,6 +8,7 @@
#include <cstdio>
#include <iostream>
#include <fstream>
using
namespace
ACGL
::
Utils
;
CoutLikeStreamBuffer
::
CoutLikeStreamBuffer
()
:
base_type
()
{
...
...
@@ -15,6 +16,7 @@ CoutLikeStreamBuffer::CoutLikeStreamBuffer() : base_type() {
mBufferMaxSize
=
256
;
mBuffer
=
new
char
[
mBufferMaxSize
+
1
];
mNewLineIsAboutToStart
=
true
;
mMirrorToFile
=
false
;
}
CoutLikeStreamBuffer
::~
CoutLikeStreamBuffer
()
{
...
...
@@ -29,6 +31,29 @@ void CoutLikeStreamBuffer::setPrefix( const std::string &_prefix ) {
mPrefix
=
_prefix
;
}
void
CoutLikeStreamBuffer
::
setFilename
(
const
std
::
string
&
_filename
)
{
mFilename
=
_filename
;
if
(
_filename
==
""
)
{
mMirrorToFile
=
false
;
}
else
{
mMirrorToFile
=
true
;
}
}
void
CoutLikeStreamBuffer
::
mirrorToFile
(
const
std
::
string
&
_token
)
{
if
(
mMirrorToFile
==
false
)
{
return
;
}
// opening and closing the file each time is slow but we don't
// loose much in case the app crashes and debugging is the main
// usecase for this function!
std
::
ofstream
file
;
file
.
open
(
mFilename
,
std
::
ios
::
app
);
file
<<
_token
;
file
.
close
();
}
CoutLikeStreamBuffer
::
base_type
::
int_type
CoutLikeStreamBuffer
::
overflow
(
base_type
::
int_type
ch
)
{
// print buffer
if
((
mBufferSize
>=
mBufferMaxSize
)
||
(
base_type
::
traits_type
::
eq_int_type
(
ch
,
base_type
::
traits_type
::
eof
())))
{
...
...
@@ -36,6 +61,7 @@ CoutLikeStreamBuffer::base_type::int_type CoutLikeStreamBuffer::overflow(base_ty
if
(
mNewLineIsAboutToStart
)
{
#ifndef __ANDROID__
std
::
cout
<<
mPrefix
;
mirrorToFile
(
mPrefix
);
#endif
mNewLineIsAboutToStart
=
false
;
}
...
...
@@ -45,10 +71,13 @@ CoutLikeStreamBuffer::base_type::int_type CoutLikeStreamBuffer::overflow(base_ty
__android_log_print
(
mAndroidPriority
,
mPrefix
.
c_str
(),
"%s"
,
mBuffer
);
#else
std
::
cout
<<
mBuffer
;
mirrorToFile
(
mBuffer
);
#endif
mBufferSize
=
0
;
}
}
else
{
}
if
(
!
(
base_type
::
traits_type
::
eq_int_type
(
ch
,
base_type
::
traits_type
::
eof
())))
{
mBuffer
[
mBufferSize
++
]
=
(
char
)
ch
;
}
return
base_type
::
traits_type
::
not_eof
(
ch
);
...
...
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