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
noinst_PROGRAMS
=
@PACKAGE@-test-logserver
bin_PROGRAMS
=
@PACKAGE@-log @PACKAGE@-logserver-wrap
noinst_PROGRAMS
=
@PACKAGE@-test-logserver
@PACKAGE@-log-stdin
@PACKAGE@
_test_logserver_SOURCES
=
logserver.cc
@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;
using
namespace
std
;
// -------------------------------------------------------------------------
static
struct
option
longopts
[]
=
{
{
"help"
,
no_argument
,
0
,
'h'
},
{
"iaddr"
,
required_argument
,
0
,
'i'
},
{
"port"
,
required_argument
,
0
,
'p'
},
{
"verbose"
,
no_argument
,
0
,
'v'
},
{
NULL
,
0
,
0
,
0
}
{
"help"
,
no_argument
,
0
,
'h'
},
{
"iaddr"
,
required_argument
,
0
,
'i'
},
{
"port"
,
required_argument
,
0
,
'p'
},
{
"verbose"
,
no_argument
,
0
,
'v'
},
{
NULL
,
0
,
0
,
0
}
};
// --------------------------------------------------------------------------
static
void
print_help
()
{
printf
(
"-h - this message
\n
"
);
printf
(
"-v - Print all messages to stdout
\n
"
);
printf
(
"-i addr - LogServer ip or hostname. Default: localhost.
\n
"
);
printf
(
"-p port - LogServer port. Default: 3333.
\n
"
);
printf
(
"-h - this message
\n
"
);
printf
(
"-v - Print all messages to stdout
\n
"
);
printf
(
"-i addr - LogServer ip or hostname. Default: localhost.
\n
"
);
printf
(
"-p port - LogServer port. Default: 3333.
\n
"
);
}
// --------------------------------------------------------------------------
int
main
(
int
argc
,
char
*
argv
[],
char
*
envp
[]
)
{
int
optindex
=
0
;
int
opt
=
0
;
int
verb
=
0
;
string
addr
(
"localhost"
);
int
port
=
3333
;
try
{
while
(
(
opt
=
getopt_long
(
argc
,
argv
,
"hvi:p:"
,
longopts
,
&
optindex
))
!=
-
1
)
{
switch
(
opt
)
{
case
'h'
:
print_help
();
return
0
;
case
'i'
:
addr
=
string
(
optarg
);
break
;
case
'p'
:
port
=
atoi
(
optarg
);
break
;
case
'v'
:
verb
=
1
;
break
;
case
'?'
:
default:
printf
(
"? argumnet
\n
"
);
return
0
;
}
}
if
(
verb
)
cout
<<
"(init): listen "
<<
addr
<<
":"
<<
port
<<
endl
;
DebugStream
log
;
LogServer
ls
(
log
);
ls
.
run
(
addr
,
port
,
true
);
int
optindex
=
0
;
int
opt
=
0
;
int
verb
=
0
;
string
addr
(
"localhost"
);
int
port
=
3333
;
try
{
while
(
(
opt
=
getopt_long
(
argc
,
argv
,
"hvi:p:"
,
longopts
,
&
optindex
))
!=
-
1
)
{
switch
(
opt
)
{
case
'h'
:
print_help
();
return
0
;
case
'i'
:
addr
=
string
(
optarg
);
break
;
case
'p'
:
port
=
atoi
(
optarg
);
break
;
case
'v'
:
verb
=
1
;
break
;
case
'?'
:
default:
printf
(
"? argumnet
\n
"
);
return
0
;
}
}
if
(
verb
)
cout
<<
"(init): listen "
<<
addr
<<
":"
<<
port
<<
endl
;
DebugStream
log
;
LogServer
ls
(
log
);
ls
.
run
(
addr
,
port
,
true
);
char
buf
[
10000
];
while
(
true
)
{
size_t
r
=
read
(
0
,
buf
,
sizeof
(
buf
)
-
1
);
if
(
r
>
0
)
{
buf
[
r
]
=
'\0'
;
log
<<
buf
;
}
}
}
char
buf
[
10000
];
while
(
true
)
{
size_t
r
=
read
(
fileno
(
stdin
)
,
buf
,
sizeof
(
buf
)
-
1
);
if
(
r
>
0
)
{
buf
[
r
]
=
'\0'
;
log
<<
buf
;
}
}
}
catch
(
SystemError
&
err
)
{
cerr
<<
"(log-stdin): "
<<
err
<<
endl
;
return
1
;
return
1
;
}
catch
(
Exception
&
ex
)
{
cerr
<<
"(log-stdin): "
<<
ex
<<
endl
;
return
1
;
cerr
<<
"(log-stdin): "
<<
ex
<<
endl
;
return
1
;
}
catch
(...)
{
cerr
<<
"(log-stdin): catch(...)"
<<
endl
;
return
1
;
cerr
<<
"(log-stdin): catch(...)"
<<
endl
;
return
1
;
}
return
0
;
}
// --------------------------------------------------------------------------
Utilities/ULog/log-wrap.cc
View file @
41cba1cc
...
...
@@ -16,107 +16,105 @@ using namespace std;
// -------------------------------------------------------------------------
static
void
print_help
()
{
printf
(
"
\n
"
);
printf
(
"Usage: uniset2-logserver-wrap listen-addr listen-port PROGRAMM ARGS..
\n
"
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
printf
(
"Usage: uniset2-logserver-wrap listen-addr listen-port PROGRAMM ARGS..
\n
"
);
printf
(
"
\n
"
);
}
// --------------------------------------------------------------------------
int
main
(
int
argc
,
char
*
argv
[],
char
*
envp
[]
)
{
if
(
argc
<
4
)
{
print_help
();
return
1
;
}
string
addr
(
argv
[
1
]);
int
port
=
atoi
(
argv
[
2
]);
if
(
argc
<
4
)
{
print_help
();
return
1
;
}
string
addr
(
argv
[
1
]);
int
port
=
atoi
(
argv
[
2
]);
int
pid
;
int
cp
[
2
];
/* Child to parent pipe */
if
(
pipe
(
cp
)
<
0
)
{
perror
(
"Can't make pipe"
);
exit
(
1
);
}
try
{
/* Create a child to run command. */
switch
(
pid
=
fork
()
)
{
case
-
1
:
{
perror
(
"Can't fork"
);
exit
(
1
);
}
case
0
:
{
/* Child. */
close
(
cp
[
0
]);
int
pid
;
int
cp
[
2
];
/* Child to parent pipe */
if
(
pipe
(
cp
)
<
0
)
{
perror
(
"Can't make pipe"
);
exit
(
1
);
}
try
{
switch
(
pid
=
fork
()
)
{
case
-
1
:
{
perror
(
"Can't fork"
);
exit
(
1
);
}
case
0
:
{
/* Child. */
close
(
cp
[
0
]);
close
(
fileno
(
stderr
)
);
//close stderr
dup2
(
fileno
(
stdout
),
fileno
(
stderr
));
close
(
fileno
(
stdout
)
);
dup2
(
cp
[
1
],
fileno
(
stdout
));
close
(
fileno
(
stdout
));
/* Close current stdout. */
dup2
(
cp
[
1
],
fileno
(
stdout
));
/* Make stdout go to write end of pipe. */
close
(
fileno
(
stderr
)
);
dup2
(
fileno
(
stdout
),
fileno
(
stderr
));
execvpe
(
argv
[
3
],
argv
+
3
,
envp
);
perror
(
"No exec"
);
kill
(
getppid
(),
SIGQUIT
);
exit
(
1
);
}
break
;
execvpe
(
argv
[
3
],
argv
+
3
,
envp
);
perror
(
"No exec"
);
kill
(
getppid
(),
SIGQUIT
);
exit
(
1
);
}
break
;
default:
{
/* Parent. */
close
(
cp
[
1
]);
default:
{
/* Parent. */
close
(
cp
[
1
]);
DebugStream
zlog
;
zlog
.
addLevel
(
Debug
::
ANY
);
DebugStream
zlog
;
zlog
.
addLevel
(
Debug
::
ANY
);
LogServer
ls
(
zlog
);
cout
<<
"wrap: server "
<<
addr
<<
":"
<<
port
<<
endl
;
ls
.
run
(
addr
,
port
,
true
);
char
buf
[
5000
];
while
(
true
)
{
ssize_t
r
=
read
(
cp
[
0
],
&
buf
,
sizeof
(
buf
)
-
1
);
if
(
r
>
0
)
{
cout
<<
"***READ**"
<<
endl
;
buf
[
r
]
=
'\0'
;
zlog
<<
buf
;
}
}
exit
(
0
);
}
break
;
}
}
LogServer
ls
(
zlog
);
cout
<<
"wrap: server "
<<
addr
<<
":"
<<
port
<<
endl
;
ls
.
run
(
addr
,
port
,
true
);
char
buf
[
5000
];
while
(
true
)
{
ssize_t
r
=
read
(
cp
[
0
],
&
buf
,
sizeof
(
buf
)
-
1
);
if
(
r
>
0
)
{
buf
[
r
]
=
'\0'
;
zlog
<<
buf
;
}
}
exit
(
0
);
}
break
;
}
}
catch
(
SystemError
&
err
)
{
cerr
<<
"(logserver-wrap): "
<<
err
<<
endl
;
return
1
;
return
1
;
}
catch
(
Exception
&
ex
)
{
cerr
<<
"(logserver-wrap): "
<<
ex
<<
endl
;
return
1
;
return
1
;
}
catch
(...)
{
cerr
<<
"(logserver-wrap): catch(...)"
<<
endl
;
return
1
;
return
1
;
}
return
0
;
}
// --------------------------------------------------------------------------
Utilities/ULog/logserver.cc
View file @
41cba1cc
...
...
@@ -82,17 +82,17 @@ int main( int argc, char **argv )
}
DebugStream
dlog
;
dlog
.
setLogName
(
"dlog"
);
DebugStream
dlog
;
dlog
.
setLogName
(
"dlog"
);
DebugStream
dlog2
;
dlog2
.
setLogName
(
"dlog2"
);
dlog2
.
setLogName
(
"dlog2"
);
LogAgregator
la
;
la
.
add
(
dlog
);
la
.
add
(
dlog2
);
LogAgregator
la
;
la
.
add
(
dlog
);
la
.
add
(
dlog2
);
LogServer
ls
(
la
);
//
LogServer ls(cout);
//
LogServer ls(cout);
dlog
.
addLevel
(
Debug
::
ANY
);
dlog2
.
addLevel
(
Debug
::
ANY
);
...
...
@@ -101,16 +101,16 @@ int main( int argc, char **argv )
unsigned
int
i
=
0
;
while
(
true
)
{
dlog
<<
"["
<<
++
i
<<
"] Test message for log"
<<
endl
;
dlog
.
info
()
<<
": dlog : INFO message"
<<
endl
;
dlog
.
warn
()
<<
": dlog : WARN message"
<<
endl
;
dlog
.
crit
()
<<
": dlog : CRIT message"
<<
endl
;
dlog
<<
"["
<<
++
i
<<
"] Test message for log"
<<
endl
;
dlog
.
info
()
<<
": dlog : INFO message"
<<
endl
;
dlog
.
warn
()
<<
": dlog : WARN message"
<<
endl
;
dlog
.
crit
()
<<
": dlog : CRIT message"
<<
endl
;
dlog2
.
info
()
<<
": dlog2: INFO message"
<<
endl
;
dlog2
.
warn
()
<<
": dlog2: WARN message"
<<
endl
;
dlog2
.
crit
()
<<
": dlog2: CRIT message"
<<
endl
;
msleep
(
delay
);
dlog2
.
info
()
<<
": dlog2: INFO message"
<<
endl
;
dlog2
.
warn
()
<<
": dlog2: WARN message"
<<
endl
;
dlog2
.
crit
()
<<
": dlog2: CRIT message"
<<
endl
;
msleep
(
delay
);
}
}
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