Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 328108a

Browse filesBrowse files
authored
Restore the ability to filter spammy log messages (#530)
* Move connection checkin log messages to their own target Under heavy load they can happen thousands of times per second, and should generally be considered a nuisance at best. This marks the state discard as an info rather than a warning, and moves all the messages into their own log-target, so they can be filtered separately from the more relevant warnings. Signed-off-by: D.S. Ljungmark <spider@skuggor.se> * Remove left-over env_logger dependencies When moving to tracing-subscriber for logging, the env_logger dependencies were left around, this cuts them out as dead code. Signed-off-by: D.S. Ljungmark <spider@skuggor.se> * Restore ability to filter log messages at runtime This restores the RUST_LOG filters from env_logger but now with the tracing subscriber setup. The filters are chained so commandline options mark the default in case either option is set, which should be the path of least confusion for users. ( RUST_LOG setting level to debug, and commandline to warning is an odd user case, and I don't know what a user who does that is expecting. ) It also bumps the version number as a fix to see which versions have which behaviour. Signed-off-by: D.S. Ljungmark <spider@skuggor.se> --------- Signed-off-by: D.S. Ljungmark <spider@skuggor.se>
1 parent 4cf54a6 commit 328108a
Copy full SHA for 328108a

File tree

Expand file treeCollapse file tree

5 files changed

+42
-49
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+42
-49
lines changed

‎Cargo.lock

Copy file name to clipboardExpand all lines: Cargo.lock
+31-41Lines changed: 31 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

Copy file name to clipboardExpand all lines: Cargo.toml
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pgcat"
3-
version = "1.1.0"
3+
version = "1.1.1"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -22,7 +22,6 @@ once_cell = "1"
2222
sqlparser = {version = "0.34", features = ["visitor"] }
2323
log = "0.4"
2424
arc-swap = "1"
25-
env_logger = "0.10"
2625
parking_lot = "0.12.1"
2726
hmac = "0.12"
2827
sha2 = "0.10"
@@ -48,7 +47,7 @@ serde_json = "1"
4847
itertools = "0.10"
4948
clap = { version = "4.3.1", features = ["derive", "env"] }
5049
tracing = "0.1.37"
51-
tracing-subscriber = { version = "0.3.17", features = ["json"]}
50+
tracing-subscriber = { version = "0.3.17", features = ["json", "env-filter", "std"]}
5251

5352
[target.'cfg(not(target_env = "msvc"))'.dependencies]
5453
jemallocator = "0.5.0"

‎src/logger.rs

Copy file name to clipboardExpand all lines: src/logger.rs
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
use crate::cmd_args::{Args, LogFormat};
22
use tracing_subscriber;
3+
use tracing_subscriber::EnvFilter;
34

45
pub fn init(args: &Args) {
6+
// Iniitalize a default filter, and then override the builtin default "warning" with our
7+
// commandline, (default: "info")
8+
let filter = EnvFilter::from_default_env().add_directive(args.log_level.into());
9+
510
let trace_sub = tracing_subscriber::fmt()
6-
.with_max_level(args.log_level)
11+
.with_env_filter(filter)
712
.with_ansi(!args.no_color);
813

914
match args.log_format {

‎src/main.rs

Copy file name to clipboardExpand all lines: src/main.rs
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ extern crate arc_swap;
2323
extern crate async_trait;
2424
extern crate bb8;
2525
extern crate bytes;
26-
extern crate env_logger;
2726
extern crate exitcode;
2827
extern crate log;
2928
extern crate md5;

‎src/server.rs

Copy file name to clipboardExpand all lines: src/server.rs
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ impl Server {
11361136
// server connection thrashing if clients repeatedly do this.
11371137
// Instead, we ROLLBACK that transaction before putting the connection back in the pool
11381138
if self.in_transaction() {
1139-
warn!("Server returned while still in transaction, rolling back transaction");
1139+
warn!(target: "pgcat::server::cleanup", "Server returned while still in transaction, rolling back transaction");
11401140
self.query("ROLLBACK").await?;
11411141
}
11421142

@@ -1146,14 +1146,14 @@ impl Server {
11461146
// send `DISCARD ALL` if we think the session is altered instead of just sending
11471147
// it before each checkin.
11481148
if self.cleanup_state.needs_cleanup() && self.cleanup_connections {
1149-
warn!("Server returned with session state altered, discarding state ({}) for application {}", self.cleanup_state, self.application_name);
1149+
info!(target: "pgcat::server::cleanup", "Server returned with session state altered, discarding state ({}) for application {}", self.cleanup_state, self.application_name);
11501150
self.query("DISCARD ALL").await?;
11511151
self.query("RESET ROLE").await?;
11521152
self.cleanup_state.reset();
11531153
}
11541154

11551155
if self.in_copy_mode() {
1156-
warn!("Server returned while still in copy-mode");
1156+
warn!(target: "pgcat::server::cleanup", "Server returned while still in copy-mode");
11571157
}
11581158

11591159
Ok(())

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.