Skip to content

Commit 840a077

Browse files
committed
separate config logging section
1 parent abbbe47 commit 840a077

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ Create `/etc/graphite-clickhouse/graphite-clickhouse.conf`
5555
```toml
5656
[common]
5757
listen = ":9090"
58-
logfile = "/var/log/graphite-clickhouse/graphite-clickhouse.log"
59-
loglevel = "info"
6058
max-cpu = 1
6159

6260
[clickhouse]
@@ -70,6 +68,10 @@ rollup-conf = "/etc/graphite-clickhouse/rollup.xml"
7068
extra-prefix = ""
7169
data-timeout = "1m0s"
7270
tree-timeout = "1m0s"
71+
72+
[logging]
73+
file = "/var/log/graphite-clickhouse/graphite-clickhouse.log"
74+
level = "info"
7375
```
7476

7577
## Run on same host with graphite-web

config/config.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"time"
88

99
"github.com/BurntSushi/toml"
10-
"github.com/uber-go/zap"
1110

1211
"github.com/lomik/graphite-clickhouse/helper/rollup"
1312
)
@@ -37,9 +36,7 @@ func (d *Duration) Value() time.Duration {
3736
}
3837

3938
type Common struct {
40-
Listen string `toml:"listen"`
41-
LogFile string `toml:"logfile"`
42-
LogLevel zap.Level `toml:"loglevel"`
39+
Listen string `toml:"listen"`
4340
// MetricPrefix string `toml:"metric-prefix"`
4441
// MetricInterval *Duration `toml:"metric-interval"`
4542
// MetricEndpoint string `toml:"metric-endpoint"`
@@ -56,20 +53,24 @@ type ClickHouse struct {
5653
ExtraPrefix string `toml:"extra-prefix"`
5754
}
5855

56+
type Logging struct {
57+
File string `toml:"file"`
58+
Level string `toml:"level"`
59+
}
60+
5961
// Config ...
6062
type Config struct {
6163
Common Common `toml:"common"`
6264
ClickHouse ClickHouse `toml:"clickhouse"`
65+
Logging Logging `toml:"logging"`
6366
Rollup *rollup.Rollup `toml:"-"`
6467
}
6568

6669
// NewConfig ...
6770
func New() *Config {
6871
cfg := &Config{
6972
Common: Common{
70-
Listen: ":9090",
71-
LogFile: "/var/log/graphite-clickhouse/graphite-clickhouse.log",
72-
LogLevel: zap.InfoLevel,
73+
Listen: ":9090",
7374
// MetricPrefix: "carbon.graphite-clickhouse.{host}",
7475
// MetricInterval: &Duration{
7576
// Duration: time.Minute,
@@ -90,6 +91,10 @@ func New() *Config {
9091
},
9192
RollupConf: "/etc/graphite-clickhouse/rollup.xml",
9293
},
94+
Logging: Logging{
95+
File: "/var/log/graphite-clickhouse/graphite-clickhouse.log",
96+
Level: "info",
97+
},
9398
}
9499

95100
return cfg

graphite-clickhouse.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,25 @@ func main() {
108108
}
109109
runtime.GOMAXPROCS(cfg.Common.MaxCPU)
110110

111-
zapOutput, err := zapwriter.New(cfg.Common.LogFile)
111+
zapOutput, err := zapwriter.New(cfg.Logging.File)
112112
if err != nil {
113113
log.Fatal(err)
114114
}
115115

116+
var logLevel zap.Level
117+
if err = logLevel.UnmarshalText([]byte(cfg.Logging.Level)); err != nil {
118+
log.Fatal(err)
119+
}
120+
121+
dynamicLevel := zap.DynamicLevel()
122+
dynamicLevel.SetLevel(logLevel)
123+
116124
logger := zap.New(
117125
zapwriter.NewMixedEncoder(),
118126
zap.AddCaller(),
119127
zap.Output(zapOutput),
128+
dynamicLevel,
120129
)
121-
logger.SetLevel(cfg.Common.LogLevel)
122130

123131
/* CONFIG end */
124132

0 commit comments

Comments
 (0)