Skip to content

Commit

Permalink
add tracing and brush up export logging
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Jul 19, 2022
1 parent 5adcf1a commit 32b889d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type App struct {
cfg Config
}

// New creates a new slackdump app. It inherits the logging from slack optiond
// New creates a new slackdump app. It inherits the logging from slack options
// in the Config.
func New(cfg Config, provider auth.Provider) (*App, error) {
if err := cfg.Validate(); err != nil {
Expand Down
29 changes: 16 additions & 13 deletions internal/export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/slack-go/slack"

"github.com/rusq/dlog"
"github.com/rusq/slackdump/v2"
"github.com/rusq/slackdump/v2/downloader"
"github.com/rusq/slackdump/v2/fsadapter"
Expand All @@ -25,9 +24,9 @@ import (

// Export is the instance of Slack Exporter.
type Export struct {
fs fsadapter.FS // target filesystem
sd *slackdump.Session // Session instance
dlog logger.Interface
fs fsadapter.FS // target filesystem
sd *slackdump.Session // Session instance
lg logger.Interface

// time window
opts Options
Expand All @@ -36,9 +35,9 @@ type Export struct {
// New creates a new Export instance, that will save export to the
// provided fs.
func New(sd *slackdump.Session, fs fsadapter.FS, cfg Options) *Export {
se := &Export{fs: fs, sd: sd, dlog: cfg.Logger, opts: cfg}
if se.dlog == nil {
se.dlog = logger.Default
se := &Export{fs: fs, sd: sd, lg: cfg.Logger, opts: cfg}
if se.lg == nil {
se.lg = logger.Default
}
network.Logger = se.l()
return se
Expand Down Expand Up @@ -72,7 +71,11 @@ func (se *Export) messages(ctx context.Context, users types.Users) error {
if se.opts.IncludeFiles {
// start the downloader
dl.Start(ctx)
defer dl.Stop()
defer func() {
trace.Log(ctx, "info", "waiting for downloads to finish")
dl.Stop()
trace.Log(ctx, "info", "downloader stopped")
}()
}

var chans []slack.Channel
Expand Down Expand Up @@ -118,7 +121,7 @@ func (se *Export) exclusiveExport(ctx context.Context, dl *downloader.Client, us
if err := se.sd.StreamChannels(ctx, slackdump.AllChanTypes, func(ch slack.Channel) error {
if include, ok := listIdx[ch.ID]; ok && !include {
trace.Logf(ctx, "info", "skipping %s", ch.ID)
dlog.Printf("skipping: %s", ch.ID)
se.lg.Printf("skipping: %s", ch.ID)
return nil
}
if err := se.exportConversation(ctx, dl, uidx, ch); err != nil {
Expand Down Expand Up @@ -155,7 +158,7 @@ func (se *Export) inclusiveExport(ctx context.Context, dl *downloader.Client, us
for _, entry := range list.Include {
if include, ok := elIdx[entry]; ok && !include {
trace.Logf(ctx, "info", "skipping %s", entry)
dlog.Printf("skipping: %s", entry)
se.lg.Printf("skipping: %s", entry)
continue
}
sl, err := structures.ParseLink(entry)
Expand Down Expand Up @@ -288,8 +291,8 @@ func serialize(w io.Writer, data any) error {
}

func (se *Export) l() logger.Interface {
if se.dlog == nil {
se.dlog = logger.Default
if se.lg == nil {
se.lg = logger.Default
}
return se.dlog
return se.lg
}

0 comments on commit 32b889d

Please sign in to comment.