Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nemu3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
nemu3
Commits
39a92658
Commit
39a92658
authored
Sep 01, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Logging functions
parent
5d45f21d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
1 deletion
+65
-1
src/netns/environ.py
src/netns/environ.py
+65
-1
No files found.
src/netns/environ.py
View file @
39a92658
# vim:ts=4:sw=4:et:ai:sts=4
# vim:ts=4:sw=4:et:ai:sts=4
import
os
,
subprocess
import
os
,
os
.
path
,
subprocess
,
sys
,
syslog
from
syslog
import
LOG_ERR
,
LOG_WARNING
,
LOG_NOTICE
,
LOG_INFO
,
LOG_DEBUG
__all__
=
[
"ip_path"
,
"tc_path"
,
"brctl_path"
,
"sysctl_path"
,
"hz"
]
__all__
=
[
"ip_path"
,
"tc_path"
,
"brctl_path"
,
"sysctl_path"
,
"hz"
]
__all__
+=
[
"tcpdump_path"
,
"netperf_path"
]
__all__
+=
[
"tcpdump_path"
,
"netperf_path"
]
__all__
+=
[
"execute"
,
"backticks"
]
__all__
+=
[
"execute"
,
"backticks"
]
__all__
+=
[
"LOG_ERR"
,
"LOG_WARNING"
,
"LOG_NOTICE"
,
"LOG_INFO"
,
"LOG_DEBUG"
]
__all__
+=
[
"set_log_level"
,
"logger"
]
__all__
+=
[
"error"
,
"warning"
,
"notice"
,
"info"
,
"debug"
]
def
find_bin
(
name
,
extra_path
=
None
):
def
find_bin
(
name
,
extra_path
=
None
):
search
=
[]
search
=
[]
...
@@ -68,3 +72,63 @@ def backticks(cmd):
...
@@ -68,3 +72,63 @@ def backticks(cmd):
raise
RuntimeError
(
"Error executing `%s': %s"
%
(
" "
.
join
(
cmd
),
err
))
raise
RuntimeError
(
"Error executing `%s': %s"
%
(
" "
.
join
(
cmd
),
err
))
return
out
return
out
# Logging
_log_level
=
LOG_WARNING
_log_use_syslog
=
False
_log_stream
=
sys
.
stderr
_log_syslog_opts
=
()
_log_pid
=
os
.
getpid
()
def
set_log_level
(
level
):
"Sets the log level for console messages, does not affect syslog logging."
global
_log_level
assert
level
>
LOG_ERR
and
level
<=
LOG_DEBUG
_log_level
=
level
def
set_log_output
(
file
):
"Redirect console messages to the provided stream."
global
_log_stream
assert
hasattr
(
file
,
"write"
)
and
hasattr
(
file
,
"flush"
)
_log_stream
=
file
def
log_use_syslog
(
use
=
True
,
ident
=
None
,
logopt
=
0
,
facility
=
syslog
.
LOG_USER
):
"Enable or disable the use of syslog for logging messages."
global
_log_use_syslog
,
_log_syslog_opts
if
not
use
:
if
_log_use_syslog
:
syslog
.
closelog
()
_log_use_syslog
=
False
return
if
not
ident
:
#ident = os.path.basename(sys.argv[0])
ident
=
"netns"
syslog
.
openlog
(
"%s[%d]"
%
(
ident
,
os
.
getpid
()),
logopt
,
facility
)
_log_syslog_opts
=
(
ident
,
logopt
,
facility
)
_log_use_syslog
=
True
info
(
"Syslog logging started"
)
def
logger
(
priority
,
message
):
"Print a log message in syslog, console or both."
global
_log_use_syslog
,
_log_stream
if
_log_use_syslog
:
if
os
.
getpid
()
!=
_log_pid
:
# Re-init logging
log_use_syslog
(
_log_use_syslog
,
*
_log_syslog_opts
)
syslog
.
syslog
(
priority
,
message
)
return
if
priority
>
_log_level
:
return
_log_stream
.
write
(
"[%d] %s
\
n
"
%
(
os
.
getpid
(),
message
.
rstrip
()))
_log_stream
.
flush
()
def
error
(
message
):
logger
(
LOG_ERR
,
message
)
def
warning
(
message
):
logger
(
LOG_WARNING
,
message
)
def
notice
(
message
):
logger
(
LOG_NOTICE
,
message
)
def
info
(
message
):
logger
(
LOG_INFO
,
message
)
def
debug
(
message
):
logger
(
LOG_DEBUG
,
message
)
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