Skip to content

Commit d2c870c

Browse files
authored
refactor(log): first letter of the log is capitalized (#92)
Signed-off-by: Kevin Cui <bh@bugs.cc>
1 parent 8bc7248 commit d2c870c

File tree

6 files changed

+36
-32
lines changed

6 files changed

+36
-32
lines changed

pkg/cli/migrate.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,21 @@ func (m *MigrateContext) Setup() error {
4949
func (m *MigrateContext) Start() error {
5050
log := m.Logger
5151

52+
log.Infof("Ready to migrate, from %s to %s", m.OldImageDir, m.NewImageDir)
53+
5254
if err := wsl.SafeSyncDisk(log, m.DistroName); err != nil {
5355
switch {
5456
case errors.Is(err, wsl.ErrDistroNotExist):
55-
log.Info("distro is not exist")
57+
log.Info("Distro is not exist")
5658
break
5759
case errors.Is(err, wsl.ErrDistroNotRunning):
58-
log.Info("distro is not running")
60+
log.Info("Distro is not running")
5961
break
6062
default:
6163
if err := wsl.Terminate(log, m.DistroName); err != nil {
6264
return fmt.Errorf("cannot terminate distro %s: %w", m.DistroName, err)
6365
}
64-
log.Info("distro is terminated")
66+
log.Info("Distro is terminated")
6567
}
6668
}
6769

@@ -78,7 +80,7 @@ func (m *MigrateContext) Start() error {
7880
return fmt.Errorf("failed to copy data: %w", err)
7981
}
8082

81-
log.Info("data is copied to new dir")
83+
log.Info("File data.vhdx is copied to new dir")
8284
}
8385

8486
// move distro
@@ -102,7 +104,7 @@ func (m *MigrateContext) Start() error {
102104
}
103105
}
104106

105-
log.Info("distro is moved")
107+
log.Info("Distro is moved")
106108
}
107109

108110
// copy versions.json
@@ -112,16 +114,18 @@ func (m *MigrateContext) Start() error {
112114
return fmt.Errorf("failed to copy versions: %w", err)
113115
}
114116

115-
log.Info("versions is copied to new dir")
117+
log.Info("File versions.json is copied to new dir")
116118
}
117119

118120
if err := os.RemoveAll(oldDataPath); err != nil {
119-
log.Warnf("failed to remove old data.vhdx: %v", err)
121+
log.Warnf("Failed to remove old data.vhdx: %v", err)
120122
}
121123

122124
if err := os.RemoveAll(oldVersions); err != nil {
123-
log.Warnf("failed to remove old versions.json: %v", err)
125+
log.Warnf("Failed to remove old versions.json: %v", err)
124126
}
125127

128+
log.Infof("Success to migrate, from %s to %s", m.OldImageDir, m.NewImageDir)
129+
126130
return nil
127131
}

pkg/update/handler.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2024 OOMOL, Inc. <https://www.oomol.com>
1+
// SPDX-FileCopyrightText: 2024-2025 OOMOL, Inc. <https://www.oomol.com>
22
// SPDX-License-Identifier: MPL-2.0
33

44
package update
@@ -22,7 +22,7 @@ func (c *Context) updateRootfs() error {
2222
err := wsl.SafeSyncDisk(log, c.DistroName)
2323
switch {
2424
case errors.Is(err, wsl.ErrDistroNotRunning), err == nil:
25-
log.Infof("removing old distro: %s", c.DistroName)
25+
log.Infof("Removing old distro: %s", c.DistroName)
2626
if err := wsl.Unregister(log, c.DistroName); err != nil {
2727
return fmt.Errorf("cannot remove old distro %s: %w", c.DistroName, err)
2828
}
@@ -33,7 +33,7 @@ func (c *Context) updateRootfs() error {
3333
}
3434
}
3535

36-
log.Infof("importing distro %s from %s", c.DistroName, c.RootFSPath)
36+
log.Infof("Importing distro %s from %s", c.DistroName, c.RootFSPath)
3737
if err := wsl.ImportDistro(log, c.DistroName, c.ImageDir, c.RootFSPath); err != nil {
3838
return fmt.Errorf("failed to import distro: %w", err)
3939
}
@@ -49,7 +49,7 @@ func (c *Context) updateData() error {
4949
err := wsl.SafeSyncDisk(log, c.DistroName)
5050
switch {
5151
case err == nil:
52-
log.Infof("shutting down distro: %s", c.DistroName)
52+
log.Infof("Shutting down distro: %s", c.DistroName)
5353
if err := wsl.Terminate(log, c.DistroName); err != nil {
5454
return fmt.Errorf("cannot terminate distro %s: %w", c.DistroName, err)
5555
}
@@ -62,18 +62,18 @@ func (c *Context) updateData() error {
6262

6363
dataPath := filepath.Join(c.ImageDir, "data.vhdx")
6464

65-
log.Infof("umounting data: %s", dataPath)
65+
log.Infof("Umounting data: %s", dataPath)
6666
if err := wsl.UmountVHDX(log, dataPath); err != nil {
6767
return fmt.Errorf("failed to unmount data: %w", err)
6868
}
6969

70-
log.Infof("removing old data: %s", dataPath)
70+
log.Infof("Removing old data: %s", dataPath)
7171
if err := os.RemoveAll(dataPath); err != nil {
7272
return fmt.Errorf("failed to remove old data: %w", err)
7373
}
7474

7575
dataSize := util.DataSize(c.Name + c.ImageDir)
76-
log.Infof("creating new data: %s, size: %d", dataPath, dataSize)
76+
log.Infof("Creating new data: %s, size: %d", dataPath, dataSize)
7777
if err := vhdx.Create(dataPath, dataSize); err != nil {
7878
return fmt.Errorf("failed to create new data: %w", err)
7979
}

pkg/update/update.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2024 OOMOL, Inc. <https://www.oomol.com>
1+
// SPDX-FileCopyrightText: 2024-2025 OOMOL, Inc. <https://www.oomol.com>
22
// SPDX-License-Identifier: MPL-2.0
33

44
package update
@@ -49,22 +49,22 @@ func (c *Context) needUpdate() (result []types.VersionKey) {
4949
jsonVersion := &types.Version{}
5050
data, err := os.ReadFile(c.jsonPath)
5151
if err != nil {
52-
log.Warnf("failed to read versions.json file: %v", err)
52+
log.Warnf("Failed to read versions.json file: %v", err)
5353
return []types.VersionKey{types.VersionRootFS, types.VersionData}
5454
}
5555

5656
if err := json.Unmarshal(data, jsonVersion); err != nil {
57-
log.Warnf("failed to unmarshal versions.json file, json content: %s, %v", data, err)
57+
log.Warnf("Failed to unmarshal versions.json file, json content: %s, %v", data, err)
5858
_ = os.RemoveAll(c.jsonPath)
5959
return []types.VersionKey{types.VersionRootFS, types.VersionData}
6060
}
6161

6262
rootfsPath := filepath.Join(c.ImageDir, "ext4.vhdx")
6363
if jsonVersion.RootFS != c.RootFS || util.Exists(rootfsPath) != nil {
6464
if jsonVersion.RootFS != c.RootFS {
65-
log.Infof("need update rootfs, because version changed: %s -> %s", jsonVersion.RootFS, c.RootFS)
65+
log.Infof("Need update rootfs, because version changed: %s -> %s", jsonVersion.RootFS, c.RootFS)
6666
} else {
67-
log.Infof("need update rootfs, because rootfs not exists: %s", rootfsPath)
67+
log.Infof("Need update rootfs, because rootfs not exists: %s", rootfsPath)
6868
}
6969

7070
result = append(result, types.VersionRootFS)
@@ -73,9 +73,9 @@ func (c *Context) needUpdate() (result []types.VersionKey) {
7373
dataPath := filepath.Join(c.ImageDir, "data.vhdx")
7474
if jsonVersion.Data != c.Data || util.Exists(dataPath) != nil {
7575
if jsonVersion.Data != c.Data {
76-
log.Infof("need update data, because version changed: %s -> %s", jsonVersion.Data, c.Data)
76+
log.Infof("Need update data, because version changed: %s -> %s", jsonVersion.Data, c.Data)
7777
} else {
78-
log.Infof("need update data, because data not exists: %s", dataPath)
78+
log.Infof("Need update data, because data not exists: %s", dataPath)
7979
}
8080
result = append(result, types.VersionData)
8181
}
@@ -87,7 +87,7 @@ func (c *Context) CheckAndReplace() error {
8787
log := c.Logger
8888
list := c.needUpdate()
8989
if len(list) == 0 {
90-
log.Info("no need to update versions")
90+
log.Info("No need to update versions")
9191
return nil
9292
}
9393

@@ -98,7 +98,7 @@ func (c *Context) CheckAndReplace() error {
9898
return fmt.Errorf("failed to update data: %w", err)
9999
}
100100
event.NotifyRun(event.UpdateDataSuccess)
101-
log.Info("update data success")
101+
log.Info("Update data success")
102102
}
103103

104104
if slices.Contains(list, types.VersionRootFS) {
@@ -108,7 +108,7 @@ func (c *Context) CheckAndReplace() error {
108108
return fmt.Errorf("failed to update rootfs: %w", err)
109109
}
110110
event.NotifyRun(event.UpdateRootFSSuccess)
111-
log.Info("update rootfs success")
111+
log.Info("Update rootfs success")
112112
}
113113

114114
if err := c.save(); err != nil {

pkg/util/process.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2024 OOMOL, Inc. <https://www.oomol.com>
1+
// SPDX-FileCopyrightText: 2024-2025 OOMOL, Inc. <https://www.oomol.com>
22
// SPDX-License-Identifier: MPL-2.0
33

44
package util
@@ -14,17 +14,17 @@ import (
1414

1515
func WaitBindPID(ctx context.Context, log *logger.Context, pid int) error {
1616
if pid == 0 {
17-
log.Info("pid is 0, no need to wait")
17+
log.Info("PID is 0, no need to wait")
1818
<-ctx.Done()
1919
return nil
2020
}
2121

22-
log.Infof("wait bind pid: %d exit", pid)
22+
log.Infof("Wait bind pid: %d exit", pid)
2323

2424
for {
2525
select {
2626
case <-ctx.Done():
27-
log.Info("cancel wait bind pid, because context done")
27+
log.Info("Cancel wait bind pid, because context done")
2828
return nil
2929
default:
3030
exists, err := process.PidExistsWithContext(ctx, int32(pid))

pkg/wsl/check.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func checkVersion(ctx context.Context, opt *types.InitOpt) bool {
6969

7070
select {
7171
case <-ctx.Done():
72-
log.Warnf("cancel waiting wsl update, ctx is done: %v", context.Cause(ctx))
72+
log.Warnf("Cancel waiting wsl update, ctx is done: %v", context.Cause(ctx))
7373
return false
7474
case <-channel.ReceiveWSLUpdated():
7575
log.Info("WSL updated")

pkg/wsl/distro.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func SafeSyncDisk(log *logger.Context, distroName string) error {
107107
func MountVHDX(log *logger.Context, path string) error {
108108
if _, err := wslExec(log, "--mount", "--bare", "--vhd", path); err != nil {
109109
if strings.Contains(err.Error(), "MountVhd/WSL_E_USER_VHD_ALREADY_ATTACHED") {
110-
log.Infof("vhdx already mounted: %s", path)
110+
log.Infof("VHDX already mounted: %s", path)
111111
return nil
112112
}
113113
return fmt.Errorf("wsl mount %s failed: %w", path, err)
@@ -123,7 +123,7 @@ func UmountVHDX(log *logger.Context, path string) error {
123123

124124
if _, err := wslExec(log, "--unmount", path); err != nil {
125125
if strings.Contains(err.Error(), "DetachDisk/ERROR_FILE_NOT_FOUND") {
126-
log.Infof("vhdx already unmounted: %s", path)
126+
log.Infof("VHDX already unmounted: %s", path)
127127
return nil
128128
}
129129
return fmt.Errorf("wsl umount %s failed: %w", path, err)

0 commit comments

Comments
 (0)