in common/daemon.h [92:127]
void write_log( const char* message )
{
const int max_log_len = 10 * 1024 * 1024; // 10 MB
int fd = open( "/var/credentials-fetcher/logging/credentials-fetcher.log", O_RDWR );
struct stat st;
if ( fstat( fd, &st ) < 0 )
{
perror( "fstat" );
close( fd );
FILE* fp = fopen( "/var/credentials-fetcher/logging/credentials-fetcher.log", "w" );
fclose( fp );
fd = open( "/var/credentials-fetcher/logging/credentials-fetcher.log", O_RDWR );
}
else if ( st.st_size > max_log_len )
{
close( fd );
FILE* fp = fopen( "/var/credentials-fetcher/logging/credentials-fetcher.log", "w" );
fclose( fp );
fd = open( "/var/credentials-fetcher/logging/credentials-fetcher.log", O_RDWR );
}
FILE* fp = fdopen( fd, "a+" );
if ( fp != NULL )
{
time_t current_time = time( NULL );
struct tm* local_time = localtime( ¤t_time );
char time_buffer[80];
strftime( time_buffer, 80, "%Y-%m-%d %H:%M:%S", local_time );
fprintf( fp, "%s: %s \n", time_buffer, message );
fclose( fp );
}
std::string log_buf = std::string( message );
log_ring_buffer[log_buffer_count] = log_buf;
log_buffer_count = ( log_buffer_count + 1 ) % MAX_LOG_BUFFER_COUNT;
close( fd );
}