diff --git a/config/config.md b/config/config.md
index d413936ff3cd..6a48ed717e69 100644
--- a/config/config.md
+++ b/config/config.md
@@ -161,6 +161,7 @@
| `logging.otlp_endpoint` | String | `http://localhost:4317` | The OTLP tracing endpoint. |
| `logging.append_stdout` | Bool | `true` | Whether to append logs to stdout. |
| `logging.log_format` | String | `text` | The log format. Can be `text`/`json`. |
+| `logging.max_log_files` | Integer | `720` | The maximum amount of log files. |
| `logging.tracing_sample_ratio` | -- | -- | The percentage of tracing will be sampled and exported.
Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
ratio > 1 are treated as 1. Fractions < 0 are treated as 0 |
| `logging.tracing_sample_ratio.default_ratio` | Float | `1.0` | -- |
| `logging.slow_query` | -- | -- | The slow query log options. |
@@ -251,6 +252,7 @@
| `logging.otlp_endpoint` | String | `http://localhost:4317` | The OTLP tracing endpoint. |
| `logging.append_stdout` | Bool | `true` | Whether to append logs to stdout. |
| `logging.log_format` | String | `text` | The log format. Can be `text`/`json`. |
+| `logging.max_log_files` | Integer | `720` | The maximum amount of log files. |
| `logging.tracing_sample_ratio` | -- | -- | The percentage of tracing will be sampled and exported.
Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
ratio > 1 are treated as 1. Fractions < 0 are treated as 0 |
| `logging.tracing_sample_ratio.default_ratio` | Float | `1.0` | -- |
| `logging.slow_query` | -- | -- | The slow query log options. |
@@ -320,6 +322,7 @@
| `logging.otlp_endpoint` | String | `http://localhost:4317` | The OTLP tracing endpoint. |
| `logging.append_stdout` | Bool | `true` | Whether to append logs to stdout. |
| `logging.log_format` | String | `text` | The log format. Can be `text`/`json`. |
+| `logging.max_log_files` | Integer | `720` | The maximum amount of log files. |
| `logging.tracing_sample_ratio` | -- | -- | The percentage of tracing will be sampled and exported.
Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
ratio > 1 are treated as 1. Fractions < 0 are treated as 0 |
| `logging.tracing_sample_ratio.default_ratio` | Float | `1.0` | -- |
| `logging.slow_query` | -- | -- | The slow query log options. |
@@ -476,6 +479,7 @@
| `logging.otlp_endpoint` | String | `http://localhost:4317` | The OTLP tracing endpoint. |
| `logging.append_stdout` | Bool | `true` | Whether to append logs to stdout. |
| `logging.log_format` | String | `text` | The log format. Can be `text`/`json`. |
+| `logging.max_log_files` | Integer | `720` | The maximum amount of log files. |
| `logging.tracing_sample_ratio` | -- | -- | The percentage of tracing will be sampled and exported.
Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
ratio > 1 are treated as 1. Fractions < 0 are treated as 0 |
| `logging.tracing_sample_ratio.default_ratio` | Float | `1.0` | -- |
| `logging.slow_query` | -- | -- | The slow query log options. |
@@ -526,6 +530,7 @@
| `logging.otlp_endpoint` | String | `http://localhost:4317` | The OTLP tracing endpoint. |
| `logging.append_stdout` | Bool | `true` | Whether to append logs to stdout. |
| `logging.log_format` | String | `text` | The log format. Can be `text`/`json`. |
+| `logging.max_log_files` | Integer | `720` | The maximum amount of log files. |
| `logging.tracing_sample_ratio` | -- | -- | The percentage of tracing will be sampled and exported.
Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
ratio > 1 are treated as 1. Fractions < 0 are treated as 0 |
| `logging.tracing_sample_ratio.default_ratio` | Float | `1.0` | -- |
| `logging.slow_query` | -- | -- | The slow query log options. |
diff --git a/config/datanode.example.toml b/config/datanode.example.toml
index 06a59ebd6fcd..22670f857c06 100644
--- a/config/datanode.example.toml
+++ b/config/datanode.example.toml
@@ -580,6 +580,9 @@ append_stdout = true
## The log format. Can be `text`/`json`.
log_format = "text"
+## The maximum amount of log files.
+max_log_files = 720
+
## The percentage of tracing will be sampled and exported.
## Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
## ratio > 1 are treated as 1. Fractions < 0 are treated as 0
diff --git a/config/flownode.example.toml b/config/flownode.example.toml
index 9d6d2fe5aa68..34825542fa06 100644
--- a/config/flownode.example.toml
+++ b/config/flownode.example.toml
@@ -78,6 +78,9 @@ append_stdout = true
## The log format. Can be `text`/`json`.
log_format = "text"
+## The maximum amount of log files.
+max_log_files = 720
+
## The percentage of tracing will be sampled and exported.
## Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
## ratio > 1 are treated as 1. Fractions < 0 are treated as 0
diff --git a/config/frontend.example.toml b/config/frontend.example.toml
index cc9698f61e88..83e7808d4667 100644
--- a/config/frontend.example.toml
+++ b/config/frontend.example.toml
@@ -185,6 +185,9 @@ append_stdout = true
## The log format. Can be `text`/`json`.
log_format = "text"
+## The maximum amount of log files.
+max_log_files = 720
+
## The percentage of tracing will be sampled and exported.
## Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
## ratio > 1 are treated as 1. Fractions < 0 are treated as 0
diff --git a/config/metasrv.example.toml b/config/metasrv.example.toml
index 8431940b45aa..416f5ee6ef23 100644
--- a/config/metasrv.example.toml
+++ b/config/metasrv.example.toml
@@ -172,6 +172,9 @@ append_stdout = true
## The log format. Can be `text`/`json`.
log_format = "text"
+## The maximum amount of log files.
+max_log_files = 720
+
## The percentage of tracing will be sampled and exported.
## Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
## ratio > 1 are treated as 1. Fractions < 0 are treated as 0
diff --git a/config/standalone.example.toml b/config/standalone.example.toml
index 2d14b6550f3c..4c40d2dde6db 100644
--- a/config/standalone.example.toml
+++ b/config/standalone.example.toml
@@ -624,6 +624,9 @@ append_stdout = true
## The log format. Can be `text`/`json`.
log_format = "text"
+## The maximum amount of log files.
+max_log_files = 720
+
## The percentage of tracing will be sampled and exported.
## Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
## ratio > 1 are treated as 1. Fractions < 0 are treated as 0
diff --git a/src/common/telemetry/src/logging.rs b/src/common/telemetry/src/logging.rs
index c21766f04dc9..4c5a9ee18f88 100644
--- a/src/common/telemetry/src/logging.rs
+++ b/src/common/telemetry/src/logging.rs
@@ -54,6 +54,9 @@ pub struct LoggingOptions {
/// The log format that can be one of "json" or "text". Default is "text".
pub log_format: LogFormat,
+ /// The maximum number of log files set by default.
+ pub max_log_files: usize,
+
/// Whether to append logs to stdout. Default is true.
pub append_stdout: bool,
@@ -116,6 +119,8 @@ impl Default for LoggingOptions {
tracing_sample_ratio: None,
append_stdout: true,
slow_query: SlowQueryOptions::default(),
+ // Rotation hourly, 24 files per day, keeps info log files of 30 days
+ max_log_files: 720,
}
}
}
@@ -206,8 +211,17 @@ pub fn init_global_logging(
// Configure the file logging layer with rolling policy.
let file_logging_layer = if !opts.dir.is_empty() {
- let rolling_appender =
- RollingFileAppender::new(Rotation::HOURLY, &opts.dir, "greptimedb");
+ let rolling_appender = RollingFileAppender::builder()
+ .rotation(Rotation::HOURLY)
+ .filename_prefix("greptimedb")
+ .max_log_files(opts.max_log_files)
+ .build(&opts.dir)
+ .unwrap_or_else(|e| {
+ panic!(
+ "initializing rolling file appender at {} failed: {}",
+ &opts.dir, e
+ )
+ });
let (writer, guard) = tracing_appender::non_blocking(rolling_appender);
guards.push(guard);
@@ -228,8 +242,17 @@ pub fn init_global_logging(
// Configure the error file logging layer with rolling policy.
let err_file_logging_layer = if !opts.dir.is_empty() {
- let rolling_appender =
- RollingFileAppender::new(Rotation::HOURLY, &opts.dir, "greptimedb-err");
+ let rolling_appender = RollingFileAppender::builder()
+ .rotation(Rotation::HOURLY)
+ .filename_prefix("greptimedb-err")
+ .max_log_files(opts.max_log_files)
+ .build(&opts.dir)
+ .unwrap_or_else(|e| {
+ panic!(
+ "initializing rolling file appender at {} failed: {}",
+ &opts.dir, e
+ )
+ });
let (writer, guard) = tracing_appender::non_blocking(rolling_appender);
guards.push(guard);
@@ -256,8 +279,17 @@ pub fn init_global_logging(
};
let slow_query_logging_layer = if !opts.dir.is_empty() && opts.slow_query.enable {
- let rolling_appender =
- RollingFileAppender::new(Rotation::HOURLY, &opts.dir, "greptimedb-slow-queries");
+ let rolling_appender = RollingFileAppender::builder()
+ .rotation(Rotation::HOURLY)
+ .filename_prefix("greptimedb-slow-queries")
+ .max_log_files(opts.max_log_files)
+ .build(&opts.dir)
+ .unwrap_or_else(|e| {
+ panic!(
+ "initializing rolling file appender at {} failed: {}",
+ &opts.dir, e
+ )
+ });
let (writer, guard) = tracing_appender::non_blocking(rolling_appender);
guards.push(guard);
diff --git a/src/log-store/src/kafka/client_manager.rs b/src/log-store/src/kafka/client_manager.rs
index 589d5a900efb..6dfb97b027cc 100644
--- a/src/log-store/src/kafka/client_manager.rs
+++ b/src/log-store/src/kafka/client_manager.rs
@@ -182,7 +182,7 @@ mod tests {
use super::*;
- /// Creates `num_topiocs` number of topics each will be decorated by the given decorator.
+ /// Creates `num_topics` number of topics each will be decorated by the given decorator.
pub async fn create_topics(
num_topics: usize,
decorator: F,
diff --git a/tests-integration/tests/http.rs b/tests-integration/tests/http.rs
index 5f3eb854bbe6..20a0f4edd2ae 100644
--- a/tests-integration/tests/http.rs
+++ b/tests-integration/tests/http.rs
@@ -833,6 +833,7 @@ max_retry_times = 3
retry_delay = "500ms"
[logging]
+max_log_files = 720
append_stdout = true
enable_otlp_tracing = false