-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add log-level property to config schema (#2359)
## Why make this change? Adds log-level property to dab config file under the runtime section, closing issue #1645. The log-level is necessary to receive updates from the program, and with this property, it gives the users the ability to change what type of information they receive from the program. Lastly, it allows the users to have more options on how to change the log-level property, be it through the config file or the CLI. ## What is this change? First, the log-level property was added to the config file schema, in order for the user to have the ability to add the property into their config file. In order to save the information that is inside the property, a new object model named `LogLevelOptions` was created, inside of it is a new object model named `Level` with the purpose of showing all of the possible values in an enum type. A `LogLevelOptions` was then added to `RuntimeOptions` so the program knows in which section it is supposed to parse the information. A new converter `LogLevelOptionsConverterFactory` was created in order to allow the property in the config file to be deserialized. The logic in `Startup` file was modified to first tries to set the loggers based on the log-level property, in the case that log-level is null, it will fall back on the logic that was set up for `Host Mode`. New tests were created in `ConfigurationTests` to test the validity of the code. ## How was this tested? - [x] Integration Tests - [ ] Unit Tests --------- Co-authored-by: Ruben Cerna <[email protected]>
- Loading branch information
1 parent
e9972fe
commit 37222f1
Showing
10 changed files
with
244 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using Azure.DataApiBuilder.Config.ObjectModel; | ||
|
||
namespace Azure.DataApiBuilder.Config.Converters; | ||
|
||
/// <summary> | ||
/// Defines how DAB reads and writes log level options | ||
/// </summary> | ||
internal class LogLevelOptionsConverterFactory : JsonConverterFactory | ||
{ | ||
/// <inheritdoc/> | ||
public override bool CanConvert(Type typeToConvert) | ||
{ | ||
return typeToConvert.IsAssignableTo(typeof(LogLevelOptions)); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override JsonConverter? CreateConverter(Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
return new LogLevelOptionsConverter(); | ||
} | ||
|
||
private class LogLevelOptionsConverter : JsonConverter<LogLevelOptions> | ||
{ | ||
/// <summary> | ||
/// Defines how DAB reads loglevel options and defines which values are | ||
/// used to instantiate LogLevelOptions. | ||
/// Uses default deserialize. | ||
/// </summary> | ||
public override LogLevelOptions? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
JsonSerializerOptions jsonSerializerOptions = new(options); | ||
jsonSerializerOptions.Converters.Remove(jsonSerializerOptions.Converters.First(c => c is LogLevelOptionsConverterFactory)); | ||
return JsonSerializer.Deserialize<LogLevelOptions>(ref reader, jsonSerializerOptions); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, LogLevelOptions value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStartObject(); | ||
writer.WritePropertyName("level"); | ||
JsonSerializer.Serialize(writer, value.Value, options); | ||
writer.WriteEndObject(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Text.Json.Serialization; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Azure.DataApiBuilder.Config.ObjectModel; | ||
|
||
/// <summary> | ||
/// Holds the settings used at runtime to set the LogLevel of the different providers | ||
/// </summary> | ||
public record LogLevelOptions | ||
{ | ||
[JsonPropertyName("level")] | ||
public LogLevel? Value { get; set; } | ||
|
||
public LogLevelOptions(LogLevel? Value = null) | ||
{ | ||
this.Value = Value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters