Skip to content

Commit

Permalink
less verbose logging
Browse files Browse the repository at this point in the history
  • Loading branch information
remcoros committed Jul 27, 2024
1 parent 686fcc9 commit 06636b2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
21 changes: 19 additions & 2 deletions src/PushTX/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ Serves a custom version of Coldcard's pushtx single html file that only uses thi
*/
var builder = WebApplication.CreateSlimBuilder(args);

// only use a simple console logger
builder.Logging.ClearProviders();
builder.Logging.AddSimpleConsole(x =>
{
x.SingleLine = true;
});
builder.Services.AddSingleton(sp => sp.GetRequiredService<ILoggerFactory>().CreateLogger("PushTX"));

// simple json-rpc client
builder.Services.AddHttpClient<RpcClient>();

// this will throw when RPC_HOST / RPC_USERNAME / RPC_PASSWORD are not set
Expand All @@ -41,7 +50,7 @@ Serves a custom version of Coldcard's pushtx single html file that only uses thi
// returns: a transaction id (string)
app.MapPost("/api/tx", async (
HttpContext context,
[FromServices] ILogger<Program> log,
[FromServices] ILogger log,
[FromServices] RpcClient rpcClient,
[FromServices] RpcSettings settings) =>
{
Expand Down Expand Up @@ -81,7 +90,7 @@ Serves a custom version of Coldcard's pushtx single html file that only uses thi
// returns: mempool.space compatible transaction result (json)
app.MapGet("/api/tx/{txid}", async (
HttpContext context,
[FromServices] ILogger<Program> log,
[FromServices] ILogger log,
[FromServices] RpcClient rpcClient,
[FromServices] RpcSettings settings,
[FromRoute] string txid) =>
Expand Down Expand Up @@ -189,6 +198,11 @@ Serves a custom version of Coldcard's pushtx single html file that only uses thi
/*
* Run it!
*/
var log = app.Services.GetRequiredService<ILogger>();

app.Services.GetRequiredService<IHostApplicationLifetime>()
.ApplicationStarted.Register(() => log.LogInformation("Application started."));

app.Run();

/*
Expand Down Expand Up @@ -338,6 +352,9 @@ string EnvVar(string name)
}
}

/*
* mempool.space api like compatible models
*/
public class MempoolTxData(string txid, MempoolTxDataVin[] vin, MempoolTxDataVout[] vout, MempoolConfirmedStatus status)
{
[JsonPropertyName("txid")]
Expand Down
7 changes: 4 additions & 3 deletions src/PushTX/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Default": "Warning",
"Microsoft.AspNetCore": "Warning",
"Microsoft.Hosting": "Information",
"System.Net": "Information"
"Microsoft.Hosting": "Warning",
"System.Net": "Warning",
"PushTX": "Information"
}
},
"AllowedHosts": "*"
Expand Down

0 comments on commit 06636b2

Please sign in to comment.