|
6 | 6 | Filesystem monitoring with Fuse and Python |
7 | 7 | https://github.com/pleiszenburg/loggedfs-python |
8 | 8 |
|
9 | | - src/loggedfs/cli.py: Command line interface |
| 9 | + src/loggedfs/_core/cli.py: Command line interface |
10 | 10 |
|
11 | 11 | Copyright (C) 2017-2019 Sebastian M. Ernst <[email protected]> |
12 | 12 |
|
|
31 | 31 |
|
32 | 32 | import click |
33 | 33 |
|
34 | | -from .core import loggedfs_factory |
35 | | -from .filter import parse_filters |
| 34 | +from .defaults import LOG_ENABLED_DEFAULT, LOG_PRINTPROCESSNAME_DEFAULT |
| 35 | +from .fs import loggedfs_factory |
| 36 | +from .filter import filter_pipeline_class |
36 | 37 |
|
37 | 38 |
|
38 | 39 | # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
70 | 71 | is_flag = True, |
71 | 72 | help = 'Format output as JSON instead of traditional loggedfs format.' |
72 | 73 | ) |
| 74 | +@click.option( |
| 75 | + '-b', '--buffers', |
| 76 | + is_flag = True, |
| 77 | + help = 'Include read/write-buffers (compressed, BASE64) in log.' |
| 78 | + ) |
| 79 | +@click.option( |
| 80 | + '--lib', |
| 81 | + is_flag = True, |
| 82 | + help = 'Run in library mode. DO NOT USE THIS FROM THE COMMAND LINE!', |
| 83 | + hidden = True |
| 84 | + ) |
73 | 85 | @click.argument( |
74 | 86 | 'directory', |
75 | 87 | type = click.Path(exists = True, file_okay = False, dir_okay = True, resolve_path = True) |
76 | 88 | ) |
77 | | -def cli_entry(f, p, c, s, l, json, directory): |
| 89 | +def cli_entry(f, p, c, s, l, json, buffers, lib, directory): |
78 | 90 | """LoggedFS-python is a transparent fuse-filesystem which allows to log |
79 | | - every operations that happens in the backend filesystem. Logs can be written |
80 | | - to syslog, to a file, or to the standard output. LoggedFS comes with an XML |
| 91 | + every operation that happens in the backend filesystem. Logs can be written |
| 92 | + to syslog, to a file, or to the standard output. LoggedFS-python allows to specify an XML |
81 | 93 | configuration file in which you can choose exactly what you want to log and |
82 | 94 | what you don't want to log. You can add filters on users, operations (open, |
83 | | - read, write, chown, chmod, etc.), filenames and return code. Filename |
84 | | - filters are regular expressions. |
| 95 | + read, write, chown, chmod, etc.), filenames, commands and return code. |
85 | 96 | """ |
86 | 97 |
|
87 | 98 | loggedfs_factory( |
88 | 99 | directory, |
89 | | - **__process_config__(c, l, s, f, p, json) |
| 100 | + **__process_config__(c, l, s, f, p, json, buffers, lib) |
90 | 101 | ) |
91 | 102 |
|
92 | 103 |
|
93 | 104 | def __process_config__( |
94 | 105 | config_fh, |
95 | 106 | log_file, |
96 | 107 | log_syslog_off, |
97 | | - fuse_foreground_bool, |
98 | | - fuse_allowother_bool, |
99 | | - log_json |
| 108 | + fuse_foreground, |
| 109 | + fuse_allowother, |
| 110 | + log_json, |
| 111 | + log_buffers, |
| 112 | + lib_mode |
100 | 113 | ): |
101 | 114 |
|
102 | 115 | if config_fh is not None: |
103 | | - config_xml_str = config_fh.read() |
| 116 | + config_data = config_fh.read() |
104 | 117 | config_fh.close() |
| 118 | + ( |
| 119 | + log_enabled, log_printprocessname, filter_obj |
| 120 | + ) = filter_pipeline_class.from_xmlstring(config_data) |
105 | 121 | config_file = config_fh.name |
106 | 122 | else: |
107 | | - config_file = '[None]' |
108 | | - config_xml_str = None |
109 | | - |
110 | | - config_dict = parse_filters(config_xml_str) |
| 123 | + log_enabled = LOG_ENABLED_DEFAULT |
| 124 | + log_printprocessname = LOG_PRINTPROCESSNAME_DEFAULT |
| 125 | + filter_obj = filter_pipeline_class() |
| 126 | + config_file = None |
111 | 127 |
|
112 | 128 | return { |
113 | | - 'log_includes': config_dict['log_includes'], |
114 | | - 'log_excludes': config_dict['log_excludes'], |
115 | | - 'log_enabled': config_dict['log_enabled'], |
116 | | - 'log_printprocessname': config_dict['log_printprocessname'], |
| 129 | + 'fuse_foreground': fuse_foreground, |
| 130 | + 'fuse_allowother': fuse_allowother, |
| 131 | + 'lib_mode': lib_mode, |
| 132 | + 'log_buffers': log_buffers, |
| 133 | + '_log_configfile' : config_file, |
| 134 | + 'log_enabled': log_enabled, |
117 | 135 | 'log_file': log_file, |
118 | | - 'log_syslog': not log_syslog_off, |
119 | | - 'log_configmsg': 'LoggedFS-python using configuration file %s' % config_file, |
| 136 | + 'log_filter': filter_obj, |
120 | 137 | 'log_json': log_json, |
121 | | - 'fuse_foreground_bool': fuse_foreground_bool, |
122 | | - 'fuse_allowother_bool': fuse_allowother_bool |
| 138 | + 'log_printprocessname': log_printprocessname, |
| 139 | + 'log_syslog': not log_syslog_off |
123 | 140 | } |
0 commit comments