Skip to content

Commit 357bc96

Browse files
committed
Extra logging levels; logging for xic and query
1 parent f5bbd4c commit 357bc96

File tree

5 files changed

+104
-13
lines changed

5 files changed

+104
-13
lines changed

LogFormat.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ public enum LogFormat
55
SILENT,
66
VERBOSE,
77
DEFAULT,
8-
NONE
8+
WARNING,
9+
ERROR
910
}
1011

1112
}

MainClass.cs

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ private static void XicParametersParsing(string[] args)
5353
XicParameters parameters = new XicParameters();
5454
string singleFile = null;
5555
string fileDirectory = null;
56+
string logFormatString = null;
5657

5758
var optionSet = new OptionSet
5859
{
@@ -97,6 +98,10 @@ private static void XicParametersParsing(string[] args)
9798
{
9899
"w|warningsAreErrors", "Return non-zero exit code for warnings; default only for errors",
99100
v => parameters.Vigilant = v != null
101+
},
102+
{
103+
"l=|logging=", "Optional logging level: 0 for silent, 1 for verbose, 2 for default, 3 for warning, 4 for error; both numeric and text (case insensitive) value recognized.",
104+
v => logFormatString = v
100105
}
101106
};
102107

@@ -187,6 +192,13 @@ private static void XicParametersParsing(string[] args)
187192
parameters.rawFileList.Add(file.FullName);
188193
}
189194
}
195+
196+
if (logFormatString != null)
197+
{
198+
parameters.LogFormat = (LogFormat)ParseToEnum(typeof(LogFormat), logFormatString, "-l, --logging");
199+
}
200+
201+
if (parameters.stdout) parameters.LogFormat = LogFormat.SILENT; //switch off logging in stdout
190202
}
191203
catch (OptionException optionException)
192204
{
@@ -210,10 +222,38 @@ private static void XicParametersParsing(string[] args)
210222
var exitCode = 1;
211223
try
212224
{
213-
// execute the xic commands
225+
switch (parameters.LogFormat)
226+
{
227+
case LogFormat.VERBOSE:
228+
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root.Level =
229+
Level.Debug;
230+
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository())
231+
.RaiseConfigurationChanged(EventArgs.Empty);
232+
break;
233+
case LogFormat.SILENT:
234+
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root.Level =
235+
Level.Off;
236+
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository())
237+
.RaiseConfigurationChanged(EventArgs.Empty);
238+
break;
239+
case LogFormat.WARNING:
240+
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root.Level =
241+
Level.Warn;
242+
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository())
243+
.RaiseConfigurationChanged(EventArgs.Empty);
244+
break;
245+
case LogFormat.ERROR:
246+
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root.Level =
247+
Level.Error;
248+
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository())
249+
.RaiseConfigurationChanged(EventArgs.Empty);
250+
break;
251+
}
252+
214253
XicExecutor.Run(parameters);
215254

216255
Log.Info($"Processing completed {parameters.Errors} errors, {parameters.Warnings} warnings");
256+
217257
exitCode = parameters.Vigilant ? parameters.Errors + parameters.Warnings : parameters.Errors;
218258
}
219259
catch (Exception ex)
@@ -236,6 +276,7 @@ private static void XicParametersParsing(string[] args)
236276

237277
private static void SpectrumQueryParametersParsing(string[] args)
238278
{
279+
string logFormatString = null;
239280
QueryParameters parameters = new QueryParameters();
240281
var optionSet = new OptionSet
241282
{
@@ -270,6 +311,10 @@ private static void SpectrumQueryParametersParsing(string[] args)
270311
{
271312
"w|warningsAreErrors", "Return non-zero exit code for warnings; default only for errors",
272313
v => parameters.Vigilant = v != null
314+
},
315+
{
316+
"l=|logging=", "Optional logging level: 0 for silent, 1 for verbose, 2 for default, 3 for warning, 4 for error; both numeric and text (case insensitive) value recognized.",
317+
v => logFormatString = v
273318
}
274319
};
275320

@@ -310,6 +355,13 @@ private static void SpectrumQueryParametersParsing(string[] args)
310355
"specify a valid scan range",
311356
"-s, --scans");
312357
}
358+
359+
if (logFormatString != null)
360+
{
361+
parameters.LogFormat = (LogFormat)ParseToEnum(typeof(LogFormat), logFormatString, "-l, --logging");
362+
}
363+
364+
if (parameters.stdout) parameters.LogFormat = LogFormat.SILENT; //switch off logging in stdout
313365
}
314366
catch (OptionException optionException)
315367
{
@@ -333,6 +385,34 @@ private static void SpectrumQueryParametersParsing(string[] args)
333385
var exitCode = 1;
334386
try
335387
{
388+
switch (parameters.LogFormat)
389+
{
390+
case LogFormat.VERBOSE:
391+
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root.Level =
392+
Level.Debug;
393+
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository())
394+
.RaiseConfigurationChanged(EventArgs.Empty);
395+
break;
396+
case LogFormat.SILENT:
397+
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root.Level =
398+
Level.Off;
399+
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository())
400+
.RaiseConfigurationChanged(EventArgs.Empty);
401+
break;
402+
case LogFormat.WARNING:
403+
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root.Level =
404+
Level.Warn;
405+
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository())
406+
.RaiseConfigurationChanged(EventArgs.Empty);
407+
break;
408+
case LogFormat.ERROR:
409+
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root.Level =
410+
Level.Error;
411+
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository())
412+
.RaiseConfigurationChanged(EventArgs.Empty);
413+
break;
414+
}
415+
336416
QueryExecutor.Run(parameters);
337417

338418
Log.Info($"Processing completed {parameters.Errors} errors, {parameters.Warnings} warnings");
@@ -434,7 +514,7 @@ private static void RegularParametersParsing(string[] args)
434514
v => parseInput.AllDetectors = v != null
435515
},
436516
{
437-
"l=|logging=", "Optional logging level: 0 for silent, 1 for verbose; both numeric and text (case insensitive) value recognized.",
517+
"l=|logging=", "Optional logging level: 0 for silent, 1 for verbose, 2 for default, 3 for warning, 4 for error; both numeric and text (case insensitive) value recognized.",
438518
v => logFormatString = v
439519
},
440520
{
@@ -689,6 +769,18 @@ private static void RegularParametersParsing(string[] args)
689769
((log4net.Repository.Hierarchy.Hierarchy) LogManager.GetRepository())
690770
.RaiseConfigurationChanged(EventArgs.Empty);
691771
break;
772+
case LogFormat.WARNING:
773+
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root.Level =
774+
Level.Warn;
775+
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository())
776+
.RaiseConfigurationChanged(EventArgs.Empty);
777+
break;
778+
case LogFormat.ERROR:
779+
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root.Level =
780+
Level.Error;
781+
((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository())
782+
.RaiseConfigurationChanged(EventArgs.Empty);
783+
break;
692784
}
693785

694786
RawFileParser.Parse(parseInput);

Query/QueryExecutor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.IO;
55
using Mono.Options;
66
using Newtonsoft.Json;
7-
using ThermoRawFileParser.Writer;
87

98
namespace ThermoRawFileParser.Query
109
{

Query/QueryParameters.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,9 @@ public class QueryParameters
1818
public HashSet<int> scanNumbers { get; set; }
1919
public bool stdout { get; set; }
2020
public bool Vigilant { get; set; }
21-
public int Errors
22-
{
23-
get => _errors;
24-
}
25-
public int Warnings
26-
{
27-
get => _warnings;
28-
}
21+
public int Errors { get => _errors; }
22+
public int Warnings { get => _warnings; }
23+
public LogFormat LogFormat { get; set; }
2924

3025
public QueryParameters()
3126
{
@@ -37,6 +32,7 @@ public QueryParameters()
3732
scanNumbers = new HashSet<int>();
3833
stdout = false;
3934
Vigilant = false;
35+
LogFormat = LogFormat.DEFAULT;
4036
_errors = 0;
4137
_warnings = 0;
4238
}
@@ -52,6 +48,7 @@ public QueryParameters(QueryParameters copy)
5248
foreach (int s in copy.scanNumbers) scanNumbers.Add(s);
5349
stdout = copy.stdout;
5450
Vigilant = copy.Vigilant;
51+
LogFormat = copy.LogFormat;
5552
_errors = copy.Errors;
5653
_warnings = copy.Warnings;
5754
}

XIC/XicParameters.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public class XicParameters
1717
public bool stdout { get; set; }
1818
public bool Vigilant { get; set; }
1919
public int Errors { get => _errors; }
20-
2120
public int Warnings { get => _warnings; }
21+
public LogFormat LogFormat { get; set; }
2222

2323
public XicParameters()
2424
{
@@ -31,6 +31,7 @@ public XicParameters()
3131
base64 = false;
3232
stdout = false;
3333
Vigilant = false;
34+
LogFormat = LogFormat.DEFAULT;
3435
_errors = 0;
3536
_warnings = 0;
3637
}
@@ -61,6 +62,7 @@ public XicParameters(XicParameters copy)
6162
outputFileName = copy.outputFileName;
6263
base64 = copy.base64;
6364
stdout = copy.stdout;
65+
LogFormat = copy.LogFormat;
6466
Vigilant = copy.Vigilant;
6567
_errors = copy.Errors;
6668
_warnings = copy.Warnings;

0 commit comments

Comments
 (0)