Skip to content

Commit

Permalink
Merge pull request #407 from ucdavis/srk/hide-queries
Browse files Browse the repository at this point in the history
log txn POST params and hide EF core logs
  • Loading branch information
srkirkland authored Jan 19, 2024
2 parents f032efb + 3bfc206 commit de81f7f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
25 changes: 20 additions & 5 deletions Sloth.Api/Controllers/v2/TransactionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;
using Serilog;
using Sloth.Api.Attributes;
using Sloth.Api.Errors;
using Sloth.Api.Models.v2;
Expand Down Expand Up @@ -185,8 +186,6 @@ public async Task<IList<Transaction>> GetByMetadata(string key, string value)
return transactions;
}

// TODO: just for testing, remove later

/// <summary>
/// Validate Financial Segment String
/// </summary>
Expand All @@ -199,9 +198,6 @@ public async Task<bool> ValidateFinancialSegmentString(string id)
return await _aggieEnterpriseService.IsAccountValid(id);
}


// TODO: update to AE

/// <summary>
/// Create a Transaction with a list of Transfers
/// </summary>
Expand All @@ -212,6 +208,8 @@ public async Task<bool> ValidateFinancialSegmentString(string id)
[ProducesResponseType(typeof(BadRequestObjectResult), 400)]
public async Task<IActionResult> Post([FromBody] CreateTransactionViewModel transaction)
{
LogTransactionCreating(transaction);

var teamId = GetTeamId();

if (!ModelState.IsValid)
Expand Down Expand Up @@ -364,6 +362,23 @@ await _context.Database.CreateExecutionStrategy().ExecuteAsync(async () =>
return new JsonResult(transactionToCreate);
}

private void LogTransactionCreating(CreateTransactionViewModel transaction)
{
var txn = new
{
transaction.KfsTrackingNumber,
transaction.ProcessorTrackingNumber,
transaction.MerchantTrackingNumber,
transaction.MerchantTrackingUrl,
transaction.Source,
transaction.SourceType,
Transfers = transaction.Transfers.Select(t => new { t.Amount, t.FinancialSegmentString, t.Description, t.Direction }).ToArray(),
Metadata = transaction.Metadata.Select(m => new { m.Name, m.Value }).ToArray(),
};

Log.Information("Transaction Creation Starting: {@Transaction}", txn);
}

private string GetTeamId()
{
return User.FindFirst(ClaimTypes.PrimaryGroupSid)?.Value;
Expand Down
2 changes: 1 addition & 1 deletion Sloth.Api/Logging/LoggingConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static LoggerConfiguration GetConfiguration()
// standard logger
var logConfig = new LoggerConfiguration()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
// .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning) // uncomment this to hide EF core general info logs
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning) // uncomment this to hide EF core general info logs
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
.Enrich.FromLogContext()
.Enrich.WithExceptionDetails()
Expand Down
2 changes: 1 addition & 1 deletion Sloth.Jobs.Core/Logging/LoggingConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static LoggerConfiguration GetConfiguration()
// standard logger
var logConfig = new LoggerConfiguration()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
// .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning) // uncomment this to hide EF core general info logs
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning) // uncomment this to hide EF core general info logs
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
.Enrich.FromLogContext()
.Enrich.WithExceptionDetails()
Expand Down
2 changes: 1 addition & 1 deletion Sloth.Web/Logging/LoggingConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static LoggerConfiguration GetConfiguration()
// standard logger
var logConfig = new LoggerConfiguration()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
// .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning) // uncomment this to hide EF core general info logs
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning) // uncomment this to hide EF core general info logs
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
.Enrich.FromLogContext()
.Enrich.WithExceptionDetails()
Expand Down

0 comments on commit de81f7f

Please sign in to comment.