Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F82949059
logging.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Sep 14, 09:30
Size
1003 B
Mime Type
text/x-python
Expires
Mon, Sep 16, 09:30 (2 d)
Engine
blob
Format
Raw Data
Handle
20778759
Attached To
R11599 sausage-binary
logging.py
View Options
'''
Logging setting module
'''
from
logging.handlers
import
SysLogHandler
import
logging
import
os
def
setup_logging
(
debug
=
False
,
verbose
=
False
):
pid
=
os
.
getpid
()
# Logger
# we are trying to catch all log from other module
level
=
logging
.
DEBUG
if
debug
is
True
else
logging
.
INFO
fmt
=
f
"[
%(levelname)s
] SAUSAGE {pid}
%(name)s
-
%(message)s
"
# create a syslog handler
sys_h
=
SysLogHandler
(
address
=
"/dev/log"
)
sys_h
.
setLevel
(
level
)
sys_h
.
setFormatter
(
logging
.
Formatter
(
fmt
))
handlers
=
[
sys_h
]
if
verbose
:
level
=
logging
.
DEBUG
# create console handler and set level to debug
c_h
=
logging
.
StreamHandler
()
c_h
.
setLevel
(
logging
.
DEBUG
)
handlers
.
append
(
c_h
)
# add syslog handler to root
logging
.
basicConfig
(
level
=
level
,
format
=
fmt
,
handlers
=
handlers
)
# create a sausage module wide logger which use root configuration
logger
=
logging
.
getLogger
(
"sausage"
)
logger
.
setLevel
(
level
)
return
logger
Event Timeline
Log In to Comment