Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
41cba1cc
Commit
41cba1cc
authored
Sep 11, 2014
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(Log): доделал утилиту log-wrap для "чтения" cerr и cout
parent
0217b4b1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
163 additions
and
165 deletions
+163
-165
Makefile.am
Utilities/ULog/Makefile.am
+2
-2
log-stdin.cc
Utilities/ULog/log-stdin.cc
+69
-69
log-wrap.cc
Utilities/ULog/log-wrap.cc
+76
-78
logserver.cc
Utilities/ULog/logserver.cc
+16
-16
No files found.
Utilities/ULog/Makefile.am
View file @
41cba1cc
bin_PROGRAMS
=
@PACKAGE@-log
@PACKAGE@-log-stdin
@PACKAGE@-logserver-wrap
bin_PROGRAMS
=
@PACKAGE@-log @PACKAGE@-logserver-wrap
noinst_PROGRAMS
=
@PACKAGE@-test-logserver
noinst_PROGRAMS
=
@PACKAGE@-test-logserver
@PACKAGE@-log-stdin
@PACKAGE@
_test_logserver_SOURCES
=
logserver.cc
@PACKAGE@
_test_logserver_SOURCES
=
logserver.cc
@PACKAGE@
_test_logserver_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
$(COMCPP_LIBS)
@PACKAGE@
_test_logserver_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
$(COMCPP_LIBS)
...
...
Utilities/ULog/log-stdin.cc
View file @
41cba1cc
...
@@ -10,94 +10,94 @@ using namespace UniSetTypes;
...
@@ -10,94 +10,94 @@ using namespace UniSetTypes;
using
namespace
std
;
using
namespace
std
;
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
static
struct
option
longopts
[]
=
{
static
struct
option
longopts
[]
=
{
{
"help"
,
no_argument
,
0
,
'h'
},
{
"help"
,
no_argument
,
0
,
'h'
},
{
"iaddr"
,
required_argument
,
0
,
'i'
},
{
"iaddr"
,
required_argument
,
0
,
'i'
},
{
"port"
,
required_argument
,
0
,
'p'
},
{
"port"
,
required_argument
,
0
,
'p'
},
{
"verbose"
,
no_argument
,
0
,
'v'
},
{
"verbose"
,
no_argument
,
0
,
'v'
},
{
NULL
,
0
,
0
,
0
}
{
NULL
,
0
,
0
,
0
}
};
};
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
static
void
print_help
()
static
void
print_help
()
{
{
printf
(
"-h - this message
\n
"
);
printf
(
"-h - this message
\n
"
);
printf
(
"-v - Print all messages to stdout
\n
"
);
printf
(
"-v - Print all messages to stdout
\n
"
);
printf
(
"-i addr - LogServer ip or hostname. Default: localhost.
\n
"
);
printf
(
"-i addr - LogServer ip or hostname. Default: localhost.
\n
"
);
printf
(
"-p port - LogServer port. Default: 3333.
\n
"
);
printf
(
"-p port - LogServer port. Default: 3333.
\n
"
);
}
}
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
int
main
(
int
argc
,
char
*
argv
[],
char
*
envp
[]
)
int
main
(
int
argc
,
char
*
argv
[],
char
*
envp
[]
)
{
{
int
optindex
=
0
;
int
optindex
=
0
;
int
opt
=
0
;
int
opt
=
0
;
int
verb
=
0
;
int
verb
=
0
;
string
addr
(
"localhost"
);
string
addr
(
"localhost"
);
int
port
=
3333
;
int
port
=
3333
;
try
try
{
{
while
(
(
opt
=
getopt_long
(
argc
,
argv
,
"hvi:p:"
,
longopts
,
&
optindex
))
!=
-
1
)
while
(
(
opt
=
getopt_long
(
argc
,
argv
,
"hvi:p:"
,
longopts
,
&
optindex
))
!=
-
1
)
{
{
switch
(
opt
)
switch
(
opt
)
{
{
case
'h'
:
case
'h'
:
print_help
();
print_help
();
return
0
;
return
0
;
case
'i'
:
case
'i'
:
addr
=
string
(
optarg
);
addr
=
string
(
optarg
);
break
;
break
;
case
'p'
:
case
'p'
:
port
=
atoi
(
optarg
);
port
=
atoi
(
optarg
);
break
;
break
;
case
'v'
:
case
'v'
:
verb
=
1
;
verb
=
1
;
break
;
break
;
case
'?'
:
case
'?'
:
default:
default:
printf
(
"? argumnet
\n
"
);
printf
(
"? argumnet
\n
"
);
return
0
;
return
0
;
}
}
}
}
if
(
verb
)
if
(
verb
)
cout
<<
"(init): listen "
<<
addr
<<
":"
<<
port
<<
endl
;
cout
<<
"(init): listen "
<<
addr
<<
":"
<<
port
<<
endl
;
DebugStream
log
;
DebugStream
log
;
LogServer
ls
(
log
);
LogServer
ls
(
log
);
ls
.
run
(
addr
,
port
,
true
);
ls
.
run
(
addr
,
port
,
true
);
char
buf
[
10000
];
char
buf
[
10000
];
while
(
true
)
while
(
true
)
{
{
size_t
r
=
read
(
0
,
buf
,
sizeof
(
buf
)
-
1
);
size_t
r
=
read
(
fileno
(
stdin
)
,
buf
,
sizeof
(
buf
)
-
1
);
if
(
r
>
0
)
if
(
r
>
0
)
{
{
buf
[
r
]
=
'\0'
;
buf
[
r
]
=
'\0'
;
log
<<
buf
;
log
<<
buf
;
}
}
}
}
}
}
catch
(
SystemError
&
err
)
catch
(
SystemError
&
err
)
{
{
cerr
<<
"(log-stdin): "
<<
err
<<
endl
;
cerr
<<
"(log-stdin): "
<<
err
<<
endl
;
return
1
;
return
1
;
}
}
catch
(
Exception
&
ex
)
catch
(
Exception
&
ex
)
{
{
cerr
<<
"(log-stdin): "
<<
ex
<<
endl
;
cerr
<<
"(log-stdin): "
<<
ex
<<
endl
;
return
1
;
return
1
;
}
}
catch
(...)
catch
(...)
{
{
cerr
<<
"(log-stdin): catch(...)"
<<
endl
;
cerr
<<
"(log-stdin): catch(...)"
<<
endl
;
return
1
;
return
1
;
}
}
return
0
;
return
0
;
}
}
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
Utilities/ULog/log-wrap.cc
View file @
41cba1cc
...
@@ -16,107 +16,105 @@ using namespace std;
...
@@ -16,107 +16,105 @@ using namespace std;
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
static
void
print_help
()
static
void
print_help
()
{
{
printf
(
"
\n
"
);
printf
(
"
\n
"
);
printf
(
"Usage: uniset2-logserver-wrap listen-addr listen-port PROGRAMM ARGS..
\n
"
);
printf
(
"Usage: uniset2-logserver-wrap listen-addr listen-port PROGRAMM ARGS..
\n
"
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
}
}
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
int
main
(
int
argc
,
char
*
argv
[],
char
*
envp
[]
)
int
main
(
int
argc
,
char
*
argv
[],
char
*
envp
[]
)
{
{
if
(
argc
<
4
)
if
(
argc
<
4
)
{
{
print_help
();
print_help
();
return
1
;
return
1
;
}
}
string
addr
(
argv
[
1
]);
string
addr
(
argv
[
1
]);
int
port
=
atoi
(
argv
[
2
]);
int
port
=
atoi
(
argv
[
2
]);
int
pid
;
int
pid
;
int
cp
[
2
];
/* Child to parent pipe */
int
cp
[
2
];
/* Child to parent pipe */
if
(
pipe
(
cp
)
<
0
)
if
(
pipe
(
cp
)
<
0
)
{
{
perror
(
"Can't make pipe"
);
perror
(
"Can't make pipe"
);
exit
(
1
);
exit
(
1
);
}
}
try
try
{
{
/* Create a child to run command. */
switch
(
pid
=
fork
()
)
switch
(
pid
=
fork
()
)
{
{
case
-
1
:
case
-
1
:
{
{
perror
(
"Can't fork"
);
perror
(
"Can't fork"
);
exit
(
1
);
exit
(
1
);
}
}
case
0
:
case
0
:
{
{
/* Child. */
/* Child. */
close
(
cp
[
0
]);
close
(
cp
[
0
]);
close
(
fileno
(
stderr
)
);
//close stderr
close
(
fileno
(
stdout
)
);
dup2
(
fileno
(
stdout
),
fileno
(
stderr
));
dup2
(
cp
[
1
],
fileno
(
stdout
));
close
(
fileno
(
stdout
));
/* Close current stdout. */
close
(
fileno
(
stderr
)
);
dup2
(
cp
[
1
],
fileno
(
stdout
));
/* Make stdout go to write end of pipe. */
dup2
(
fileno
(
stdout
),
fileno
(
stderr
));
execvpe
(
argv
[
3
],
argv
+
3
,
envp
);
execvpe
(
argv
[
3
],
argv
+
3
,
envp
);
perror
(
"No exec"
);
perror
(
"No exec"
);
kill
(
getppid
(),
SIGQUIT
);
kill
(
getppid
(),
SIGQUIT
);
exit
(
1
);
exit
(
1
);
}
}
break
;
break
;
default:
default:
{
{
/* Parent. */
/* Parent. */
close
(
cp
[
1
]);
close
(
cp
[
1
]);
DebugStream
zlog
;
DebugStream
zlog
;
zlog
.
addLevel
(
Debug
::
ANY
);
zlog
.
addLevel
(
Debug
::
ANY
);
LogServer
ls
(
zlog
);
LogServer
ls
(
zlog
);
cout
<<
"wrap: server "
<<
addr
<<
":"
<<
port
<<
endl
;
cout
<<
"wrap: server "
<<
addr
<<
":"
<<
port
<<
endl
;
ls
.
run
(
addr
,
port
,
true
);
ls
.
run
(
addr
,
port
,
true
);
char
buf
[
5000
];
char
buf
[
5000
];
while
(
true
)
while
(
true
)
{
{
ssize_t
r
=
read
(
cp
[
0
],
&
buf
,
sizeof
(
buf
)
-
1
);
ssize_t
r
=
read
(
cp
[
0
],
&
buf
,
sizeof
(
buf
)
-
1
);
if
(
r
>
0
)
if
(
r
>
0
)
{
{
cout
<<
"***READ**"
<<
endl
;
buf
[
r
]
=
'\0'
;
buf
[
r
]
=
'\0'
;
zlog
<<
buf
;
zlog
<<
buf
;
}
}
}
}
exit
(
0
);
exit
(
0
);
}
}
break
;
break
;
}
}
}
}
catch
(
SystemError
&
err
)
catch
(
SystemError
&
err
)
{
{
cerr
<<
"(logserver-wrap): "
<<
err
<<
endl
;
cerr
<<
"(logserver-wrap): "
<<
err
<<
endl
;
return
1
;
return
1
;
}
}
catch
(
Exception
&
ex
)
catch
(
Exception
&
ex
)
{
{
cerr
<<
"(logserver-wrap): "
<<
ex
<<
endl
;
cerr
<<
"(logserver-wrap): "
<<
ex
<<
endl
;
return
1
;
return
1
;
}
}
catch
(...)
catch
(...)
{
{
cerr
<<
"(logserver-wrap): catch(...)"
<<
endl
;
cerr
<<
"(logserver-wrap): catch(...)"
<<
endl
;
return
1
;
return
1
;
}
}
return
0
;
return
0
;
}
}
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
Utilities/ULog/logserver.cc
View file @
41cba1cc
...
@@ -82,17 +82,17 @@ int main( int argc, char **argv )
...
@@ -82,17 +82,17 @@ int main( int argc, char **argv )
}
}
DebugStream
dlog
;
DebugStream
dlog
;
dlog
.
setLogName
(
"dlog"
);
dlog
.
setLogName
(
"dlog"
);
DebugStream
dlog2
;
DebugStream
dlog2
;
dlog2
.
setLogName
(
"dlog2"
);
dlog2
.
setLogName
(
"dlog2"
);
LogAgregator
la
;
LogAgregator
la
;
la
.
add
(
dlog
);
la
.
add
(
dlog
);
la
.
add
(
dlog2
);
la
.
add
(
dlog2
);
LogServer
ls
(
la
);
LogServer
ls
(
la
);
//
LogServer ls(cout);
//
LogServer ls(cout);
dlog
.
addLevel
(
Debug
::
ANY
);
dlog
.
addLevel
(
Debug
::
ANY
);
dlog2
.
addLevel
(
Debug
::
ANY
);
dlog2
.
addLevel
(
Debug
::
ANY
);
...
@@ -101,16 +101,16 @@ int main( int argc, char **argv )
...
@@ -101,16 +101,16 @@ int main( int argc, char **argv )
unsigned
int
i
=
0
;
unsigned
int
i
=
0
;
while
(
true
)
while
(
true
)
{
{
dlog
<<
"["
<<
++
i
<<
"] Test message for log"
<<
endl
;
dlog
<<
"["
<<
++
i
<<
"] Test message for log"
<<
endl
;
dlog
.
info
()
<<
": dlog : INFO message"
<<
endl
;
dlog
.
info
()
<<
": dlog : INFO message"
<<
endl
;
dlog
.
warn
()
<<
": dlog : WARN message"
<<
endl
;
dlog
.
warn
()
<<
": dlog : WARN message"
<<
endl
;
dlog
.
crit
()
<<
": dlog : CRIT message"
<<
endl
;
dlog
.
crit
()
<<
": dlog : CRIT message"
<<
endl
;
dlog2
.
info
()
<<
": dlog2: INFO message"
<<
endl
;
dlog2
.
info
()
<<
": dlog2: INFO message"
<<
endl
;
dlog2
.
warn
()
<<
": dlog2: WARN message"
<<
endl
;
dlog2
.
warn
()
<<
": dlog2: WARN message"
<<
endl
;
dlog2
.
crit
()
<<
": dlog2: CRIT message"
<<
endl
;
dlog2
.
crit
()
<<
": dlog2: CRIT message"
<<
endl
;
msleep
(
delay
);
msleep
(
delay
);
}
}
}
}
catch
(
SystemError
&
err
)
catch
(
SystemError
&
err
)
...
...
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