webhookd/pkg/worker/work_log.go
Nicolas Carlier 1dab1e968d feat(notification): complete refactoring of the notification system
- URL based configuration
- Only prefixed output lines are notified
- HTTP notifier: send a JSON with notification in the text attribute
- SMTP notifier: send an email with notification text in body
2018-12-30 21:00:22 +00:00

26 lines
555 B
Go

package worker
import (
"fmt"
"os"
"path"
"path/filepath"
"github.com/ncarlier/webhookd/pkg/config"
"github.com/ncarlier/webhookd/pkg/tools"
)
// RetrieveLogFile retrieve work log with its name and id
func RetrieveLogFile(id, name string) (*os.File, error) {
logPattern := path.Join(*config.Get().LogDir, fmt.Sprintf("%s_%s_*.txt", tools.ToSnakeCase(name), id))
files, err := filepath.Glob(logPattern)
if err != nil {
return nil, err
}
if len(files) > 0 {
filename := files[len(files)-1]
return os.Open(filename)
}
return nil, nil
}