Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce logging #214

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmd/calendarsync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ func main() {
}

func Run(c *cli.Context) error {
log.Infof("started calendarsync version %v", Version)

if c.Bool(flagVersion) {
fmt.Println("Version:", Version)
os.Exit(0)
Expand Down Expand Up @@ -197,7 +199,7 @@ func Run(c *cli.Context) error {
if cfg.UpdateConcurrency != 0 {
controller.SetConcurrency(cfg.UpdateConcurrency)
}
log.Info("loaded sync controller")
log.Debug("loaded sync controller")

if c.Bool("clean") {
err = controller.CleanUp(c.Context, startTime, endTime)
Expand All @@ -211,5 +213,6 @@ func Run(c *cli.Context) error {
log.Fatalf("we had some errors during synchronization:\n%v", err)
}
}
log.Info("sync complete")
return nil
}
4 changes: 2 additions & 2 deletions internal/adapter/google/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (c *CalendarAPI) SetupOauth2(ctx context.Context, credentials auth.Credenti
}

c.authenticated = true
c.logger.Info("using stored credentials")
c.logger.Debug("using stored credentials")
}

return nil
Expand Down Expand Up @@ -178,7 +178,7 @@ func (c *CalendarAPI) EventsInTimeframe(ctx context.Context, start time.Time, en
return nil, err
}

c.logger.Infof("loaded %d events between %s and %s.", len(events), start.Format(time.RFC1123), end.Format(time.RFC1123))
c.logger.Infof("loaded %d events between %s and %s.", len(events), start.Format(time.DateOnly), end.Format(time.DateOnly))

return events, nil
}
Expand Down
4 changes: 2 additions & 2 deletions internal/adapter/outlook_http/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (c *CalendarAPI) SetupOauth2(ctx context.Context, credentials auth.Credenti
}

c.authenticated = true
c.logger.Info("using stored credentials")
c.logger.Debug("using stored credentials")
c.logger.Debugf("expiry time of stored token: %s", expiry.String())
}

Expand Down Expand Up @@ -207,7 +207,7 @@ func (c *CalendarAPI) EventsInTimeframe(ctx context.Context, start time.Time, en
return nil, err
}

c.logger.Infof("loaded %d events between %s and %s.", len(events), start.Format(time.RFC1123), end.Format(time.RFC1123))
c.logger.Infof("loaded %d events between %s and %s.", len(events), start.Format(time.DateOnly), end.Format(time.DateOnly))

return events, nil
}
Expand Down
9 changes: 9 additions & 0 deletions internal/adapter/zep/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ type CalendarAPI struct {
client *caldav.Client

calendarID string
logger *log.Logger

principal string
homeSet string
}

// Assert that the expected interfaces are implemented
var _ port.Configurable = &CalendarAPI{}
var _ port.LogSetter = &CalendarAPI{}

func (zep *CalendarAPI) GetCalendarHash() string {
var id []byte
Expand Down Expand Up @@ -95,6 +97,9 @@ func (zep *CalendarAPI) EventsInTimeframe(ctx context.Context, start time.Time,
}

var syncEvents []models.Event

zep.logger.Infof("loaded %d events between %s and %s.", len(absences), start.Format(time.DateOnly), end.Format(time.DateOnly))

for _, v := range absences {
syncEvents = append(syncEvents,
models.Event{
Expand Down Expand Up @@ -204,3 +209,7 @@ func safeGetComponentPropValueString(event ical.Event, key string) string {
}
return prop.Value
}

func (zep *CalendarAPI) SetLogger(logger *log.Logger) {
zep.logger = logger
}
11 changes: 6 additions & 5 deletions internal/sync/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (p Controller) SynchroniseTimeframe(ctx context.Context, start time.Time, e
filteredEventsInSource := []models.Event{}

for _, filter := range p.filters {
p.logger.Info("loaded filter", "name", filter.Name())
p.logger.Debug("loaded filter", "name", filter.Name())
}

for _, event := range eventsInSource {
Expand All @@ -96,14 +96,15 @@ func (p Controller) SynchroniseTimeframe(ctx context.Context, start time.Time, e

// Output which transformers were loaded
for _, trans := range p.transformers {
p.logger.Info("loaded transformer", "name", trans.Name())
p.logger.Debug("loaded transformer", "name", trans.Name())
}

for _, event := range filteredEventsInSource {
transformedEventsInSource = append(transformedEventsInSource, TransformEvent(event, p.transformers...))
}

toCreate, toUpdate, toDelete := p.diffEvents(transformedEventsInSource, eventsInSink)
log.Infof("found %d new, %d changed, and %d deleted events", len(toCreate), len(toUpdate), len(toDelete))
if dryRun {
p.logger.Warn("we're running in dry run mode, no changes will be executed")
return nil
Expand Down Expand Up @@ -200,7 +201,7 @@ func (p Controller) diffEvents(sourceEvents []models.Event, sinkEvents []models.
// - Delete event (in calendar A)
// - Run sync from calendar B to calendar A. This will copy (and thereby resurrect) the event.
//
// Solution: Ignore events the originate from the sink, but no longer exist there.
// Solution: Ignore events that originate from the sink, but no longer exist there.
if event.Metadata.SourceID == p.sink.GetCalendarHash() {
p.logger.Info("skipping event as it originates from the sink, but no longer exists there", logFields(event)...)
continue
Expand All @@ -217,7 +218,7 @@ func (p Controller) diffEvents(sourceEvents []models.Event, sinkEvents []models.
updateEvents = append(updateEvents, sinkEvent.Overwrite(event))

default:
p.logger.Info("event in sync", logFields(event)...)
p.logger.Debug("event in sync", logFields(event)...)
}
}

Expand All @@ -238,7 +239,7 @@ func (p Controller) diffEvents(sourceEvents []models.Event, sinkEvents []models.
default:
// Do not delete events which were not loaded by the current sourceEvents-adapter.
// This enables the synchronization of multiple sources without them interfering.
p.logger.Info("event is not in sourceEvents but was not synced with this source adapter, skipping", logFields(event)...)
p.logger.Debug("event is not in sourceEvents but was not synced with this source adapter, skipping", logFields(event)...)
}
}

Expand Down
Loading