netboot/pixiecore/cli/logging.go
David Anderson ee0987169f pixiecore/cli: implement logging controls.
The v1compat CLI is now complete, with support for --debug. The v2 CLI
additionally supports optional timestamping, so that when you're using
a modern init system that captures logs for you (e.g. systemd), you
don't have stuttering timestamps.
2016-08-15 21:54:47 -07:00

36 lines
926 B
Go

// Copyright © 2016 David Anderson <dave@natulte.net>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cli
import (
"fmt"
"log"
"sync"
)
var logSync sync.Mutex
func logWithStdLog(subsys, msg string) {
logSync.Lock()
defer logSync.Unlock()
log.Printf("[%s] %s", subsys, msg)
}
func logWithStdFmt(subsys, msg string) {
logSync.Lock()
defer logSync.Unlock()
fmt.Printf("[%s] %s\n", subsys, msg)
}