7
7
"errors"
8
8
"flag"
9
9
"fmt"
10
+ "io"
11
+ "log"
10
12
"net/url"
11
13
"os"
12
14
"path"
@@ -16,11 +18,13 @@ import (
16
18
slogger "github.com/osbuild/osbuild-composer/pkg/splunk_logger"
17
19
18
20
"github.com/BurntSushi/toml"
21
+ "github.com/coreos/go-systemd/journal"
19
22
"github.com/sirupsen/logrus"
20
23
21
24
"github.com/osbuild/images/pkg/arch"
22
25
"github.com/osbuild/images/pkg/dnfjson"
23
26
"github.com/osbuild/osbuild-composer/internal/cloud/awscloud"
27
+ "github.com/osbuild/osbuild-composer/internal/common"
24
28
"github.com/osbuild/osbuild-composer/internal/upload/azure"
25
29
"github.com/osbuild/osbuild-composer/internal/upload/koji"
26
30
"github.com/osbuild/osbuild-composer/internal/upload/oci"
@@ -167,6 +171,11 @@ func RequestAndRunJob(client *worker.Client, acceptedJobTypes []string, jobImpls
167
171
}
168
172
169
173
func main () {
174
+ // Redirect Go standard logger into logrus before it's used by other packages
175
+ log .SetOutput (common .Logger ())
176
+ // Ensure the Go standard logger does not have any prefix or timestamp
177
+ log .SetFlags (0 )
178
+
170
179
var unix bool
171
180
flag .BoolVar (& unix , "unix" , false , "Interpret 'address' as a path to a unix domain socket instead of a network address" )
172
181
@@ -188,6 +197,39 @@ func main() {
188
197
logrus .Fatalf ("Could not load config file '%s': %v" , configFile , err )
189
198
}
190
199
200
+ logrus .SetReportCaller (true )
201
+ logrus .AddHook (& common.BuildHook {})
202
+ logrus .SetOutput (os .Stdout )
203
+ logLevel , err := logrus .ParseLevel (config .Logging .Level )
204
+ if err == nil {
205
+ logrus .SetLevel (logLevel )
206
+ } else {
207
+ logrus .Info ("Failed to load loglevel from config:" , err )
208
+ }
209
+
210
+ // logger configuration
211
+ switch config .Logging .Format {
212
+ case "journal" , "" :
213
+ // If we are running under systemd, use the journal. Otherwise,
214
+ // fallback to text formatter.
215
+ if journal .Enabled () {
216
+ logrus .Info ("Switching to journal logging mode, use logging.no_discard to keep writing to standard output/error" )
217
+ logrus .SetFormatter (& logrus.JSONFormatter {})
218
+ logrus .AddHook (& common.JournalHook {})
219
+ if ! config .Logging .NoDiscard {
220
+ logrus .SetOutput (io .Discard )
221
+ }
222
+ } else {
223
+ logrus .SetFormatter (& logrus.TextFormatter {})
224
+ }
225
+ case "text" :
226
+ logrus .SetFormatter (& logrus.TextFormatter {})
227
+ case "json" :
228
+ logrus .SetFormatter (& logrus.JSONFormatter {})
229
+ default :
230
+ logrus .Infof ("Failed to set logging format from config, '%s' is not a valid option" , config .Logging .Format )
231
+ }
232
+
191
233
logrus .Info ("Composer configuration:" )
192
234
encoder := toml .NewEncoder (logrus .StandardLogger ().WriterLevel (logrus .InfoLevel ))
193
235
err = encoder .Encode (& config )
0 commit comments