0
0
Fork 0
mirror of https://github.com/crazy-max/diun.git synced 2025-03-16 04:13:30 +00:00

Use zoneinfo from Go ()

Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2020-11-01 00:22:39 +01:00 committed by GitHub
parent cf0b5c01e2
commit 67071ea11f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 19 additions and 24 deletions
.github/workflows
Dockerfile
cmd
docs
internal
app
logging
model

View file

@ -4,7 +4,6 @@ on:
push:
branches:
- '**'
- 'v*'
tags:
- 'v*'
paths-ignore:
@ -23,7 +22,6 @@ on:
- 'mkdocs.yml'
jobs:
go:
runs-on: ubuntu-latest
steps:

View file

@ -31,7 +31,6 @@ LABEL maintainer="CrazyMax"
RUN apk --update --no-cache add \
ca-certificates \
libressl \
tzdata \
&& rm -rf /tmp/* /var/cache/apk/*
COPY --from=builder /app/diun /usr/local/bin/diun

View file

@ -7,7 +7,6 @@ import (
"runtime"
"strings"
"syscall"
"time"
"github.com/alecthomas/kong"
"github.com/crazy-max/diun/v4/internal/app"
@ -54,14 +53,8 @@ func main() {
Summary: true,
}))
// Load timezone location
location, err := time.LoadLocation(cli.Timezone)
if err != nil {
log.Fatal().Err(err).Msgf("Cannot load timezone %s", cli.Timezone)
}
// Init
logging.Configure(&cli, location)
logging.Configure(&cli)
log.Info().Str("version", version).Msgf("Starting %s", meta.Name)
// Handle os signals
@ -82,7 +75,7 @@ func main() {
log.Debug().Msg(cfg.String())
// Init
if diun, err = app.New(meta, cli, cfg, location); err != nil {
if diun, err = app.New(meta, cli, cfg); err != nil {
log.Fatal().Err(err).Msgf("Cannot initialize %s", meta.Name)
}

View file

@ -1,5 +1,17 @@
# FAQ
## Timezone
By default, all interpretation and scheduling is done with your local timezone (`TZ` environment variable).
Cron schedule may also override the timezone to be interpreted in by providing an additional space-separated field
at the beginning of the cron spec, of the form `CRON_TZ=<timezone>`:
```yaml
watch:
schedule: "CRON_TZ=Asia/Tokyo 0 */6 * * *"
```
## Test notifications
Through the [command line](usage/cli.md) with:

View file

@ -36,7 +36,6 @@ and [File](providers/file.md) providers available
* Get notified through Gotify, Mail, Slack, Telegram and [more](config/index.md#reference)
* [Healthchecks support](config/watch.md#healthchecks) to monitor Diun watcher
* Enhanced logging
* Timezone can be changed
* Official [Docker image available](install/docker.md)
## License

View file

@ -21,6 +21,7 @@ User=diun
Group=diun
ExecStart=/usr/local/bin/diun --config /etc/diun/diun.yml --log-level info
Restart=always
#Environment=TZ=Europe/Paris
Environment=DIUN_DB_PATH=/var/lib/diun/diun.db
[Install]

View file

@ -18,7 +18,6 @@ Flags:
--help Show context-sensitive help.
--version
--config=STRING Diun configuration file ($CONFIG).
--timezone="UTC" Timezone assigned to Diun ($TZ).
--log-level="info" Set log level ($LOG_LEVEL).
--log-json Enable JSON logging output ($LOG_JSON).
--log-caller Add file:line of the caller to log output ($LOG_CALLER).
@ -32,7 +31,6 @@ Following environment variables can be used in place:
| Name | Default | Description |
|--------------------|---------------|---------------|
| `CONFIG` | | Diun configuration file |
| `TZ` | `UTC` | Timezone assigned |
| `LOG_LEVEL` | `info` | Log level output |
| `LOG_JSON` | `false` | Enable JSON logging output |
| `LOG_CALLER` | `false` | Enable to add `file:line` of the caller |

View file

@ -39,14 +39,14 @@ type Diun struct {
}
// New creates new diun instance
func New(meta model.Meta, cli model.Cli, cfg *config.Config, location *time.Location) (*Diun, error) {
func New(meta model.Meta, cli model.Cli, cfg *config.Config) (*Diun, error) {
var err error
diun := &Diun{
meta: meta,
cfg: cfg,
cron: cron.New(cron.WithLocation(location), cron.WithParser(cron.NewParser(
cron.SecondOptional|cron.Minute|cron.Hour|cron.Dom|cron.Month|cron.Dow|cron.Descriptor),
cron: cron.New(cron.WithParser(cron.NewParser(
cron.SecondOptional | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor),
)),
}

View file

@ -13,14 +13,10 @@ import (
)
// Configure configures logger
func Configure(cli *model.Cli, location *time.Location) {
func Configure(cli *model.Cli) {
var err error
var w io.Writer
zerolog.TimestampFunc = func() time.Time {
return time.Now().In(location)
}
if !cli.LogJSON {
w = zerolog.ConsoleWriter{
Out: os.Stdout,

View file

@ -6,7 +6,6 @@ import "github.com/alecthomas/kong"
type Cli struct {
Version kong.VersionFlag
Cfgfile string `kong:"name='config',env='CONFIG',help='Diun configuration file.'"`
Timezone string `kong:"name='timezone',env='TZ',default='UTC',help='Timezone assigned to Diun.'"`
LogLevel string `kong:"name='log-level',env='LOG_LEVEL',default='info',help='Set log level.'"`
LogJSON bool `kong:"name='log-json',env='LOG_JSON',default='false',help='Enable JSON logging output.'"`
LogCaller bool `kong:"name='log-caller',env='LOG_CALLER',default='false',help='Add file:line of the caller to log output.'"`