mirror of
https://github.com/clearlinux/mixer-tools.git
synced 2026-08-18 19:45:56 +00:00
f6dcd44f21
Implement the logging package for mixer. A common log file can be set for all the mixer commands in the builder.conf. E.g. `mixer config set Mixer.LOG <filepath>` The log file and level can also be set for individual mixer commands using the `--log` and `--log-level` flags respectively. The various log levels are: ERROR (1), WARNING (2), INFO (3), DEBUG (4) and VERBOSE (5). Default log level is 4. Fixes #666 Signed-off-by: Ashlesha Atrey ashlesha.atrey@intel.com
63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
// Copyright © 2018 Intel Corporation
|
|
//
|
|
// 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 config
|
|
|
|
import (
|
|
"bufio"
|
|
"github.com/clearlinux/mixer-tools/log"
|
|
"os"
|
|
)
|
|
|
|
// CurrentStateVersion is the current revision for the state file structure
|
|
const CurrentStateVersion = "1.1"
|
|
|
|
func (state *MixState) parseVersionAndConvert() error {
|
|
f, err := os.Open(state.filename)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer func() {
|
|
_ = f.Close()
|
|
}()
|
|
|
|
// Read state version
|
|
reader := bufio.NewReader(f)
|
|
found, err := state.parseVersion(reader)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Already on latest version
|
|
if found && state.version == CurrentStateVersion {
|
|
return nil
|
|
}
|
|
|
|
log.Info(log.Mixer, "Converting state to version %s", CurrentStateVersion)
|
|
|
|
return state.convertCurrent()
|
|
}
|
|
|
|
func (state *MixState) convertCurrent() error {
|
|
// Version only exists in new state, so parse mixer.state as TOML
|
|
if err := state.parse(); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Set state to the current version
|
|
state.version = CurrentStateVersion
|
|
|
|
return state.Save()
|
|
}
|