Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
David Thompson
SMTK
Commits
5c50ab77
Commit
5c50ab77
authored
Oct 08, 2013
by
Bob Obara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ENH:Added Logger Class and Test
parent
7ae31465
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
251 additions
and
2 deletions
+251
-2
smtk/CMakeLists.txt
smtk/CMakeLists.txt
+5
-2
smtk/util/CMakeLists.txt
smtk/util/CMakeLists.txt
+17
-0
smtk/util/Logger.cxx
smtk/util/Logger.cxx
+64
-0
smtk/util/Logger.h
smtk/util/Logger.h
+105
-0
smtk/util/Testing/CMakeLists.txt
smtk/util/Testing/CMakeLists.txt
+5
-0
smtk/util/Testing/loggerTest.cxx
smtk/util/Testing/loggerTest.cxx
+55
-0
No files found.
smtk/CMakeLists.txt
View file @
5c50ab77
...
...
@@ -6,8 +6,11 @@ smtk_source_group(attribute)
add_subdirectory
(
model
)
smtk_source_group
(
model
)
set
(
smtk_headers
${
attributeHeaders
}
${
modelHeaders
}
)
set
(
smtk_srcs
${
attributeSrcs
}
${
modelSrcs
}
)
add_subdirectory
(
util
)
smtk_source_group
(
util
)
set
(
smtk_headers
${
attributeHeaders
}
${
modelHeaders
}
${
utilHeaders
}
)
set
(
smtk_srcs
${
attributeSrcs
}
${
modelSrcs
}
${
utilSrcs
}
)
add_library
(
SMTKCore
${
smtk_srcs
}
)
smtk_export_header
(
SMTKCore SMTKCoreExports.h
)
...
...
smtk/util/CMakeLists.txt
0 → 100644
View file @
5c50ab77
project
(
SMTK_Util
)
# set up sources to build
set
(
utilSrcs
Logger.cxx
)
set
(
utilHeaders
Logger.h
)
#install the headers
smtk_public_headers
(
${
utilHeaders
}
)
if
(
SMTK_ENABLE_TESTING
)
add_subdirectory
(
Testing
)
endif
(
SMTK_ENABLE_TESTING
)
smtk/util/Logger.cxx
0 → 100644
View file @
5c50ab77
/*=========================================================================
Copyright (c) 1998-2013 Kitware Inc. 28 Corporate Drive,
Clifton Park, NY, 12065, USA.
All rights reserved. No part of this software may be reproduced, distributed,
or modified, in any form or by any means, without permission in writing from
Kitware Inc.
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN
"AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
PROVIDE
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
=========================================================================*/
#include "smtk/util/Logger.h"
using
namespace
smtk
::
util
;
//----------------------------------------------------------------------------
void
Logger
::
addRecord
(
Severity
s
,
const
std
::
string
&
m
,
const
std
::
string
&
fname
,
unsigned
int
line
)
{
if
((
s
==
Logger
::
ERROR
)
||
(
s
==
Logger
::
FATAL
))
{
this
->
m_hasErrors
=
true
;
}
this
->
m_records
.
push_back
(
Record
(
s
,
m
,
fname
,
line
));
}
//----------------------------------------------------------------------------
void
Logger
::
reset
()
{
this
->
m_hasErrors
=
false
;
this
->
m_records
.
empty
();
}
//----------------------------------------------------------------------------
std
::
string
Logger
::
severityAsString
(
Severity
s
)
{
switch
(
s
)
{
case
DEBUG
:
return
"DEBUG"
;
case
INFO
:
return
"INFO"
;
case
WARNING
:
return
"WARNING"
;
case
ERROR
:
return
"ERROR"
;
case
FATAL
:
return
"FATAL"
;
default:
return
"UNKNOWN"
;
}
return
"UNKNOWN"
;
}
smtk/util/Logger.h
0 → 100644
View file @
5c50ab77
/*=========================================================================
Copyright (c) 1998-2013 Kitware Inc. 28 Corporate Drive,
Clifton Park, NY, 12065, USA.
All rights reserved. No part of this software may be reproduced, distributed,
or modified, in any form or by any means, without permission in writing from
Kitware Inc.
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN
"AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
PROVIDE
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
=========================================================================*/
// .NAME Logger.h -
// .SECTION Description
// .SECTION See Also
#ifndef __smtk_util_Logger_h
#define __smtk_util_Logger_h
#include "smtk/SMTKCoreExports.h"
#include <string>
#include <sstream>
#include <vector>
#define smtkErrorMacro(logger, x) do { \
std::stringstream s1; \
s1 << x << std::endl; \
logger.addRecord(smtk::util::Logger::ERROR, \
s1.str(), __FILE__, __LINE__); \
} while (0)
#define smtkWarningMacro(logger, x) do { \
std::stringstream s1; \
s1 << x << std::endl; \
logger.addRecord(smtk::util::Logger::WARNING, \
s1.str(), __FILE__, __LINE__); \
} while (0)
#define smtkDebugMacro(logger, x) do { \
std::stringstream s1; \
s1 << x << std::endl; \
logger.addRecord(smtk::util::Logger::DEBUG, \
s1.str(), __FILE__, __LINE__); \
} while (0)
namespace
smtk
{
namespace
util
{
class
SMTKCORE_EXPORT
Logger
{
public:
enum
Severity
{
DEBUG
,
INFO
,
WARNING
,
ERROR
,
FATAL
};
struct
Record
{
Severity
severity
;
std
::
string
message
;
std
::
string
fileName
;
unsigned
int
lineNumber
;
Record
(
Severity
s
,
const
std
::
string
&
m
,
const
std
::
string
&
f
=
""
,
unsigned
int
l
=
0
)
:
severity
(
s
),
message
(
m
),
fileName
(
f
),
lineNumber
(
l
)
{}
Record
()
:
severity
(
INFO
),
lineNumber
(
0
)
{}
};
Logger
()
:
m_hasErrors
(
false
)
{}
std
::
size_t
numberOfRecords
()
const
{
return
this
->
m_records
.
size
();}
bool
hasErrors
()
const
{
return
this
->
m_hasErrors
;}
void
addRecord
(
Severity
s
,
const
std
::
string
&
m
,
const
std
::
string
&
fname
=
""
,
unsigned
int
line
=
0
);
const
Record
&
record
(
int
i
)
const
{
return
this
->
m_records
[
i
];}
void
reset
();
static
std
::
string
severityAsString
(
Severity
s
);
protected:
std
::
vector
<
Record
>
m_records
;
bool
m_hasErrors
;
private:
};
};
};
#endif
/* __smtk_util_Logger_h */
smtk/util/Testing/CMakeLists.txt
0 → 100644
View file @
5c50ab77
add_executable
(
loggerTest loggerTest.cxx
)
target_link_libraries
(
loggerTest SMTKCore
)
add_test
(
loggerTest
${
EXECUTABLE_OUTPUT_PATH
}
/loggerTest
)
smtk/util/Testing/loggerTest.cxx
0 → 100644
View file @
5c50ab77
/*=========================================================================
Copyright (c) 1998-2013 Kitware Inc. 28 Corporate Drive,
Clifton Park, NY, 12065, USA.
All rights reserved. No part of this software may be reproduced, distributed,
or modified, in any form or by any means, without permission in writing from
Kitware Inc.
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN
"AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
PROVIDE
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
=========================================================================*/
// .NAME Logger.h -
// .SECTION Description
// .SECTION See Also
#include "smtk/util/Logger.h"
#include <iostream>
int
main
()
{
smtk
::
util
::
Logger
logger
;
smtkErrorMacro
(
logger
,
"this is an error no = "
<<
45
<<
" ERROR!"
);
smtkWarningMacro
(
logger
,
"this is a warning no = "
<<
10.1234
<<
" WARNING!"
);
smtkDebugMacro
(
logger
,
"this is a Debug no = "
<<
1
<<
" DEBUG!"
);
logger
.
addRecord
(
smtk
::
util
::
Logger
::
INFO
,
"Sample Info String
\n
"
);
int
i
,
n
=
logger
.
numberOfRecords
();
if
(
n
!=
4
)
{
std
::
cerr
<<
"Wrong number of records! Got "
<<
n
<<
" Should be 4!
\n
"
;
return
-
1
;
}
smtk
::
util
::
Logger
::
Record
r
;
for
(
i
=
0
;
i
<
n
;
i
++
)
{
r
=
logger
.
record
(
i
);
std
::
cerr
<<
" Record "
<<
i
<<
":
\n\t
Severity = "
<<
smtk
::
util
::
Logger
::
severityAsString
(
r
.
severity
)
<<
"
\n\t
Message = "
<<
r
.
message
<<
"
\t
File = "
<<
r
.
fileName
<<
"
\n\t
Line = "
<<
r
.
lineNumber
<<
std
::
endl
;
}
return
0
;
}
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