Skip to content

Commit 45e784e

Browse files
committed
logging speedup flag -m added
1 parent 80fe7b3 commit 45e784e

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

CHANGES.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Changes
44
0.0.4 (2019-XX-XX)
55
------------------
66

7-
* (TBD)
7+
* FEATURE: New flag ``-m``, explicitly excluding all operations from the log that do not have the potential to change the filesystem. Added for convenience.
88

99
0.0.3 (2019-05-01)
1010
------------------

src/loggedfs/_core/cli.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,16 @@
8282
help = 'Run in library mode. DO NOT USE THIS FROM THE COMMAND LINE!',
8383
hidden = True
8484
)
85+
@click.option(
86+
'-m', '--only-modify-operations',
87+
is_flag = True,
88+
help = 'Exclude logging of all operations that can not cause changes in the filesystem. Convenience flag for accelerated logging.'
89+
)
8590
@click.argument(
8691
'directory',
8792
type = click.Path(exists = True, file_okay = False, dir_okay = True, resolve_path = True)
8893
)
89-
def cli_entry(f, p, c, s, l, json, buffers, lib, directory):
94+
def cli_entry(f, p, c, s, l, json, buffers, lib, only_modify_operations, directory):
9095
"""LoggedFS-python is a transparent fuse-filesystem which allows to log
9196
every operation that happens in the backend filesystem. Logs can be written
9297
to syslog, to a file, or to the standard output. LoggedFS-python allows to specify an XML
@@ -97,7 +102,7 @@ def cli_entry(f, p, c, s, l, json, buffers, lib, directory):
97102

98103
loggedfs_factory(
99104
directory,
100-
**__process_config__(c, l, s, f, p, json, buffers, lib)
105+
**__process_config__(c, l, s, f, p, json, buffers, lib, only_modify_operations)
101106
)
102107

103108

@@ -109,7 +114,8 @@ def __process_config__(
109114
fuse_allowother,
110115
log_json,
111116
log_buffers,
112-
lib_mode
117+
lib_mode,
118+
log_only_modify_operations
113119
):
114120

115121
if config_fh is not None:
@@ -135,6 +141,7 @@ def __process_config__(
135141
'log_file': log_file,
136142
'log_filter': filter_obj,
137143
'log_json': log_json,
144+
'log_only_modify_operations': log_only_modify_operations,
138145
'log_printprocessname': log_printprocessname,
139146
'log_syslog': not log_syslog_off
140147
}

src/loggedfs/_core/defaults.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@
3737
LOG_BUFFERS_DEFAULT = False
3838
LOG_ENABLED_DEFAULT = True
3939
LOG_JSON_DEFAULT = False
40+
LOG_ONLYMODIFYOPERATIONS_DEFAULT = False
4041
LOG_PRINTPROCESSNAME_DEFAULT = True
4142
LOG_SYSLOG_DEFAULT = False

src/loggedfs/_core/fs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
LOG_BUFFERS_DEFAULT,
5454
LOG_ENABLED_DEFAULT,
5555
LOG_JSON_DEFAULT,
56+
LOG_ONLYMODIFYOPERATIONS_DEFAULT,
5657
LOG_PRINTPROCESSNAME_DEFAULT,
5758
LOG_SYSLOG_DEFAULT
5859
)
@@ -131,6 +132,7 @@ def __init__(self,
131132
log_file = None,
132133
log_filter = None,
133134
log_json = LOG_JSON_DEFAULT,
135+
log_only_modify_operations = LOG_ONLYMODIFYOPERATIONS_DEFAULT,
134136
log_printprocessname = LOG_PRINTPROCESSNAME_DEFAULT,
135137
log_syslog = LOG_SYSLOG_DEFAULT,
136138
**kwargs
@@ -169,6 +171,8 @@ def __init__(self,
169171
raise TypeError('log_buffers must be of type bool')
170172
if not isinstance(lib_mode, bool):
171173
raise TypeError('lib_mode must be of type bool')
174+
if not isinstance(log_only_modify_operations, bool):
175+
raise TypeError('log_only_modify_operations must be of type bool')
172176

173177
if not isinstance(fuse_foreground, bool):
174178
raise TypeError('fuse_foreground must be of type bool')
@@ -181,6 +185,7 @@ def __init__(self,
181185
self._log_buffers = log_buffers
182186
self._log_filter = log_filter
183187
self._lib_mode = lib_mode
188+
self._log_only_modify_operations = log_only_modify_operations
184189

185190
self._logger = get_logger('LoggedFS-python', log_enabled, log_file, log_syslog, self._log_json)
186191

src/loggedfs/_core/out.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,23 @@ def _log_event_(
183183
ret_status, ret_value
184184
):
185185

186+
if self._log_only_modify_operations:
187+
if func.__name__ not in (
188+
'chmod',
189+
'chown',
190+
'link',
191+
'mkdir',
192+
'mknod',
193+
'rename',
194+
'rmdir',
195+
'symlink',
196+
'truncate',
197+
'unlink',
198+
'utimens',
199+
'write'
200+
):
201+
return
202+
186203
uid, gid, pid = fuse_get_context()
187204

188205
p_cmdname = ''

0 commit comments

Comments
 (0)