|
33 | 33 | import errno |
34 | 34 | from functools import wraps |
35 | 35 | import grp |
36 | | -import logging |
37 | | -import logging.handlers |
38 | 36 | import os |
39 | 37 | import pwd |
40 | 38 | import re |
41 | 39 | import stat |
42 | 40 | import sys |
43 | | -import time |
44 | | - |
45 | | -try: |
46 | | - from time import time_ns |
47 | | -except ImportError: |
48 | | - from time import time as _time |
49 | | - time_ns = lambda: int(_time() * 1e9) |
50 | 41 |
|
51 | 42 | from fuse import ( |
52 | 43 | FUSE, |
|
61 | 52 | except ImportError: |
62 | 53 | fuse_features = {} |
63 | 54 |
|
64 | | - |
65 | | -# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
66 | | -# LOGGING: Support nano-second timestamps |
67 | | -# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
68 | | - |
69 | | -class _LogRecord_ns_(logging.LogRecord): |
70 | | - def __init__(self, *args, **kwargs): |
71 | | - self.created_ns = time_ns() # Fetch precise timestamp |
72 | | - super().__init__(*args, **kwargs) |
73 | | - |
74 | | -class _Formatter_ns_(logging.Formatter): |
75 | | - default_nsec_format = '%s,%09d' |
76 | | - def formatTime(self, record, datefmt=None): |
77 | | - if datefmt is not None: # Do not handle custom formats here ... |
78 | | - return super().formatTime(record, datefmt) # ... leave to original implementation |
79 | | - ct = self.converter(record.created_ns / 1e9) |
80 | | - t = time.strftime(self.default_time_format, ct) |
81 | | - s = self.default_nsec_format % (t, record.created_ns - (record.created_ns // 10**9) * 10**9) |
82 | | - return s |
83 | | - |
84 | | -logging.setLogRecordFactory(_LogRecord_ns_) |
| 55 | +from .log import get_logger |
| 56 | +from .timing import time |
85 | 57 |
|
86 | 58 |
|
87 | 59 | # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
@@ -350,7 +322,8 @@ def __init__(self, |
350 | 322 | if log_excludes is None: |
351 | 323 | log_excludes = [] |
352 | 324 |
|
353 | | - self._init_logger(log_enabled, log_file, log_syslog, log_printprocessname) |
| 325 | + self._log_printprocessname = bool(log_printprocessname) |
| 326 | + self.logger = get_logger('LoggedFS-python', log_enabled, log_file, log_syslog) |
354 | 327 |
|
355 | 328 | if bool(fuse_foreground_bool): |
356 | 329 | self.logger.info('LoggedFS-python not running as a daemon') |
@@ -383,40 +356,6 @@ def __init__(self, |
383 | 356 | self._compile_filter(log_includes, log_excludes) |
384 | 357 |
|
385 | 358 |
|
386 | | - def _init_logger(self, log_enabled, log_file, log_syslog, log_printprocessname): |
387 | | - |
388 | | - log_formater = _Formatter_ns_('%(asctime)s (%(name)s) %(message)s') |
389 | | - log_formater_short = _Formatter_ns_('%(message)s') |
390 | | - |
391 | | - self._log_printprocessname = bool(log_printprocessname) |
392 | | - |
393 | | - self.logger = logging.getLogger('LoggedFS-python') |
394 | | - |
395 | | - if not bool(log_enabled): |
396 | | - self.logger.setLevel(logging.CRITICAL) |
397 | | - return |
398 | | - self.logger.setLevel(logging.DEBUG) |
399 | | - |
400 | | - ch = logging.StreamHandler() |
401 | | - ch.setLevel(logging.DEBUG) |
402 | | - ch.setFormatter(log_formater) |
403 | | - self.logger.addHandler(ch) |
404 | | - |
405 | | - if bool(log_syslog): |
406 | | - sl = logging.handlers.SysLogHandler(address = '/dev/log') # TODO Linux only |
407 | | - sl.setLevel(logging.DEBUG) |
408 | | - sl.setFormatter(log_formater_short) |
409 | | - self.logger.addHandler(sl) |
410 | | - |
411 | | - if log_file is None: |
412 | | - return |
413 | | - |
414 | | - fh = logging.FileHandler(os.path.join(log_file)) # TODO |
415 | | - fh.setLevel(logging.DEBUG) |
416 | | - fh.setFormatter(log_formater) |
417 | | - self.logger.addHandler(fh) |
418 | | - |
419 | | - |
420 | 359 | def _compile_filter(self, include_list, exclude_list): |
421 | 360 |
|
422 | 361 | def proc_filter_item(in_item): |
@@ -716,7 +655,7 @@ def _fix_time_(atime, mtime): |
716 | 655 | if mtime in [UTIME_OMIT, None]: |
717 | 656 | mtime = st.st_mtime_ns |
718 | 657 | if UTIME_NOW in (atime, mtime): |
719 | | - now = time_ns() |
| 658 | + now = time.time_ns() |
720 | 659 | if atime == UTIME_NOW: |
721 | 660 | atime = now |
722 | 661 | if mtime == UTIME_NOW: |
|
0 commit comments