Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
osv
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Verlässliche Systemsoftware
projects
osv
Commits
8eb501da
Commit
8eb501da
authored
12 years ago
by
Guy Zana
Browse files
Options
Downloads
Patches
Plain Diff
Added a logger that filters log messages using tags and severity (debug,info,warn,error)
parent
2c60606b
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
core/debug.cc
+76
-11
76 additions, 11 deletions
core/debug.cc
include/debug.hh
+42
-7
42 additions, 7 deletions
include/debug.hh
with
118 additions
and
18 deletions
core/debug.cc
+
76
−
11
View file @
8eb501da
...
...
@@ -7,19 +7,78 @@
using
namespace
std
;
Debug
*
Debug
::
p
instance
=
0
;
logger
*
logger
::
_
instance
=
nullptr
;
extern
"C"
{
logger
::
logger
()
{
this
->
parse_configuration
();
}
void
debug
(
const
char
*
msg
)
logger
::~
logger
(
)
{
console
::
write
(
msg
,
strlen
(
msg
),
true
);
}
void
debug_write
(
const
char
*
msg
,
size_t
len
)
bool
logger
::
parse_configuration
(
void
)
{
console
::
write
(
msg
,
len
,
false
);
// FIXME: read configuration from a file
add_tag
(
"virtio-blk"
,
logger_error
);
add_tag
(
"pci"
,
logger_info
);
return
(
true
);
}
void
logger
::
add_tag
(
const
char
*
tag
,
logger_severity
severity
)
{
auto
it
=
_log_level
.
find
(
tag
);
if
(
it
!=
_log_level
.
end
())
{
_log_level
.
erase
(
it
);
}
_log_level
.
insert
(
make_pair
(
tag
,
severity
));
}
logger
::
logger_severity
logger
::
get_tag
(
const
char
*
tag
)
{
auto
it
=
_log_level
.
find
(
tag
);
if
(
it
==
_log_level
.
end
())
{
return
(
logger_error
);
}
return
(
it
->
second
);
}
bool
logger
::
is_filtered
(
const
char
*
tag
,
logger_severity
severity
)
{
logger_severity
configured_severity
=
this
->
get_tag
(
tag
);
if
(
configured_severity
==
logger_none
)
{
return
(
true
);
}
if
(
severity
<
configured_severity
)
{
return
(
true
);
}
return
(
false
);
}
void
logger
::
log
(
const
char
*
tag
,
logger_severity
severity
,
const
boost
::
format
&
_fmt
)
{
if
(
this
->
is_filtered
(
tag
,
severity
))
{
return
;
}
debug
(
fmt
(
"[%s]: "
)
%
tag
,
false
);
debug
(
_fmt
,
true
);
}
void
logger
::
log
(
const
char
*
tag
,
logger_severity
severity
,
const
char
*
_fmt
,
...)
{
if
(
this
->
is_filtered
(
tag
,
severity
))
{
return
;
}
// FIXME: implement...
}
void
debug
(
std
::
string
str
,
bool
lf
)
...
...
@@ -32,10 +91,16 @@ void debug(const boost::format& fmt, bool lf)
debug
(
fmt
.
str
(),
lf
);
}
extern
"C"
{
/*std::ostream& operator<<(std::ostream& os, const aa& a)
{
os <<"print stream func " << a.geta() << " " << a.getname();
void
debug
(
const
char
*
msg
)
{
console
::
write
(
msg
,
strlen
(
msg
),
true
);
}
void
debug_write
(
const
char
*
msg
,
size_t
len
)
{
console
::
write
(
msg
,
len
,
false
);
}
return os;
}*/
}
This diff is collapsed.
Click to expand it.
include/debug.hh
+
42
−
7
View file @
8eb501da
...
...
@@ -2,23 +2,58 @@
#define DEBUG_H
#include
<iostream>
#include
<map>
#include
<string>
#include
"boost/format.hpp"
typedef
boost
::
format
fmt
;
class
IsaSerialConsole
;
class
Debug
{
class
logger
{
public:
//friend std::ostream& operator<<(std::ostream&, const aa&);
static
Debug
*
Instance
()
{
return
(
pinstance
)
?
pinstance
:
(
pinstance
=
new
Debug
);};
enum
logger_severity
{
logger_debug
=
0
,
logger_info
=
1
,
logger_warn
=
2
,
logger_error
=
3
,
// Suppress output, even errors
logger_none
=
4
};
logger
();
virtual
~
logger
();
static
logger
*
instance
()
{
if
(
_instance
==
nullptr
)
{
_instance
=
new
logger
();
}
return
(
_instance
);
}
//
// Interface for logging, these functions checks the filters and
// calls the underlying debug functions.
//
void
log
(
const
char
*
tag
,
logger_severity
severity
,
const
boost
::
format
&
_fmt
);
void
log
(
const
char
*
tag
,
logger_severity
severity
,
const
char
*
_fmt
,
...);
private
:
Debug
()
{
Debug
::
pinstance
=
0
;};
Debug
(
const
Debug
&
d
)
{};
Debug
&
operator
=
(
const
Debug
&
d
)
{
pinstance
=
d
.
pinstance
;
return
*
pinstance
;};
static
logger
*
_instance
;
bool
parse_configuration
(
void
);
bool
is_filtered
(
const
char
*
tag
,
logger_severity
severity
);
// Adds a tag, if it exists then modify severity
void
add_tag
(
const
char
*
tag
,
logger_severity
severity
);
// Returns severity, per tag, if doesn't exist return error as default
logger_severity
get_tag
(
const
char
*
tag
);
std
::
map
<
std
::
string
,
logger_severity
>
_log_level
;
static
Debug
*
pinstance
;
};
extern
"C"
{
void
debug
(
const
char
*
msg
);
}
...
...
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