mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
tests: add timestamp to kernel line
Parse timestamps included in kernel kmsg line and add current system time to the messsage as well - this makes it easier to look over, when chasing some messages in journal after some time...
This commit is contained in:
parent
08888d57cb
commit
b120b2932d
@ -710,14 +710,35 @@ struct KMsg : Source {
|
|||||||
return fd >= 0;
|
return fd >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void transform( char *buf, ssize_t *sz ) {
|
||||||
|
char newbuf[ buffer_size ];
|
||||||
|
struct tm time_info;
|
||||||
|
unsigned level, num, pos;
|
||||||
|
unsigned long t;
|
||||||
|
time_t tt;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
if (sscanf( buf, "%u,%u,%lu,-;%n", &level, &num, &t, &pos ) == 3) {
|
||||||
|
memcpy( newbuf, buf, *sz );
|
||||||
|
tt = time( 0 );
|
||||||
|
len = snprintf( buf, 64, "[%lu.%06lu] <%u> ", t / 1000000, t % 1000000, level );
|
||||||
|
if ( localtime_r( &tt, &time_info ) )
|
||||||
|
len += strftime( buf + len, 64, "%F %T ", &time_info );
|
||||||
|
memcpy( buf + len, newbuf + pos, *sz - pos );
|
||||||
|
*sz = *sz - pos + len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void sync( Sink *s ) {
|
void sync( Sink *s ) {
|
||||||
#ifdef __unix
|
#ifdef __unix
|
||||||
ssize_t sz;
|
ssize_t sz;
|
||||||
char buf[ buffer_size ];
|
char buf[ buffer_size ];
|
||||||
|
|
||||||
if ( dev_kmsg() ) {
|
if ( dev_kmsg() ) {
|
||||||
while ( (sz = ::read(fd, buf, buffer_size)) > 0 )
|
while ( (sz = ::read( fd, buf, buffer_size ) ) > 0 ) {
|
||||||
|
transform( buf, &sz );
|
||||||
s->push( std::string( buf, sz ) );
|
s->push( std::string( buf, sz ) );
|
||||||
|
}
|
||||||
} else if ( can_clear ) {
|
} else if ( can_clear ) {
|
||||||
while ( ( sz = klogctl( BRICK_SYSLOG_ACTION_READ_CLEAR, buf,
|
while ( ( sz = klogctl( BRICK_SYSLOG_ACTION_READ_CLEAR, buf,
|
||||||
( int) buffer_size ) ) > 0 )
|
( int) buffer_size ) ) > 0 )
|
||||||
|
Loading…
Reference in New Issue
Block a user