refactor: 更新项目引用路径从perfect-panel/ppanel-server到perfect-panel/server
Build docker and publish / build (20.15.1) (push) Failing after 6m27s
Build docker and publish / build (20.15.1) (push) Failing after 6m27s
feat: 添加版本和构建时间变量 fix: 修正短信队列类型注释错误 style: 清理未使用的代码和测试文件 docs: 更新安装文档中的下载链接 chore: 迁移数据库脚本添加日志和订阅配置
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@ package logger
|
||||
import (
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/pkg/color"
|
||||
"github.com/perfect-panel/server/pkg/color"
|
||||
)
|
||||
|
||||
// WithColor is a helper function to add color to a string, only in plain encoding.
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/pkg/color"
|
||||
"github.com/perfect-panel/server/pkg/color"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
@@ -8,13 +8,13 @@ type LogConf struct {
|
||||
// console: log to console.
|
||||
// file: log to file.
|
||||
// volume: used in k8s, prepend the hostname to the log file name.
|
||||
Mode string `yaml:"Mode" default:"console"`
|
||||
Mode string `yaml:"Mode" default:"file"`
|
||||
// Encoding represents the encoding type, default is `json`.
|
||||
// json: json encoding.
|
||||
// plain: plain text encoding, typically used in development.
|
||||
Encoding string `yaml:"Encoding" default:"json"`
|
||||
// TimeFormat represents the time format, default is `2006-01-02T15:04:05.000Z07:00`.
|
||||
TimeFormat string `yaml:"TimeFormat" default:"2006-01-02T15:04:05.000Z07:00"`
|
||||
TimeFormat string `yaml:"TimeFormat" default:"2006-01-02 15:04:05.000"`
|
||||
// Path represents the log file path, default is `logs`.
|
||||
Path string `yaml:"Path" default:"logs"`
|
||||
// Level represents the log level, default is `info`.
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/pkg/syncx"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/timex"
|
||||
"github.com/perfect-panel/server/pkg/syncx"
|
||||
"github.com/perfect-panel/server/pkg/timex"
|
||||
)
|
||||
|
||||
type limitedExecutor struct {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/pkg/timex"
|
||||
"github.com/perfect-panel/server/pkg/timex"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/server/pkg/logger"
|
||||
)
|
||||
|
||||
type Buffer struct {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/pkg/logger"
|
||||
"github.com/perfect-panel/server/pkg/logger"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
func ReadLastNLines(path string, n int) ([]string, error) {
|
||||
// Open the file
|
||||
file, err := os.Open(fmt.Sprintf("%s/%s", path, accessFilename))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// Get file size
|
||||
fileInfo, err := file.Stat()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fileSize := fileInfo.Size()
|
||||
|
||||
// If file is empty, return empty slice
|
||||
if fileSize == 0 {
|
||||
return []string{}, nil
|
||||
}
|
||||
|
||||
// Buffer for reading
|
||||
bufferSize := int64(4096)
|
||||
if bufferSize > fileSize {
|
||||
bufferSize = fileSize
|
||||
}
|
||||
buffer := make([]byte, bufferSize)
|
||||
|
||||
// Start reading from the end
|
||||
position := fileSize
|
||||
lines := make([]string, 0, n)
|
||||
lineCount := 0
|
||||
|
||||
for lineCount < n && position > 0 {
|
||||
// How much to read
|
||||
readSize := bufferSize
|
||||
if position < bufferSize {
|
||||
readSize = position
|
||||
}
|
||||
position -= readSize
|
||||
|
||||
// Read chunk from position
|
||||
_, err := file.Seek(position, io.SeekStart)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, err = file.Read(buffer[:readSize])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Count newlines in reverse
|
||||
for i := readSize - 1; i >= 0; i-- {
|
||||
if buffer[i] == '\n' {
|
||||
lineCount++
|
||||
if lineCount > n {
|
||||
// We found more than n lines
|
||||
// Need to adjust position to read only last n lines
|
||||
position += int64(i) + 1
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we couldn't find n lines, start from beginning
|
||||
if position < 0 {
|
||||
position = 0
|
||||
}
|
||||
|
||||
// Seek to the position where we want to start reading
|
||||
_, err = file.Seek(position, io.SeekStart)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Read lines from position to end
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
lines = append(lines, scanner.Text())
|
||||
}
|
||||
|
||||
// Check if we need to trim
|
||||
if len(lines) > n {
|
||||
lines = lines[len(lines)-n:]
|
||||
}
|
||||
|
||||
return lines, scanner.Err()
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestReadLastNLines(t *testing.T) {
|
||||
t.Skipf("skip this test until this test fails")
|
||||
lines, err := ReadLastNLines("/Users/tension/code/ppanel/server/logs", 10)
|
||||
if err != nil {
|
||||
t.Fatalf("Error reading last N lines: %v", err)
|
||||
}
|
||||
for i, line := range lines {
|
||||
t.Logf("Line %d: %s", i, line)
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/internal/trace"
|
||||
"github.com/perfect-panel/server/internal/trace"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/pkg/timex"
|
||||
"github.com/perfect-panel/server/pkg/timex"
|
||||
)
|
||||
|
||||
// WithCallerSkip returns a Logger with given caller skip.
|
||||
|
||||
@@ -13,8 +13,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/pkg/fs"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/lang"
|
||||
"github.com/perfect-panel/server/pkg/fs"
|
||||
"github.com/perfect-panel/server/pkg/lang"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -11,9 +11,9 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/pkg/random"
|
||||
"github.com/perfect-panel/server/pkg/random"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/pkg/fs"
|
||||
"github.com/perfect-panel/server/pkg/fs"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package logger
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/perfect-panel/ppanel-server/pkg/syncx"
|
||||
"github.com/perfect-panel/server/pkg/syncx"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
"sync/atomic"
|
||||
|
||||
fatihcolor "github.com/fatih/color"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/color"
|
||||
"github.com/perfect-panel/ppanel-server/pkg/errorx"
|
||||
"github.com/perfect-panel/server/pkg/color"
|
||||
"github.com/perfect-panel/server/pkg/errorx"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
Reference in New Issue
Block a user