Skip to content

Commit

Permalink
logging level flag
Browse files Browse the repository at this point in the history
  • Loading branch information
fopina committed Dec 13, 2022
1 parent 2f1167e commit f9ede9e
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 8 deletions.
59 changes: 59 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
project_name: smtp_to_telegram

release:
prerelease: auto

builds:
- id: smtp_to_telegram
env:
- CGO_ENABLED=0
goos:
- windows
- darwin
- linux
goarch:
- amd64
- arm64
- arm
goarm:
- '7'
ldflags:
- -s -w -X main.Version={{.Version}}
tags:
- urfave_cli_no_docs

snapshot:
name_template: "{{ .Tag }}-next"

dockers:
- &xdocker
image_templates:
- fopina/{{ .ProjectName }}:{{ .Version }}-amd64
dockerfile: Dockerfile.release
use: buildx
goos: linux
goarch: amd64
build_flag_templates:
- --platform=linux/amd64

- <<: *xdocker
image_templates:
- fopina/{{ .ProjectName }}:{{ .Version }}-arm64
goarch: arm64
build_flag_templates:
- --platform=linux/arm64/v8

- <<: *xdocker
image_templates:
- fopina/{{ .ProjectName }}:{{ .Version }}-armv7
goarch: arm
goarm: 7
build_flag_templates:
- --platform=linux/arm/v7

docker_manifests:
- name_template: fopina/{{ .ProjectName }}:latest
image_templates:
- fopina/{{ .ProjectName }}:{{ .Version }}-amd64
- fopina/{{ .ProjectName }}:{{ .Version }}-arm64
- fopina/{{ .ProjectName }}:{{ .Version }}-armv7
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ARG GOPROXY=direct
RUN CGO_ENABLED=0 GOOS=linux go build \
-ldflags "-s -w \
-X main.Version=${ST_VERSION:-UNKNOWN_RELEASE}" \
-tags urfave_cli_no_docs \
-a -o smtp_to_telegram


Expand Down
25 changes: 17 additions & 8 deletions smtp_to_telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
units "github.com/docker/go-units"
"github.com/flashmob/go-guerrilla"
"github.com/flashmob/go-guerrilla/backends"
"github.com/flashmob/go-guerrilla/log"
"github.com/flashmob/go-guerrilla/mail"
"github.com/jhillyerd/enmime"
"github.com/urfave/cli/v2"
"io/ioutil"
"mime"
"mime/multipart"
Expand All @@ -23,6 +16,14 @@ import (
"strings"
"syscall"
"time"

units "github.com/docker/go-units"
"github.com/flashmob/go-guerrilla"
"github.com/flashmob/go-guerrilla/backends"
"github.com/flashmob/go-guerrilla/log"
"github.com/flashmob/go-guerrilla/mail"
"github.com/jhillyerd/enmime"
"github.com/urfave/cli/v2"
)

var (
Expand All @@ -38,6 +39,7 @@ type SmtpConfig struct {
smtpListen string
smtpPrimaryHost string
smtpMaxEnvelopeSize int64
logLevel string
}

type TelegramConfig struct {
Expand Down Expand Up @@ -103,6 +105,7 @@ func main() {
smtpListen: c.String("smtp-listen"),
smtpPrimaryHost: c.String("smtp-primary-host"),
smtpMaxEnvelopeSize: smtpMaxEnvelopeSize,
logLevel: c.String("log-level"),
}
forwardedAttachmentMaxSize, err := units.FromHumanSize(c.String("forwarded-attachment-max-size"))
if err != nil {
Expand Down Expand Up @@ -213,6 +216,12 @@ func main() {
Value: 4095,
EnvVars: []string{"ST_MESSAGE_LENGTH_TO_SEND_AS_FILE"},
},
&cli.StringFlag{
Name: "log-level",
Usage: "Logging level (info, debug, error, panic).",
Value: "info",
EnvVars: []string{"ST_LOG_LEVEL"},
},
}
err := app.Run(os.Args)
if err != nil {
Expand All @@ -224,7 +233,7 @@ func main() {
func SmtpStart(
smtpConfig *SmtpConfig, telegramConfig *TelegramConfig) (guerrilla.Daemon, error) {

cfg := &guerrilla.AppConfig{LogFile: log.OutputStdout.String()}
cfg := &guerrilla.AppConfig{LogFile: log.OutputStdout.String(), LogLevel: smtpConfig.logLevel}

cfg.AllowedHosts = []string{"."}

Expand Down

0 comments on commit f9ede9e

Please sign in to comment.