Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NP_TMcode
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Giacomo Mulas
NP_TMcode
Commits
ae30603d
Commit
ae30603d
authored
1 year ago
by
Giovanni La Mura
Browse files
Options
Downloads
Patches
Plain Diff
Introduce a Logger class
parent
fa52eab5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/include/logging.h
+47
-0
47 additions, 0 deletions
src/include/logging.h
src/libnptm/logging.cpp
+27
-0
27 additions, 0 deletions
src/libnptm/logging.cpp
with
74 additions
and
0 deletions
src/include/logging.h
0 → 100644
+
47
−
0
View file @
ae30603d
/* Distributed under the terms of GPLv3 or later. See COPYING for details. */
/*! \file logging.h
*
* \brief Definition of the logging system.
*/
#ifndef INCLUDE_LOGGING_H_
#define INCLUDE_LOGGING_H_
#define LOG_DEBG 0
#define LOG_INFO 1
#define LOG_WARN 2
#define LOG_ERRO 3
/*! \brief Logger class.
*
* Loggers are objects used to track the execution of a code, reporting activities
* such as function calls and parameter settings. They can be used to inform the
* user about the execution of operations at runtime (e.g. by printing messages to
* the terminal), as well as to record the execution history in appropriate log
* files. The `Logger` class offers an implementation of logging system complying
* with the requirements of the NP_TMcode project.
*/
class
Logger
{
protected:
FILE
*
log_output
;
FILE
*
err_output
;
int
log_threshold
;
public:
/*! \brief Logger instance constructor.
*
* \param threshold: `int` Threshold of the messages to be included in log. Can
* be `LOG_DEBG` (log everything), `LOG_INFO` (give detailed information),
* `LOG_WARN` (log odd looking effects), or `LOG_ERRO` (print error messages,
* `always active). The default behaviour is `LOG_WARN`.
* \param logging_output: `FILE *` Pointer to an output file for common messages
* (optional, default is `stdout`).
* \param error_output: `FILE *` Pointer to an output file for error messages
* (optional, default is `stderr`).
*/
Logger
(
int
threshold
,
FILE
*
logging_output
=
std
::
stdout
,
FILE
*
error_output
=
std
::
stderr
);
log
(
std
::
string
message
,
int
level
);
};
#endif
This diff is collapsed.
Click to expand it.
src/libnptm/logging.cpp
0 → 100644
+
27
−
0
View file @
ae30603d
/* Distributed under the terms of GPLv3 or later. See COPYING for details. */
/*! \file logging.cpp
*
* \brief Implementation of the logging system.
*/
#include
<cstdio>
#include
<string>
#ifndef INCLUDE_LOGGING_H_
#include
"../include/logging.h"
#endif
using
namespace
std
;
Logger
::
Logger
(
int
threshold
,
FILE
*
logging_output
,
FILE
*
error_output
)
{
log_threshold
=
threshold
;
log_output
=
logging_output
;
err_output
=
error_output
;
}
Logger
::
log
(
std
::
string
message
,
int
level
)
{
if
(
level
==
LOG_ERRO
)
err
(
message
);
else
{
if
(
level
>=
log_threshold
)
fprintf
(
log_output
,
message
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment