8
8
def build_main_arg_parser () -> argparse .ArgumentParser :
9
9
parser = argparse .ArgumentParser ()
10
10
11
- group = parser .add_argument_group (' Scicat Ingestor Options' )
11
+ group = parser .add_argument_group (" Scicat Ingestor Options" )
12
12
13
13
group .add_argument (
14
- '-c' ,
15
- ' --cf' ,
16
- ' --config' ,
17
- ' --config-file' ,
18
- default = ' config.20240405.json' ,
19
- dest = ' config_file' ,
20
- help = ' Configuration file name. Default: config.20240405.json' ,
14
+ "-c" ,
15
+ " --cf" ,
16
+ " --config" ,
17
+ " --config-file" ,
18
+ default = " config.20240405.json" ,
19
+ dest = " config_file" ,
20
+ help = " Configuration file name. Default: config.20240405.json" ,
21
21
type = str ,
22
22
)
23
23
group .add_argument (
24
- '-v' ,
25
- ' --verbose' ,
26
- dest = ' verbose' ,
27
- help = ' Provide logging on stdout' ,
28
- action = ' store_true' ,
24
+ "-v" ,
25
+ " --verbose" ,
26
+ dest = " verbose" ,
27
+ help = " Provide logging on stdout" ,
28
+ action = " store_true" ,
29
29
default = False ,
30
30
)
31
31
group .add_argument (
32
- ' --file-log' ,
33
- dest = ' file_log' ,
34
- help = ' Provide logging on file' ,
35
- action = ' store_true' ,
32
+ " --file-log" ,
33
+ dest = " file_log" ,
34
+ help = " Provide logging on file" ,
35
+ action = " store_true" ,
36
36
default = False ,
37
37
)
38
38
group .add_argument (
39
- ' --log-filepath-prefix' ,
40
- dest = ' log_filepath_prefix' ,
41
- help = ' Prefix of the log file path' ,
42
- default = ' .scicat_ingestor_log' ,
39
+ " --log-filepath-prefix" ,
40
+ dest = " log_filepath_prefix" ,
41
+ help = " Prefix of the log file path" ,
42
+ default = " .scicat_ingestor_log" ,
43
43
)
44
44
group .add_argument (
45
- ' --file-log-timestamp' ,
46
- dest = ' file_log_timestamp' ,
47
- help = ' Provide logging on the system log' ,
48
- action = ' store_true' ,
45
+ " --file-log-timestamp" ,
46
+ dest = " file_log_timestamp" ,
47
+ help = " Provide logging on the system log" ,
48
+ action = " store_true" ,
49
49
default = False ,
50
50
)
51
51
group .add_argument (
52
- ' --system-log' ,
53
- dest = ' system_log' ,
54
- help = ' Provide logging on the system log' ,
55
- action = ' store_true' ,
52
+ " --system-log" ,
53
+ dest = " system_log" ,
54
+ help = " Provide logging on the system log" ,
55
+ action = " store_true" ,
56
56
default = False ,
57
57
)
58
58
group .add_argument (
59
- ' --system-log-facility' ,
60
- dest = ' system_log_facility' ,
61
- help = ' Facility for system log' ,
62
- default = ' mail' ,
59
+ " --system-log-facility" ,
60
+ dest = " system_log_facility" ,
61
+ help = " Facility for system log" ,
62
+ default = " mail" ,
63
63
)
64
64
group .add_argument (
65
- ' --log-message-prefix' ,
66
- dest = ' log_message_prefix' ,
67
- help = ' Prefix for log messages' ,
68
- default = ' SFI: ' ,
65
+ " --log-message-prefix" ,
66
+ dest = " log_message_prefix" ,
67
+ help = " Prefix for log messages" ,
68
+ default = " SFI: " ,
69
69
)
70
70
group .add_argument (
71
- ' --log-level' , dest = ' log_level' , help = ' Logging level' , default = ' INFO' , type = str
71
+ " --log-level" , dest = " log_level" , help = " Logging level" , default = " INFO" , type = str
72
72
)
73
73
group .add_argument (
74
- ' --check-by-job-id' ,
75
- dest = ' check_by_job_id' ,
76
- help = ' Check the status of a job by job_id' ,
77
- action = ' store_true' ,
74
+ " --check-by-job-id" ,
75
+ dest = " check_by_job_id" ,
76
+ help = " Check the status of a job by job_id" ,
77
+ action = " store_true" ,
78
78
default = True ,
79
79
)
80
80
group .add_argument (
81
- ' --pyscicat' ,
82
- dest = ' pyscicat' ,
83
- help = ' Location where a specific version of pyscicat is available' ,
81
+ " --pyscicat" ,
82
+ dest = " pyscicat" ,
83
+ help = " Location where a specific version of pyscicat is available" ,
84
84
default = None ,
85
85
type = str ,
86
86
)
87
+ group .add_argument (
88
+ "--graylog" ,
89
+ dest = "graylog" ,
90
+ help = "Use graylog for additional logs" ,
91
+ action = "store_true" ,
92
+ default = False ,
93
+ )
87
94
return parser
88
95
89
96
97
+ @dataclass
98
+ class GraylogOptions :
99
+ host : str = ""
100
+ port : str = ""
101
+ facility : str = "scicat.ingestor"
102
+
103
+
90
104
@dataclass
91
105
class RunOptions :
92
106
"""RunOptions dataclass to store the configuration options.
@@ -107,6 +121,7 @@ class RunOptions:
107
121
check_by_job_id : bool
108
122
system_log_facility : Optional [str ] = None
109
123
pyscicat : Optional [str ] = None
124
+ graylog : bool = False
110
125
111
126
112
127
@dataclass
@@ -139,6 +154,8 @@ class ScicatConfig:
139
154
"""Merged configuration dictionary with command line arguments."""
140
155
kafka_options : kafkaOptions
141
156
"""Kafka configuration options read from files."""
157
+ graylog_options : GraylogOptions
158
+ """Graylog configuration options for streaming logs."""
142
159
143
160
def to_dict (self ) -> dict :
144
161
"""Return the configuration as a dictionary."""
@@ -150,7 +167,9 @@ def to_dict(self) -> dict:
150
167
if isinstance (value , Mapping ):
151
168
original_dict [key ] = dict (value )
152
169
153
- copied = ScicatConfig (original_dict , self .run_options , self .kafka_options )
170
+ copied = ScicatConfig (
171
+ original_dict , self .run_options , self .kafka_options , self .graylog_options
172
+ )
154
173
return asdict (copied )
155
174
156
175
@@ -171,7 +190,7 @@ def build_scicat_config(input_args: argparse.Namespace) -> ScicatConfig:
171
190
config_dict = dict ()
172
191
173
192
# Overwrite deep-copied options with command line arguments
174
- run_option_dict : dict = copy .deepcopy (config_dict .setdefault (' options' , dict ()))
193
+ run_option_dict : dict = copy .deepcopy (config_dict .setdefault (" options" , dict ()))
175
194
for arg_name , arg_value in vars (input_args ).items ():
176
195
if arg_value is not None :
177
196
run_option_dict [arg_name ] = arg_value
@@ -184,5 +203,6 @@ def build_scicat_config(input_args: argparse.Namespace) -> ScicatConfig:
184
203
return ScicatConfig (
185
204
original_dict = MappingProxyType (config_dict ),
186
205
run_options = RunOptions (** run_option_dict ),
187
- kafka_options = kafkaOptions (** config_dict .setdefault ('kafka' , dict ())),
206
+ kafka_options = kafkaOptions (** config_dict .setdefault ("kafka" , dict ())),
207
+ graylog_options = GraylogOptions (** config_dict .setdefault ("graylog" , dict ())),
188
208
)
0 commit comments