FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
netdata/python.d/python_modules/msg.py at master · srve4/netdata · GitHub
srve4
/
netdata
Public
forked from
netdata/netdata
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
netdata
/
python.d
/
python_modules
/
msg.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
74 lines (59 loc) · 1.49 KB
Breadcrumbs
netdata
/
python.d
/
python_modules
/
msg.py
Copy path
File metadata and controls
74 lines (59 loc) · 1.49 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
# -*- coding: utf-8 -*-
# Description: logging for netdata python.d modules
import
sys
from
time
import
time
,
strftime
DEBUG_FLAG
=
False
PROGRAM
=
""
LOG_COUNTER
=
2
LOG_INTERVAL
=
5
NEXT_CHECK
=
0
WRITE
=
sys
.
stderr
.
write
FLUSH
=
sys
.
stderr
.
flush
def
log_msg
(
msg_type
,
*
args
):
"""
Print message on stderr.
:param msg_type: str
"""
global
LOG_COUNTER
if
not
DEBUG_FLAG
:
LOG_COUNTER
-=
1
now
=
time
()
if
LOG_COUNTER
>=
0
:
timestamp
=
strftime
(
'%y-%m-%d %X'
)
msg
=
"%s: %s %s: %s"
%
(
timestamp
,
PROGRAM
,
str
(
msg_type
),
" "
.
join
(
args
))
WRITE
(
msg
+
"
\n
"
)
FLUSH
()
global
NEXT_CHECK
if
NEXT_CHECK
<=
now
:
NEXT_CHECK
=
now
-
(
now
%
LOG_INTERVAL
)
+
LOG_INTERVAL
if
LOG_COUNTER
<
0
:
timestamp
=
strftime
(
'%y-%m-%d %X'
)
msg
=
"%s: Prevented %s log messages from displaying"
%
(
timestamp
,
str
(
0
-
LOG_COUNTER
))
WRITE
(
msg
+
"
\n
"
)
FLUSH
()
def
debug
(
*
args
):
"""
Print debug message on stderr.
"""
if
not
DEBUG_FLAG
:
return
log_msg
(
"DEBUG"
,
*
args
)
def
error
(
*
args
):
"""
Print message on stderr.
"""
log_msg
(
"ERROR"
,
*
args
)
def
info
(
*
args
):
"""
Print message on stderr.
"""
log_msg
(
"INFO"
,
*
args
)
def
fatal
(
*
args
):
"""
Print message on stderr and exit.
"""
log_msg
(
"FATAL"
,
*
args
)
# using sys.stdout causes IOError: Broken Pipe
print
(
'DISABLE'
)
# sys.stdout.write('DISABLE\n')
sys
.
exit
(
1
)
Back
|
FazBrowse Home
|
New Git URL