FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ArduinoSimpleLogging/src/ArduinoSimpleLogging.cpp at master · janLo/ArduinoSimpleLogging · GitHub
janLo
/
ArduinoSimpleLogging
Public
Notifications
You must be signed in to change notification settings
Fork
2
Star
5
Code
Issues
1
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
ArduinoSimpleLogging
/
src
/
ArduinoSimpleLogging.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
95 lines (82 loc) · 2.44 KB
Breadcrumbs
ArduinoSimpleLogging
/
src
/
ArduinoSimpleLogging.cpp
Copy path
File metadata and controls
95 lines (82 loc) · 2.44 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
*
* ArduinoSimpleLogging
*
* https://github.com/janLo/ArduinoSimpleLogging
*
* Copyright (c) 2017 Jan Losinski.
* MIT License
*/
#
include
"
ArduinoSimpleLogging.h
"
size_t
ArduinoSimpleLogging::LogTarget::write
(
uint8_t
byte) {
return
Logger.
log
(_level, byte);
}
size_t
ArduinoSimpleLogging::LogTarget::write
(
const
uint8_t
*buffer,
size_t
size) {
return
Logger.
log
(_level, buffer, size);
}
size_t
ArduinoSimpleLogging::log
(ArduinoSimpleLogging::Level level,
const
uint8_t
*buffer,
size_t
size) {
for
(
auto
&handler : handlers) {
if
((handler.
mask
& level) !=
0
) {
handler.
stream
.
write
(buffer, size);
}
}
return
size;
}
size_t
ArduinoSimpleLogging::log
(ArduinoSimpleLogging::Level level,
uint8_t
byte) {
for
(
auto
&handler : handlers) {
if
((handler.
mask
& level) !=
0
) {
handler.
stream
.
write
(byte);
}
}
return
1
;
}
uint8_t
ArduinoSimpleLogging::LogHandler::makeMask
(
const
ArduinoSimpleLogging::Level level) {
uint8_t
mask =
0x0
;
while
(mask < level) {
mask = (mask <<
1
) | (
uint8_t
)
0x01
;
}
return
mask;
}
void
ArduinoSimpleLogging::addHandler
(ArduinoSimpleLogging::Level level,
Print &stream) {
removeHandler
(stream);
handlers.
emplace_front
(level, stream);
}
void
ArduinoSimpleLogging::removeHandler
(Print &stream) {
handlers.
remove_if
([&stream](
const
LogHandler &handler) {
return
&(handler.
stream
) == &stream;
});
}
String
ArduinoSimpleLogging::levelToString
(ArduinoSimpleLogging::Level level) {
switch
(level) {
case
ERROR
:
return
F
(
"
error
"
);
case
WARNING
:
return
F
(
"
warning
"
);
case
INFO
:
return
F
(
"
info
"
);
case
DEBUG
:
return
F
(
"
debug
"
);
}
return
F
(
"
debug
"
);
}
ArduinoSimpleLogging::Level
ArduinoSimpleLogging::stringToLevel
(
const
String &levelName) {
if
(levelName.
equalsIgnoreCase
(
F
(
"
error
"
))) {
return
ERROR
;
}
else
if
(levelName.
equalsIgnoreCase
(
F
(
"
warning
"
))) {
return
WARNING
;
}
else
if
(levelName.
equalsIgnoreCase
(
F
(
"
info
"
))) {
return
INFO
;
}
else
{
return
DEBUG
;
}
}
ArduinoSimpleLogging Logger;
ArduinoSimpleLogging::LogTarget
ArduinoSimpleLogging::debug
(
DEBUG
);
ArduinoSimpleLogging::LogTarget
ArduinoSimpleLogging::info
(
INFO
);
ArduinoSimpleLogging::LogTarget
ArduinoSimpleLogging::warning
(
WARNING
);
ArduinoSimpleLogging::LogTarget
ArduinoSimpleLogging::error
(
ERROR
);
Back
|
FazBrowse Home
|
New Git URL