/
trace_logger.cc
70 lines (53 loc) · 1.46 KB
/
trace_logger.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// This file is part of khmer, http://github.com/ged-lab/khmer/, and is
// Copyright (C) Michigan State University, 2009-2013. It is licensed under
// the three-clause BSD license; see LICENSE.
// Contact: khmer-project@idyll.org
//
#include <fcntl.h>
#include "trace_logger.hh"
#include "khmer_exception.hh"
namespace khmer
{
#ifdef WITH_INTERNAL_TRACING
TraceLogger::
TraceLogger( uint8_t const level, FILE * stream_handle )
: _level( level ), _shared_stream( true ), _stream_handle( stream_handle )
{
if( !(NULL != stream_handle) ) {
throw khmer_exception();
}
}
#endif
TraceLogger::
TraceLogger( uint8_t const level, char const * const file_name_format, ... )
#ifdef WITH_INTERNAL_TRACING
: _level( level ), _shared_stream( false )
{
char tfile_name[ FILENAME_MAX + 1 ];
va_list varargs;
va_start( varargs, file_name_format );
vsnprintf( tfile_name, FILENAME_MAX, file_name_format, varargs );
va_end( varargs );
_stream_handle = fopen( tfile_name, "w" );
if (NULL == _stream_handle) {
throw InvalidStreamBuffer( );
}
}
#else // WITH_INTERNAL_TRACING
{ }
#endif // !WITH_INTERNAL_TRACING
TraceLogger::
~TraceLogger( )
#ifdef WITH_INTERNAL_TRACING
{
if ((!_shared_stream) && (NULL != _stream_handle)) {
fclose( _stream_handle );
_stream_handle = NULL;
}
}
#else // WITH_INTERNAL_TRACING
{ }
#endif // !WITH_INTENRAL_TRACING
} // namespace khmer
// vim: set ft=cpp sts=4 sw=4 tw=80: