Skip to content

Commit 2ec8211

Browse files
committed
clang-format
1 parent f10e472 commit 2ec8211

File tree

3 files changed

+40
-41
lines changed

3 files changed

+40
-41
lines changed

include/InfoLogger/InfoLogger.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class InfoLogger
196196
// all context fields will be set to default unless an explicit context argument is given for each message.
197197
int unsetContext();
198198

199-
/// Turn on/off stdout/stderr redirection
199+
/// Turn on/off stdout/stderr redirection
200200
/// true -> turn ON. Stdout/Stderr are redirected to internal pipes and a dedicated thread captures the stream and redirects to this instance of infologger (with corresponding severity).
201201
/// false -> turn OFF (if it was ON). Stdout/Stderr are redirected to previous outputs, and capture thread is stopped.
202202
/// Return 0 on success, or an error code otherwise

src/InfoLogger.cxx

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ class InfoLogger::Impl
266266
int logV(const InfoLoggerMessageOption& options, const InfoLoggerContext& context, const char* message, va_list ap) __attribute__((format(printf, 4, 0)));
267267

268268
// main loop of collecting thread, reading incoming messages from a pipe and redirecting to infoLogger
269-
void redirectThreadLoop();
270-
269+
void redirectThreadLoop();
270+
271271
protected:
272272
int magicTag; //< A static tag used for handle validity cross-check
273273
int numberOfMessages; //< number of messages received by this object
@@ -282,14 +282,14 @@ class InfoLogger::Impl
282282

283283
InfoLoggerClient* client; //< entity to communicate with local infoLoggerD
284284
SimpleLog stdLog; //< object to output messages to stdout/file
285-
286-
bool isRedirecting=false; // state of stdout/stderr redirection
287-
int fdStdout=-1; // initial stdout file descriptor, if redirection active
288-
int fdStderr=-1; // initial stderr file descriptor, if redirection active
289-
int pipeStdout[2]; // a pipe to redirect stdout to collecting thread
290-
int pipeStderr[2]; // a pipe to redirect stderr to collecting thread
285+
286+
bool isRedirecting = false; // state of stdout/stderr redirection
287+
int fdStdout = -1; // initial stdout file descriptor, if redirection active
288+
int fdStderr = -1; // initial stderr file descriptor, if redirection active
289+
int pipeStdout[2]; // a pipe to redirect stdout to collecting thread
290+
int pipeStderr[2]; // a pipe to redirect stderr to collecting thread
291291
std::unique_ptr<std::thread> redirectThread; // the thread handling the redirection
292-
bool redirectThreadShutdown; // flag to ask the thread to stop
292+
bool redirectThreadShutdown; // flag to ask the thread to stop
293293
};
294294

295295
void InfoLogger::Impl::refreshDefaultMsg()
@@ -741,94 +741,93 @@ int InfoLogger::setMessageOption(const char* fieldName, const char* fieldValue,
741741
// required with some compilers to avoid linking errors
742742
constexpr InfoLogger::InfoLoggerMessageOption InfoLogger::undefinedMessageOption;
743743

744-
745-
void InfoLogger::Impl::redirectThreadLoop() {
744+
void InfoLogger::Impl::redirectThreadLoop()
745+
{
746746
LineBuffer lbStdout; // buffer for input lines
747747
LineBuffer lbStderr; // buffer for input lines
748748
std::string msg;
749-
bool isActive=0;
750-
while(!redirectThreadShutdown) {
751-
isActive=0;
749+
bool isActive = 0;
750+
while (!redirectThreadShutdown) {
751+
isActive = 0;
752752
lbStdout.appendFromFileDescriptor(pipeStdout[0], 0);
753753
for (;;) {
754754
if (lbStdout.getNextLine(msg)) {
755755
// no line left
756756
break;
757757
}
758-
isActive=1;
759-
pushMessage(InfoLogger::Severity::Info,msg.c_str());
758+
isActive = 1;
759+
pushMessage(InfoLogger::Severity::Info, msg.c_str());
760760
}
761761
lbStderr.appendFromFileDescriptor(pipeStderr[0], 0);
762762
for (;;) {
763763
if (lbStderr.getNextLine(msg)) {
764764
// no line left
765765
break;
766766
}
767-
isActive=1;
768-
pushMessage(InfoLogger::Severity::Error,msg.c_str());
767+
isActive = 1;
768+
pushMessage(InfoLogger::Severity::Error, msg.c_str());
769769
}
770770

771771
if (!isActive) {
772772
usleep(50000);
773773
}
774774
}
775-
// fprintf(fp,"thread stopped\n");
776-
// fclose(fp);
775+
// fprintf(fp,"thread stopped\n");
776+
// fclose(fp);
777777
}
778778

779-
780-
int InfoLogger::setStandardRedirection(bool state) {
781-
if (state==mPimpl->isRedirecting) {
779+
int InfoLogger::setStandardRedirection(bool state)
780+
{
781+
if (state == mPimpl->isRedirecting) {
782782
// we are already in the requested redirection state
783783
return -1;
784784
}
785-
785+
786786
if (state) {
787787
// turn ON redirection
788788

789789
// create a pipe
790-
if (pipe(mPimpl->pipeStdout)!=0) {
790+
if (pipe(mPimpl->pipeStdout) != 0) {
791791
return -1;
792792
}
793-
if (pipe(mPimpl->pipeStderr)!=0) {
793+
if (pipe(mPimpl->pipeStderr) != 0) {
794794
return -1;
795795
}
796-
796+
797797
// save current stdout/stderr
798798
mPimpl->fdStdout = dup(STDOUT_FILENO);
799799
dup2(mPimpl->pipeStdout[1], STDOUT_FILENO);
800800
mPimpl->fdStderr = dup(STDERR_FILENO);
801801
dup2(mPimpl->pipeStderr[1], STDERR_FILENO);
802802

803-
mPimpl->stdLog.setFileDescriptors(mPimpl->fdStdout,mPimpl->fdStderr);
803+
mPimpl->stdLog.setFileDescriptors(mPimpl->fdStdout, mPimpl->fdStderr);
804804

805805
// create collecting thread
806-
mPimpl->redirectThreadShutdown=0;
806+
mPimpl->redirectThreadShutdown = 0;
807807
std::function<void(void)> l = std::bind(&InfoLogger::Impl::redirectThreadLoop, mPimpl.get());
808808
mPimpl->redirectThread = std::make_unique<std::thread>(l);
809809

810810
} else {
811811
// turn OFF redirection
812-
812+
813813
// stop collecting thread
814-
mPimpl->redirectThreadShutdown=1;
814+
mPimpl->redirectThreadShutdown = 1;
815815
mPimpl->redirectThread->join();
816-
mPimpl->redirectThread=nullptr;
816+
mPimpl->redirectThread = nullptr;
817+
818+
mPimpl->stdLog.setFileDescriptors(STDOUT_FILENO, STDERR_FILENO);
817819

818-
mPimpl->stdLog.setFileDescriptors(STDOUT_FILENO,STDERR_FILENO);
819-
820820
dup2(mPimpl->fdStdout, STDOUT_FILENO);
821821
close(mPimpl->fdStdout);
822822
close(mPimpl->pipeStdout[0]);
823-
close(mPimpl->pipeStdout[1]);
823+
close(mPimpl->pipeStdout[1]);
824824
dup2(mPimpl->fdStderr, STDERR_FILENO);
825825
close(mPimpl->fdStderr);
826826
close(mPimpl->pipeStderr[0]);
827-
close(mPimpl->pipeStderr[1]);
828-
827+
close(mPimpl->pipeStderr[1]);
829828
}
830-
831-
mPimpl->isRedirecting=state;
829+
830+
mPimpl->isRedirecting = state;
832831
return 0;
833832
}
834833

test/testInfoLogger.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int main()
2626
printf("Message on stdout (initial stdout)\n");
2727
theLog.setStandardRedirection(1);
2828
printf("Message on stdout (redirection enabled)\n");
29-
fprintf(stderr,"Message on stderr (redirection enabled)\n");
29+
fprintf(stderr, "Message on stderr (redirection enabled)\n");
3030
usleep(100000);
3131
theLog.setStandardRedirection(0);
3232
printf("Message on stdout (redirection stopped)\n");

0 commit comments

Comments
 (0)