1- // Package logging manages setup of common logging interfaces and settings. We set the log
2- // level to all levels but we only show on stdout the info, error, and fatal levels. All
3- // other error levels are written only to a log file.
4- package logging
1+ package cli
52
63import (
74 "fmt"
@@ -13,6 +10,9 @@ import (
1310 "github.com/fatih/color"
1411 "github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
1512 "github.com/sirupsen/logrus"
13+ ctrllog "sigs.k8s.io/controller-runtime/pkg/log"
14+ "sigs.k8s.io/controller-runtime/pkg/log/zap"
15+ ctrlzap "sigs.k8s.io/controller-runtime/pkg/log/zap"
1616)
1717
1818// MaxLogFiles is the maximum number of log files we keep.
@@ -111,11 +111,22 @@ func SetupLogging() {
111111 logpath := runtimeconfig .PathToLog (fname )
112112 logfile , err := os .OpenFile (logpath , os .O_CREATE | os .O_WRONLY | os .O_APPEND , 0400 )
113113 if err != nil {
114- logrus .Warnf ("unable to setup logging: %v" , err )
114+ logrus .Warnf ("Unable to setup logging: %v" , err )
115115 return
116116 }
117117 logrus .SetOutput (logfile )
118118 logrus .AddHook (& StdoutLogger {})
119119 logrus .Debugf ("command line: %v" , os .Args )
120+
121+ setupCtrlLogging (logfile )
122+
120123 trimLogDir ()
121124}
125+
126+ // setupCtrlLogging sets up the logging for the controller-runtime package to the writer specified.
127+ func setupCtrlLogging (w io.Writer ) {
128+ k8slogger := ctrlzap .New (func (o * zap.Options ) {
129+ o .DestWriter = w
130+ })
131+ ctrllog .SetLogger (k8slogger )
132+ }
0 commit comments