]>
git.proxmox.com Git - ceph.git/blob - ceph/src/ceph-volume/ceph_volume/log.py
3 from ceph_volume
import terminal
4 from ceph_volume
import conf
6 BASE_FORMAT
= "[%(name)s][%(levelname)-6s] %(message)s"
7 FILE_FORMAT
= "[%(asctime)s]" + BASE_FORMAT
10 def setup(name
='ceph-volume.log', log_path
=None, log_level
=None):
11 log_path
= log_path
or conf
.log_path
12 # if a non-root user calls help or other no-sudo-required command the
13 # logger will fail to write to /var/lib/ceph/ so this /tmp/ path is used as
15 tmp_log_file
= os
.path
.join('/tmp/', name
)
16 root_logger
= logging
.getLogger()
17 # The default path is where all ceph log files are, and will get rotated by
18 # Ceph's logrotate rules.
19 log_level
= log_level
or "DEBUG"
20 log_level
= getattr(logging
, log_level
.upper())
21 root_logger
.setLevel(log_level
)
24 fh
= logging
.FileHandler(log_path
)
25 except (OSError, IOError) as err
:
26 terminal
.warning("Falling back to /tmp/ for logging. Can't use %s" % log_path
)
27 terminal
.warning(str(err
))
28 conf
.log_path
= tmp_log_file
29 fh
= logging
.FileHandler(tmp_log_file
)
31 fh
.setLevel(log_level
)
32 fh
.setFormatter(logging
.Formatter(FILE_FORMAT
))
34 root_logger
.addHandler(fh
)
38 # TODO: At some point ceph-volume should stop using the custom logger
39 # interface that exists in terminal.py and use the logging module to
40 # produce output for the terminal
42 sh
= logging
.StreamHandler()
43 sh
.setFormatter(logging
.Formatter('[terminal] %(message)s'))
44 sh
.setLevel(logging
.DEBUG
)
46 terminal_logger
= logging
.getLogger('terminal')
48 # allow all levels at root_logger, handlers control individual levels
49 terminal_logger
.addHandler(sh
)