@@ -36,10 +36,10 @@ const defaultOutLimit datasize.ByteSize = 1 * datasize.KB
3636//
3737// TODO(e.burkov): Get rid of it when golang/go#59229 is resolved.
3838type systemLogger struct {
39- debug * process
40- info * process
41- warning * process
42- error * process
39+ debug * osProcess
40+ info * osProcess
41+ warning * osProcess
42+ error * osProcess
4343
4444 // tag is the prefix for all log messages.
4545 //
@@ -50,6 +50,25 @@ type systemLogger struct {
5050
5151// newSystemLogger returns a macOS-specific system logger.
5252func newSystemLogger (ctx context.Context , tag string ) (l SystemLogger , err error ) {
53+ cmdCons := executil.SystemCommandConstructor {}
54+ sysl , err := newSystemLoggerWithCommandConstructor (ctx , cmdCons , tag )
55+ if err != nil {
56+ // Don't wrap the error because it's informative enough as is.
57+ return nil , err
58+ }
59+
60+ return sysl , nil
61+ }
62+
63+ // newSystemLoggerWithCommandConstructor returns a macOS-specific system logger
64+ // using the provided command constructor.
65+ //
66+ // TODO(s.chzhen): Use this as the actual constructor.
67+ func newSystemLoggerWithCommandConstructor (
68+ ctx context.Context ,
69+ cmdCons executil.CommandConstructor ,
70+ tag string ,
71+ ) (l SystemLogger , err error ) {
5372 sysl := & systemLogger {
5473 tag : tag ,
5574 }
@@ -60,24 +79,22 @@ func newSystemLogger(ctx context.Context, tag string) (l SystemLogger, err error
6079 // first argument and an error as the second.
6180 const msgFmt = "creating %s logger process: %w"
6281
63- cmdCons := executil.SystemCommandConstructor {}
64-
65- sysl .debug , err = newProcess (ctx , cmdCons , sevDebug )
82+ sysl .debug , err = newOSProcess (ctx , cmdCons , sevDebug )
6683 if err != nil {
6784 errs = append (errs , fmt .Errorf (msgFmt , sevDebug , err ))
6885 }
6986
70- sysl .info , err = newProcess (ctx , cmdCons , sevInfo )
87+ sysl .info , err = newOSProcess (ctx , cmdCons , sevInfo )
7188 if err != nil {
7289 errs = append (errs , fmt .Errorf (msgFmt , sevInfo , err ))
7390 }
7491
75- sysl .warning , err = newProcess (ctx , cmdCons , sevWarning )
92+ sysl .warning , err = newOSProcess (ctx , cmdCons , sevWarning )
7693 if err != nil {
7794 errs = append (errs , fmt .Errorf (msgFmt , sevWarning , err ))
7895 }
7996
80- sysl .error , err = newProcess (ctx , cmdCons , sevError )
97+ sysl .error , err = newOSProcess (ctx , cmdCons , sevError )
8198 if err != nil {
8299 errs = append (errs , fmt .Errorf (msgFmt , sevError , err ))
83100 }
@@ -121,7 +138,7 @@ func (l *systemLogger) Close() (err error) {
121138 defer func () { err = errors .Annotate (err , "closing logger processes: %w" ) }()
122139
123140 var errs []error
124- procs := []* process {
141+ procs := []* osProcess {
125142 l .debug ,
126143 l .info ,
127144 l .warning ,
@@ -143,8 +160,8 @@ func (l *systemLogger) Close() (err error) {
143160 return errors .Join (errs ... )
144161}
145162
146- // process is an instance of the logger process with a particular severity.
147- type process struct {
163+ // osProcess is an instance of the logger process with a particular severity.
164+ type osProcess struct {
148165 // mu synchronizes writes to stdin between each other and with the process
149166 // closing.
150167 mu * sync.Mutex
@@ -166,12 +183,12 @@ type process struct {
166183 severity severity
167184}
168185
169- // newProcess creates a new process with a particular severity.
170- func newProcess (
186+ // newOSProcess creates a new process with a particular severity.
187+ func newOSProcess (
171188 ctx context.Context ,
172189 cmdCons executil.CommandConstructor ,
173190 sev severity ,
174- ) (p * process , err error ) {
191+ ) (p * osProcess , err error ) {
175192 const (
176193 binPath = "/usr/bin/logger"
177194 optionPriority = "-p"
@@ -204,7 +221,7 @@ func newProcess(
204221 return nil , fmt .Errorf ("starting command: %w" , err )
205222 }
206223
207- return & process {
224+ return & osProcess {
208225 mu : & sync.Mutex {},
209226 cmd : cmd ,
210227 stdin : stdinWriter ,
@@ -215,7 +232,7 @@ func newProcess(
215232}
216233
217234// write writes the message to the logger.
218- func (p * process ) write (tag , msg string ) (err error ) {
235+ func (p * osProcess ) write (tag , msg string ) (err error ) {
219236 defer func () { err = errors .Annotate (err , "writing %s message" , p .severity ) }()
220237
221238 msg = strings .TrimSuffix (msg , "\n " )
@@ -228,8 +245,8 @@ func (p *process) write(tag, msg string) (err error) {
228245 return err
229246}
230247
231- // close closes the process' pipes and waits for the command to exit.
232- func (p * process ) close () (err error ) {
248+ // close closes the process's pipes and waits for the command to exit.
249+ func (p * osProcess ) close () (err error ) {
233250 defer func () { err = errors .Annotate (err , "closing %s logger: %w" , p .severity ) }()
234251
235252 var errs []error
0 commit comments