Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 305309a3c8 | |||
| 9adabd6723 | |||
| 1632256ded | |||
| 3b27697177 | |||
| dd89b362c8 | |||
|
eac80f6d2b
|
+202
-58
@@ -6,8 +6,6 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"b612.me/staros"
|
|
||||||
|
|
||||||
"b612.me/starmap"
|
"b612.me/starmap"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,11 +16,12 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Archive interface {
|
type Archive interface {
|
||||||
ShouldArchiveNow(string, os.FileInfo) bool
|
ShouldArchiveNow(*StarLogger, string, os.FileInfo) bool
|
||||||
NextLogFilePath(string, os.FileInfo) string
|
NextLogFilePath(*StarLogger, string, os.FileInfo) string
|
||||||
|
ArchiveLogFilePath(*StarLogger, string, os.FileInfo) string
|
||||||
Interval() int64
|
Interval() int64
|
||||||
HookBeforArchive() func(string, os.FileInfo) error
|
HookBeforArchive() func(*StarLogger, string, string, os.FileInfo) error //archivePath;currentPath
|
||||||
HookAfterArchive() func(string, string, os.FileInfo) error
|
HookAfterArchive() func(*StarLogger, string, string, os.FileInfo) error //archivePath;currentPath
|
||||||
}
|
}
|
||||||
|
|
||||||
type logfileinfo struct {
|
type logfileinfo struct {
|
||||||
@@ -41,7 +40,7 @@ func SetLogFile(path string, logger *StarLogger, appendMode bool) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !appendMode && staros.Exists(fullpath) {
|
if !appendMode && Exists(fullpath) {
|
||||||
os.Remove(fullpath)
|
os.Remove(fullpath)
|
||||||
}
|
}
|
||||||
fp, err := os.OpenFile(fullpath, fileMode, 0644)
|
fp, err := os.OpenFile(fullpath, fileMode, 0644)
|
||||||
@@ -119,7 +118,7 @@ func StartArchive(logger *StarLogger, arch Archive) error {
|
|||||||
select {
|
select {
|
||||||
case <-stopChan:
|
case <-stopChan:
|
||||||
return
|
return
|
||||||
case <-time.After(time.Second * time.Duration(arch.Interval())):
|
case <-time.After(time.Millisecond * time.Duration(1000*arch.Interval())):
|
||||||
}
|
}
|
||||||
fileinfo, err := GetLogFileInfo(logger)
|
fileinfo, err := GetLogFileInfo(logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -131,21 +130,30 @@ func StartArchive(logger *StarLogger, arch Archive) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fullpath := archMap.MustGet(logger.logcore.id).(logfileinfo).fullpath
|
fullpath := archMap.MustGet(logger.logcore.id).(logfileinfo).fullpath
|
||||||
if !arch.ShouldArchiveNow(fullpath, fileinfo) {
|
if !arch.ShouldArchiveNow(logger, fullpath, fileinfo) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
newLogPath := arch.NextLogFilePath(fullpath, fileinfo)
|
newLogPath := arch.NextLogFilePath(logger, fullpath, fileinfo)
|
||||||
|
archiveLogPath := arch.ArchiveLogFilePath(logger, fullpath, fileinfo)
|
||||||
if arch.HookBeforArchive() != nil {
|
if arch.HookBeforArchive() != nil {
|
||||||
if err := arch.HookBeforArchive()(fullpath, fileinfo); err != nil {
|
if err := arch.HookBeforArchive()(logger, archiveLogPath, fullpath, fileinfo); err != nil {
|
||||||
logger.Errorf("error occur while executing hook before archive,detail is %v\n", err)
|
logger.Errorf("error occur while executing hook before archive,detail is %v\n", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
err = CloseWithSwitching(logger)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
err = os.Rename(fullpath, archiveLogPath)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if err := SetLogFile(newLogPath, logger, false); err != nil {
|
if err := SetLogFile(newLogPath, logger, false); err != nil {
|
||||||
logger.Errorf("error occur while executing coverting new log file,detail is %v\n", err)
|
logger.Errorf("error occur while executing coverting new log file,detail is %v\n", err)
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
logger.Debugln("Set Log Success")
|
logger.Debugln("Archive Log Success")
|
||||||
}
|
}
|
||||||
fileinfo, err = GetLogFileInfo(logger)
|
fileinfo, err = GetLogFileInfo(logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -153,7 +161,7 @@ func StartArchive(logger *StarLogger, arch Archive) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if arch.HookAfterArchive() != nil {
|
if arch.HookAfterArchive() != nil {
|
||||||
if err := arch.HookAfterArchive()(fullpath, newLogPath, fileinfo); err != nil {
|
if err := arch.HookAfterArchive()(logger, archiveLogPath, newLogPath, fileinfo); err != nil {
|
||||||
logger.Errorf("error occur while executing hook after archive,detail is %v\n", err)
|
logger.Errorf("error occur while executing hook after archive,detail is %v\n", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -178,23 +186,47 @@ func StopArchive(logger *StarLogger) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ArchiveByDate struct {
|
type ArchiveByDate struct {
|
||||||
interval int64
|
interval int64
|
||||||
checkInterval int64
|
checkInterval int64
|
||||||
newFileNameStyle string
|
baseFileStyle string
|
||||||
hookBefor func(string, os.FileInfo) error
|
archiveStyle string
|
||||||
hookAfter func(string, string, os.FileInfo) error
|
lastSwitchTime time.Time
|
||||||
|
changeArchiveName bool
|
||||||
|
hookBefore func(*StarLogger, string, string, os.FileInfo) error
|
||||||
|
hookAfter func(*StarLogger, string, string, os.FileInfo) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (abd *ArchiveByDate) ShouldArchiveNow(fullpath string, info os.FileInfo) bool {
|
func (abd *ArchiveByDate) ShouldArchiveNow(l *StarLogger, fullpath string, info os.FileInfo) bool {
|
||||||
if time.Now().Unix()-staros.GetFileCreationTime(info).Unix() > abd.interval {
|
if abd.lastSwitchTime.IsZero() {
|
||||||
|
abd.lastSwitchTime = GetFileCreationTime(info)
|
||||||
|
}
|
||||||
|
sub := time.Now().Unix() - abd.lastSwitchTime.Unix()
|
||||||
|
if sub >= abd.interval || abd.interval-sub <= abd.checkInterval/2 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (abd *ArchiveByDate) NextLogFilePath(oldpath string, info os.FileInfo) string {
|
func (abd *ArchiveByDate) NextLogFilePath(l *StarLogger, oldpath string, info os.FileInfo) string {
|
||||||
|
var newName string
|
||||||
dir := filepath.Dir(oldpath)
|
dir := filepath.Dir(oldpath)
|
||||||
newName := time.Now().Format(abd.newFileNameStyle)
|
if !abd.changeArchiveName {
|
||||||
|
newName = abd.baseFileStyle + time.Now().Format(abd.archiveStyle)
|
||||||
|
} else {
|
||||||
|
newName = abd.baseFileStyle
|
||||||
|
}
|
||||||
|
return filepath.Join(dir, newName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (abd *ArchiveByDate) ArchiveLogFilePath(l *StarLogger, oldpath string, info os.FileInfo) string {
|
||||||
|
var newName string
|
||||||
|
dir := filepath.Dir(oldpath)
|
||||||
|
if abd.changeArchiveName {
|
||||||
|
newName = filepath.Base(abd.baseFileStyle) + time.Now().Format(abd.archiveStyle)
|
||||||
|
} else {
|
||||||
|
newName = abd.baseFileStyle
|
||||||
|
}
|
||||||
return filepath.Join(dir, newName)
|
return filepath.Join(dir, newName)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,52 +234,77 @@ func (abd *ArchiveByDate) Interval() int64 {
|
|||||||
return abd.checkInterval
|
return abd.checkInterval
|
||||||
}
|
}
|
||||||
|
|
||||||
func (abd *ArchiveByDate) HookBeforArchive() func(string, os.FileInfo) error {
|
func (abd *ArchiveByDate) HookBeforArchive() func(*StarLogger, string, string, os.FileInfo) error {
|
||||||
|
|
||||||
return abd.hookBefor
|
return abd.hookBefore
|
||||||
}
|
}
|
||||||
|
|
||||||
func (abd *ArchiveByDate) HookAfterArchive() func(string, string, os.FileInfo) error {
|
func (abd *ArchiveByDate) HookAfterArchive() func(*StarLogger, string, string, os.FileInfo) error {
|
||||||
return abd.hookAfter
|
return func(logger *StarLogger, s string, s2 string, info os.FileInfo) error {
|
||||||
|
abd.lastSwitchTime = time.Now()
|
||||||
|
if abd.hookAfter != nil {
|
||||||
|
return abd.hookAfter(logger, s, s2, info)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (abd *ArchiveByDate) SetHookBeforArchive(f func(string, os.FileInfo) error) {
|
func (abd *ArchiveByDate) SetHookBeforArchive(f func(*StarLogger, string, string, os.FileInfo) error) {
|
||||||
|
abd.hookBefore = f
|
||||||
abd.hookBefor = f
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (abd *ArchiveByDate) SetHookAfterArchive(f func(string, string, os.FileInfo) error) {
|
func (abd *ArchiveByDate) SetHookAfterArchive(f func(*StarLogger, string, string, os.FileInfo) error) {
|
||||||
abd.hookAfter = f
|
abd.hookAfter = f
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewArchiveByDate(archInterval int64, checkInterval int64, fileStyle string, hookbefor func(string, os.FileInfo) error, hookafter func(string, string, os.FileInfo) error) *ArchiveByDate {
|
func NewArchiveByDate(archInterval int64, checkInterval int64, baseFileName string, archiveFileName string, changeArchiveName bool, hookbefore func(*StarLogger, string, string, os.FileInfo) error, hookafter func(*StarLogger, string, string, os.FileInfo) error) *ArchiveByDate {
|
||||||
return &ArchiveByDate{
|
return &ArchiveByDate{
|
||||||
interval: archInterval,
|
interval: archInterval,
|
||||||
checkInterval: checkInterval,
|
checkInterval: checkInterval,
|
||||||
newFileNameStyle: fileStyle,
|
changeArchiveName: changeArchiveName,
|
||||||
hookBefor: hookbefor,
|
baseFileStyle: baseFileName,
|
||||||
hookAfter: hookafter,
|
archiveStyle: archiveFileName,
|
||||||
|
hookBefore: hookbefore,
|
||||||
|
hookAfter: hookafter,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArchiveBySize struct {
|
type ArchiveBySize struct {
|
||||||
size int64
|
size int64
|
||||||
checkInterval int64
|
checkInterval int64
|
||||||
newFileNameStyle string
|
changeArchiveName bool
|
||||||
hookBefor func(string, os.FileInfo) error
|
baseFileStyle string
|
||||||
hookAfter func(string, string, os.FileInfo) error
|
archiveStyle string
|
||||||
|
hookBefore func(*StarLogger, string, string, os.FileInfo) error
|
||||||
|
hookAfter func(*StarLogger, string, string, os.FileInfo) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (abd *ArchiveBySize) ShouldArchiveNow(fullpath string, info os.FileInfo) bool {
|
func (abd *ArchiveBySize) ShouldArchiveNow(l *StarLogger, fullpath string, info os.FileInfo) bool {
|
||||||
if info.Size() > abd.size {
|
if info.Size() > abd.size {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (abd *ArchiveBySize) NextLogFilePath(oldpath string, info os.FileInfo) string {
|
func (abd *ArchiveBySize) NextLogFilePath(l *StarLogger, oldpath string, info os.FileInfo) string {
|
||||||
|
var newName string
|
||||||
dir := filepath.Dir(oldpath)
|
dir := filepath.Dir(oldpath)
|
||||||
newName := time.Now().Format(abd.newFileNameStyle)
|
if !abd.changeArchiveName {
|
||||||
|
newName = abd.baseFileStyle + time.Now().Format(abd.archiveStyle)
|
||||||
|
} else {
|
||||||
|
newName = abd.baseFileStyle
|
||||||
|
}
|
||||||
|
return filepath.Join(dir, newName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (abd *ArchiveBySize) ArchiveLogFilePath(l *StarLogger, oldpath string, info os.FileInfo) string {
|
||||||
|
var newName string
|
||||||
|
dir := filepath.Dir(oldpath)
|
||||||
|
if abd.changeArchiveName {
|
||||||
|
newName = filepath.Base(abd.baseFileStyle) + time.Now().Format(abd.archiveStyle)
|
||||||
|
} else {
|
||||||
|
newName = abd.baseFileStyle
|
||||||
|
}
|
||||||
return filepath.Join(dir, newName)
|
return filepath.Join(dir, newName)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,30 +312,117 @@ func (abd *ArchiveBySize) Interval() int64 {
|
|||||||
return abd.checkInterval
|
return abd.checkInterval
|
||||||
}
|
}
|
||||||
|
|
||||||
func (abd *ArchiveBySize) HookBeforArchive() func(string, os.FileInfo) error {
|
func (abd *ArchiveBySize) HookBeforArchive() func(*StarLogger, string, string, os.FileInfo) error {
|
||||||
|
return abd.hookBefore
|
||||||
return abd.hookBefor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (abd *ArchiveBySize) HookAfterArchive() func(string, string, os.FileInfo) error {
|
func (abd *ArchiveBySize) HookAfterArchive() func(*StarLogger, string, string, os.FileInfo) error {
|
||||||
return abd.hookAfter
|
return abd.hookAfter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (abd *ArchiveBySize) SetHookBeforArchive(f func(string, os.FileInfo) error) {
|
func (abd *ArchiveBySize) SetHookBeforArchive(f func(*StarLogger, string, string, os.FileInfo) error) {
|
||||||
|
abd.hookBefore = f
|
||||||
abd.hookBefor = f
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (abd *ArchiveBySize) SetHookAfterArchive(f func(string, string, os.FileInfo) error) {
|
func (abd *ArchiveBySize) SetHookAfterArchive(f func(*StarLogger, string, string, os.FileInfo) error) {
|
||||||
abd.hookAfter = f
|
abd.hookAfter = f
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewArchiveBySize(size int64, checkInterval int64, fileStyle string, hookbefor func(string, os.FileInfo) error, hookafter func(string, string, os.FileInfo) error) *ArchiveBySize {
|
func NewArchiveBySize(size int64, checkInterval int64, baseFileStyle, archiveFileStyle string, changeArchiveFileName bool, hookbefore func(*StarLogger, string, string, os.FileInfo) error, hookafter func(*StarLogger, string, string, os.FileInfo) error) *ArchiveBySize {
|
||||||
return &ArchiveBySize{
|
return &ArchiveBySize{
|
||||||
size: size,
|
size: size,
|
||||||
checkInterval: checkInterval,
|
checkInterval: checkInterval,
|
||||||
newFileNameStyle: fileStyle,
|
baseFileStyle: baseFileStyle,
|
||||||
hookBefor: hookbefor,
|
archiveStyle: archiveFileStyle,
|
||||||
hookAfter: hookafter,
|
hookBefore: hookbefore,
|
||||||
|
hookAfter: hookafter,
|
||||||
|
changeArchiveName: changeArchiveFileName,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type ArchiveByDateSize struct {
|
||||||
|
interval int64
|
||||||
|
size int64
|
||||||
|
checkInterval int64
|
||||||
|
changeArchiveName bool
|
||||||
|
lastSwitchTime time.Time
|
||||||
|
baseFileStyle string
|
||||||
|
archiveStyle string
|
||||||
|
hookBefore func(*StarLogger, string, string, os.FileInfo) error
|
||||||
|
hookAfter func(*StarLogger, string, string, os.FileInfo) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (abd *ArchiveByDateSize) ShouldArchiveNow(l *StarLogger, fullpath string, info os.FileInfo) bool {
|
||||||
|
if abd.lastSwitchTime.IsZero() {
|
||||||
|
abd.lastSwitchTime = GetFileCreationTime(info)
|
||||||
|
}
|
||||||
|
if info.Size() > abd.size {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
sub := time.Now().Unix() - abd.lastSwitchTime.Unix()
|
||||||
|
if sub >= abd.interval || abd.interval-sub <= abd.checkInterval/2 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (abd *ArchiveByDateSize) NextLogFilePath(l *StarLogger, oldpath string, info os.FileInfo) string {
|
||||||
|
var newName string
|
||||||
|
dir := filepath.Dir(oldpath)
|
||||||
|
if !abd.changeArchiveName {
|
||||||
|
newName = abd.baseFileStyle + time.Now().Format(abd.archiveStyle)
|
||||||
|
} else {
|
||||||
|
newName = abd.baseFileStyle
|
||||||
|
}
|
||||||
|
return filepath.Join(dir, newName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (abd *ArchiveByDateSize) ArchiveLogFilePath(l *StarLogger, oldpath string, info os.FileInfo) string {
|
||||||
|
var newName string
|
||||||
|
dir := filepath.Dir(oldpath)
|
||||||
|
if abd.changeArchiveName {
|
||||||
|
newName = filepath.Base(abd.baseFileStyle) + time.Now().Format(abd.archiveStyle)
|
||||||
|
} else {
|
||||||
|
newName = abd.baseFileStyle
|
||||||
|
}
|
||||||
|
return filepath.Join(dir, newName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (abd *ArchiveByDateSize) Interval() int64 {
|
||||||
|
return abd.checkInterval
|
||||||
|
}
|
||||||
|
|
||||||
|
func (abd *ArchiveByDateSize) HookBeforArchive() func(*StarLogger, string, string, os.FileInfo) error {
|
||||||
|
return abd.hookBefore
|
||||||
|
}
|
||||||
|
|
||||||
|
func (abd *ArchiveByDateSize) HookAfterArchive() func(*StarLogger, string, string, os.FileInfo) error {
|
||||||
|
return func(logger *StarLogger, s string, s2 string, info os.FileInfo) error {
|
||||||
|
abd.lastSwitchTime = time.Now()
|
||||||
|
if abd.hookAfter != nil {
|
||||||
|
return abd.hookAfter(logger, s, s2, info)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (abd *ArchiveByDateSize) SetHookBeforArchive(f func(*StarLogger, string, string, os.FileInfo) error) {
|
||||||
|
abd.hookBefore = f
|
||||||
|
}
|
||||||
|
|
||||||
|
func (abd *ArchiveByDateSize) SetHookAfterArchive(f func(*StarLogger, string, string, os.FileInfo) error) {
|
||||||
|
abd.hookAfter = f
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewArchiveByDateSize(size int64, interval int64, checkInterval int64, baseFileStyle, archiveFileStyle string, changeArchiveFileName bool, hookbefore func(*StarLogger, string, string, os.FileInfo) error, hookafter func(*StarLogger, string, string, os.FileInfo) error) *ArchiveByDateSize {
|
||||||
|
return &ArchiveByDateSize{
|
||||||
|
size: size,
|
||||||
|
interval: interval,
|
||||||
|
checkInterval: checkInterval,
|
||||||
|
baseFileStyle: baseFileStyle,
|
||||||
|
archiveStyle: archiveFileStyle,
|
||||||
|
hookBefore: hookbefore,
|
||||||
|
hookAfter: hookafter,
|
||||||
|
changeArchiveName: changeArchiveFileName,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package starlog
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestArchiveByDate(t *testing.T) {
|
||||||
|
l := Std
|
||||||
|
SetLogFile("test.log", l, true)
|
||||||
|
StartArchive(l, NewArchiveByDateSize(4096, 24, 2, "test.log",
|
||||||
|
"_2006_01_02_15_04_05.log", true, nil, nil))
|
||||||
|
for {
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
l.Infoln("hahaha", time.Now())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,7 +35,7 @@ func generateCoreLogStr(skip int, logstr string) string {
|
|||||||
return logStr
|
return logStr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) build(thread string, isStd bool, isShow bool, handler func([]Attr, string), level int, logDetail string) {
|
func (logger *starlog) build(thread string, isStd bool, isShow bool, handler func(data LogData), level int, logDetail string) {
|
||||||
logger.mu.Lock()
|
logger.mu.Lock()
|
||||||
defer logger.mu.Unlock()
|
defer logger.mu.Unlock()
|
||||||
var skip, line int = 3, 0
|
var skip, line int = 3, 0
|
||||||
@@ -80,19 +80,33 @@ func (logger *starlog) build(thread string, isStd bool, isShow bool, handler fun
|
|||||||
}
|
}
|
||||||
if isShow {
|
if isShow {
|
||||||
if !logger.showColor {
|
if !logger.showColor {
|
||||||
fmt.Print(logStr)
|
if level >= logger.errOutputLevel {
|
||||||
|
fmt.Fprint(os.Stderr, logStr)
|
||||||
|
} else {
|
||||||
|
fmt.Print(logStr)
|
||||||
|
}
|
||||||
} else if !logger.onlyColorLevel {
|
} else if !logger.onlyColorLevel {
|
||||||
//logcolor := NewColor(logger.colorList[level]...)
|
if level < logger.errOutputLevel {
|
||||||
logger.colorMe[level].Fprint(stdScreen, logStr)
|
logger.colorMe[level].Fprint(stdScreen, logStr)
|
||||||
|
} else {
|
||||||
|
logger.colorMe[level].Fprint(errScreen, logStr)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprint(stdScreen, logStr)
|
if level < logger.errOutputLevel {
|
||||||
|
fmt.Fprint(stdScreen, logStr)
|
||||||
|
} else {
|
||||||
|
fmt.Fprint(errScreen, logStr)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if handler != nil {
|
if handler != nil {
|
||||||
stacks.Push(logTransfer{
|
stacks.Push(logTransfer{
|
||||||
handlerFunc: handler,
|
handlerFunc: handler,
|
||||||
colors: logger.colorList[level],
|
LogData: LogData{
|
||||||
logStr: logStr,
|
Log: logStr,
|
||||||
|
Colors: logger.colorList[level],
|
||||||
|
Name: logger.name,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if !logger.stopWriter {
|
if !logger.stopWriter {
|
||||||
@@ -130,133 +144,133 @@ func (logger *starlog) println(str ...interface{}) string {
|
|||||||
return fmt.Sprintln(str...)
|
return fmt.Sprintln(str...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Debug(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
|
func (logger *starlog) Debug(thread string, isStd bool, handler func(LogData), str ...interface{}) {
|
||||||
strs := fmt.Sprint(str...)
|
strs := fmt.Sprint(str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvDebug, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvDebug, strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Debugf(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) {
|
func (logger *starlog) Debugf(thread string, isStd bool, handler func(LogData), format string, str ...interface{}) {
|
||||||
strs := fmt.Sprintf(format, str...)
|
strs := fmt.Sprintf(format, str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvDebug, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvDebug, strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Debugln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
|
func (logger *starlog) Debugln(thread string, isStd bool, handler func(LogData), str ...interface{}) {
|
||||||
strs := fmt.Sprintln(str...)
|
strs := fmt.Sprintln(str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvDebug, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvDebug, strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Info(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
|
func (logger *starlog) Info(thread string, isStd bool, handler func(LogData), str ...interface{}) {
|
||||||
strs := fmt.Sprint(str...)
|
strs := fmt.Sprint(str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvInfo, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvInfo, strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Infof(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) {
|
func (logger *starlog) Infof(thread string, isStd bool, handler func(LogData), format string, str ...interface{}) {
|
||||||
strs := fmt.Sprintf(format, str...)
|
strs := fmt.Sprintf(format, str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvInfo, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvInfo, strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Infoln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
|
func (logger *starlog) Infoln(thread string, isStd bool, handler func(LogData), str ...interface{}) {
|
||||||
strs := fmt.Sprintln(str...)
|
strs := fmt.Sprintln(str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvInfo, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvInfo, strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Notice(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
|
func (logger *starlog) Notice(thread string, isStd bool, handler func(LogData), str ...interface{}) {
|
||||||
strs := fmt.Sprint(str...)
|
strs := fmt.Sprint(str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvNotice, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvNotice, strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Noticef(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) {
|
func (logger *starlog) Noticef(thread string, isStd bool, handler func(LogData), format string, str ...interface{}) {
|
||||||
strs := fmt.Sprintf(format, str...)
|
strs := fmt.Sprintf(format, str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvNotice, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvNotice, strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Noticeln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
|
func (logger *starlog) Noticeln(thread string, isStd bool, handler func(LogData), str ...interface{}) {
|
||||||
strs := fmt.Sprintln(str...)
|
strs := fmt.Sprintln(str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvNotice, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvNotice, strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Warning(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
|
func (logger *starlog) Warning(thread string, isStd bool, handler func(LogData), str ...interface{}) {
|
||||||
strs := fmt.Sprint(str...)
|
strs := fmt.Sprint(str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvWarning, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvWarning, strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Warningf(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) {
|
func (logger *starlog) Warningf(thread string, isStd bool, handler func(LogData), format string, str ...interface{}) {
|
||||||
strs := fmt.Sprintf(format, str...)
|
strs := fmt.Sprintf(format, str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvWarning, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvWarning, strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Warningln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
|
func (logger *starlog) Warningln(thread string, isStd bool, handler func(LogData), str ...interface{}) {
|
||||||
strs := fmt.Sprintln(str...)
|
strs := fmt.Sprintln(str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvWarning, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvWarning, strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Error(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
|
func (logger *starlog) Error(thread string, isStd bool, handler func(LogData), str ...interface{}) {
|
||||||
strs := fmt.Sprint(str...)
|
strs := fmt.Sprint(str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvError, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvError, strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Errorf(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) {
|
func (logger *starlog) Errorf(thread string, isStd bool, handler func(LogData), format string, str ...interface{}) {
|
||||||
strs := fmt.Sprintf(format, str...)
|
strs := fmt.Sprintf(format, str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvError, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvError, strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Errorln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
|
func (logger *starlog) Errorln(thread string, isStd bool, handler func(LogData), str ...interface{}) {
|
||||||
strs := fmt.Sprintln(str...)
|
strs := fmt.Sprintln(str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvError, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvError, strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Critical(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
|
func (logger *starlog) Critical(thread string, isStd bool, handler func(LogData), str ...interface{}) {
|
||||||
strs := fmt.Sprint(str...)
|
strs := fmt.Sprint(str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvCritical, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvCritical, strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Criticalf(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) {
|
func (logger *starlog) Criticalf(thread string, isStd bool, handler func(LogData), format string, str ...interface{}) {
|
||||||
strs := fmt.Sprintf(format, str...)
|
strs := fmt.Sprintf(format, str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvCritical, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvCritical, strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Criticalln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
|
func (logger *starlog) Criticalln(thread string, isStd bool, handler func(LogData), str ...interface{}) {
|
||||||
strs := fmt.Sprintln(str...)
|
strs := fmt.Sprintln(str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvCritical, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvCritical, strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Fatal(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
|
func (logger *starlog) Fatal(thread string, isStd bool, handler func(LogData), str ...interface{}) {
|
||||||
strs := fmt.Sprint(str...)
|
strs := fmt.Sprint(str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvFatal, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvFatal, strs)
|
||||||
os.Exit(9)
|
os.Exit(9)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Fatalf(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) {
|
func (logger *starlog) Fatalf(thread string, isStd bool, handler func(LogData), format string, str ...interface{}) {
|
||||||
strs := fmt.Sprintf(format, str...)
|
strs := fmt.Sprintf(format, str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvFatal, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvFatal, strs)
|
||||||
os.Exit(9)
|
os.Exit(9)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Fatalln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
|
func (logger *starlog) Fatalln(thread string, isStd bool, handler func(LogData), str ...interface{}) {
|
||||||
strs := fmt.Sprintln(str...)
|
strs := fmt.Sprintln(str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvFatal, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvFatal, strs)
|
||||||
os.Exit(9)
|
os.Exit(9)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Panic(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
|
func (logger *starlog) Panic(thread string, isStd bool, handler func(LogData), str ...interface{}) {
|
||||||
strs := fmt.Sprint(str...)
|
strs := fmt.Sprint(str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvPanic, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvPanic, strs)
|
||||||
panic(str)
|
panic(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Panicf(thread string, isStd bool, handler func([]Attr, string), format string, str ...interface{}) {
|
func (logger *starlog) Panicf(thread string, isStd bool, handler func(LogData), format string, str ...interface{}) {
|
||||||
strs := fmt.Sprintf(format, str...)
|
strs := fmt.Sprintf(format, str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvPanic, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvPanic, strs)
|
||||||
panic(fmt.Sprintf(format, str...))
|
panic(fmt.Sprintf(format, str...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Panicln(thread string, isStd bool, handler func([]Attr, string), str ...interface{}) {
|
func (logger *starlog) Panicln(thread string, isStd bool, handler func(LogData), str ...interface{}) {
|
||||||
strs := fmt.Sprintln(str...)
|
strs := fmt.Sprintln(str...)
|
||||||
logger.build(thread, isStd, logger.showStd, handler, LvPanic, strs)
|
logger.build(thread, isStd, logger.showStd, handler, LvPanic, strs)
|
||||||
panic(fmt.Sprintln(str...))
|
panic(fmt.Sprintln(str...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Print(thread string, isStd bool, isShow bool, handler func([]Attr, string), str ...interface{}) {
|
func (logger *starlog) Print(thread string, isStd bool, isShow bool, handler func(LogData), str ...interface{}) {
|
||||||
strs := fmt.Sprint(str...)
|
strs := fmt.Sprint(str...)
|
||||||
if isShow {
|
if isShow {
|
||||||
fmt.Print(strs)
|
fmt.Print(strs)
|
||||||
@@ -264,7 +278,7 @@ func (logger *starlog) Print(thread string, isStd bool, isShow bool, handler fun
|
|||||||
logger.write(strs)
|
logger.write(strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Printf(thread string, isStd bool, isShow bool, handler func([]Attr, string), format string, str ...interface{}) {
|
func (logger *starlog) Printf(thread string, isStd bool, isShow bool, handler func(LogData), format string, str ...interface{}) {
|
||||||
strs := fmt.Sprintf(format, str...)
|
strs := fmt.Sprintf(format, str...)
|
||||||
if isShow {
|
if isShow {
|
||||||
fmt.Print(strs)
|
fmt.Print(strs)
|
||||||
@@ -272,7 +286,7 @@ func (logger *starlog) Printf(thread string, isStd bool, isShow bool, handler fu
|
|||||||
logger.write(strs)
|
logger.write(strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Println(thread string, isStd bool, isShow bool, handler func([]Attr, string), str ...interface{}) {
|
func (logger *starlog) Println(thread string, isStd bool, isShow bool, handler func(LogData), str ...interface{}) {
|
||||||
strs := fmt.Sprintln(str...)
|
strs := fmt.Sprintln(str...)
|
||||||
if isShow {
|
if isShow {
|
||||||
fmt.Print(strs)
|
fmt.Print(strs)
|
||||||
@@ -280,17 +294,32 @@ func (logger *starlog) Println(thread string, isStd bool, isShow bool, handler f
|
|||||||
logger.write(strs)
|
logger.write(strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Log(thread string, isStd bool, isShow bool, level int, handler func([]Attr, string), str ...interface{}) {
|
func (logger *starlog) Log(thread string, isStd bool, isShow bool, level int, handler func(LogData), str ...interface{}) {
|
||||||
strs := fmt.Sprint(str...)
|
strs := fmt.Sprint(str...)
|
||||||
logger.build(thread, isStd, isShow, handler, level, strs)
|
logger.build(thread, isStd, isShow, handler, level, strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Logf(thread string, isStd bool, isShow bool, level int, handler func([]Attr, string), format string, str ...interface{}) {
|
func (logger *starlog) Logf(thread string, isStd bool, isShow bool, level int, handler func(LogData), format string, str ...interface{}) {
|
||||||
strs := fmt.Sprintf(format, str...)
|
strs := fmt.Sprintf(format, str...)
|
||||||
logger.build(thread, isStd, isShow, handler, level, strs)
|
logger.build(thread, isStd, isShow, handler, level, strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *starlog) Logln(thread string, isStd bool, isShow bool, level int, handler func([]Attr, string), str ...interface{}) {
|
func (logger *starlog) Logln(thread string, isStd bool, isShow bool, level int, handler func(LogData), str ...interface{}) {
|
||||||
strs := fmt.Sprintln(str...)
|
strs := fmt.Sprintln(str...)
|
||||||
logger.build(thread, isStd, isShow, handler, level, strs)
|
logger.build(thread, isStd, isShow, handler, level, strs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (logger *starlog) Write(str ...interface{}) {
|
||||||
|
strs := fmt.Sprint(str...)
|
||||||
|
logger.Write(strs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (logger *starlog) Writef(format string, str ...interface{}) {
|
||||||
|
strs := fmt.Sprintf(format, str...)
|
||||||
|
logger.Write(strs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (logger *starlog) Writeln(str ...interface{}) {
|
||||||
|
strs := fmt.Sprintln(str...)
|
||||||
|
logger.Write(strs)
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package starlog
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 检测文件/文件夹是否存在
|
||||||
|
func Exists(path string) bool {
|
||||||
|
_, err := os.Stat(path)
|
||||||
|
if err != nil && os.IsNotExist(err) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsFile 返回给定文件地址是否是一个文件,
|
||||||
|
// True为是一个文件,False为不是文件或路径无效
|
||||||
|
func IsFile(fpath string) bool {
|
||||||
|
s, err := os.Stat(fpath)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return !s.IsDir()
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsFolder 返回给定文件地址是否是一个文件夹,
|
||||||
|
// True为是一个文件夹,False为不是文件夹或路径无效
|
||||||
|
func IsFolder(fpath string) bool {
|
||||||
|
s, err := os.Stat(fpath)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return s.IsDir()
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
//go:build darwin
|
||||||
|
// +build darwin
|
||||||
|
|
||||||
|
package starlog
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func timespecToTime(ts syscall.Timespec) time.Time {
|
||||||
|
return time.Unix(int64(ts.Sec), int64(ts.Nsec))
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetFileCreationTime(fileinfo os.FileInfo) time.Time {
|
||||||
|
return timespecToTime(fileinfo.Sys().(*syscall.Stat_t).Ctimespec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetFileAccessTime(fileinfo os.FileInfo) time.Time {
|
||||||
|
return timespecToTime(fileinfo.Sys().(*syscall.Stat_t).Atimespec)
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
//go:build linux
|
||||||
|
// +build linux
|
||||||
|
|
||||||
|
package starlog
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func timespecToTime(ts syscall.Timespec) time.Time {
|
||||||
|
return time.Unix(int64(ts.Sec), int64(ts.Nsec))
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetFileCreationTime(fileinfo os.FileInfo) time.Time {
|
||||||
|
return timespecToTime(fileinfo.Sys().(*syscall.Stat_t).Ctim)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetFileAccessTime(fileinfo os.FileInfo) time.Time {
|
||||||
|
return timespecToTime(fileinfo.Sys().(*syscall.Stat_t).Atim)
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
//go:build windows
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package starlog
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetFileCreationTime(fileinfo os.FileInfo) time.Time {
|
||||||
|
d := fileinfo.Sys().(*syscall.Win32FileAttributeData)
|
||||||
|
return time.Unix(0, d.CreationTime.Nanoseconds())
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetFileAccessTime(fileinfo os.FileInfo) time.Time {
|
||||||
|
d := fileinfo.Sys().(*syscall.Win32FileAttributeData)
|
||||||
|
return time.Unix(0, d.LastAccessTime.Nanoseconds())
|
||||||
|
}
|
||||||
@@ -3,8 +3,6 @@ module b612.me/starlog
|
|||||||
go 1.16
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
b612.me/notify v1.2.0 // indirect
|
b612.me/starmap v1.2.4
|
||||||
b612.me/starmap v1.2.0
|
golang.org/x/sys v0.18.0
|
||||||
b612.me/staros v1.1.2
|
|
||||||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,28 +1,55 @@
|
|||||||
b612.me/notify v1.2.0 h1:RedXNMLqY+TozalmdIUM27EFvZp06pzeqHn/F9G1eEs=
|
b612.me/notify v1.2.5 h1:fASpzi8YAo78g6jKnefzfbsQz0nGNYFbClB2Bylj+MA=
|
||||||
b612.me/notify v1.2.0/go.mod h1:EPctpKCVnoZO1hUJTRYpOw3huTemua+SGNIuUCsnzOc=
|
b612.me/notify v1.2.5/go.mod h1:GTnAdC6v9krGxtC8Gkn8TcyUsYnHSiHjRAXsONPiLpI=
|
||||||
b612.me/starcrypto v0.0.1 h1:xGngzXPUrVbqtWzNw2e+0eWsdG7GG1/X+ONDGIzdriI=
|
b612.me/starcrypto v0.0.3 h1:lBGtz0kBdsV198BDQ72zBgOXYKBCb47R9tCWP/PFIwA=
|
||||||
b612.me/starcrypto v0.0.1/go.mod h1:hz0xRnfWNpYOlVrIPoGrQOWPibq4YiUZ7qN5tsQbzPo=
|
b612.me/starcrypto v0.0.3/go.mod h1:pF5A16p8r/h1G0x7ZNmmAF6K1sdIMpbCUxn2WGC8gZ0=
|
||||||
b612.me/stario v0.0.5 h1:Q1OGF+8eOoK49zMzkyh80GWaMuknhey6+PWJJL9ZuNo=
|
b612.me/stario v0.0.9 h1:bFDlejUJMwZ12a09snZJspQsOlkqpDAl9qKPEYOGWCk=
|
||||||
b612.me/stario v0.0.5/go.mod h1:or4ssWcxQSjMeu+hRKEgtp0X517b3zdlEOAms8Qscvw=
|
b612.me/stario v0.0.9/go.mod h1:x4D/x8zA5SC0pj/uJAi4FyG5p4j5UZoMEZfvuRR6VNw=
|
||||||
b612.me/starmap v1.2.0 h1:sRUeMRUqOyb3pAQln5U6V07kIYp0714Z3gJ/g2nCJXc=
|
b612.me/starmap v1.2.4 h1:gfAyBtzW3KKCIyI14I2pEqGsR/u2E+3tkH0xRqtWb4E=
|
||||||
b612.me/starmap v1.2.0/go.mod h1:InIJXA3qVeMkvkUhCV/XPchCiNcJcVYdYV8EAOGbGZY=
|
b612.me/starmap v1.2.4/go.mod h1:EhOUzkItc5IcyBmr1C7/vmZBbW3GgCWs63hGn7WhuMc=
|
||||||
b612.me/starnet v0.1.3 h1:UjY6M96gdPdJtxnQGzCttqSwFw93sDZSHiIGtdOlFfk=
|
b612.me/starnet v0.1.8 h1:sTNytUFP38i2BFR9nha3lTSLYb7El3tvKpZplYCrhZk=
|
||||||
b612.me/starnet v0.1.3/go.mod h1:j/dd6BKwQK80O4gfbGYg2aYtPH76gSdgpuKboK/DwN4=
|
b612.me/starnet v0.1.8/go.mod h1:k862Kf8DiVWTqdX6PHTFb6NoT+3G3Y74n8NCyNhuP0Y=
|
||||||
b612.me/staros v1.1.2 h1:jBFU1KHgn0VpyitYKwC9Zwj1GjmDBGM+fuTyV0yGXRo=
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
b612.me/staros v1.1.2/go.mod h1:9kNWVJWNJfs2MiWEt7X3SO+ixYKPGqus1ShTy8hpfU0=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
b612.me/win32api v0.0.1 h1:vLFB1xhO6pd9+zB2EyaapKB459Urv3v+C1YwgwOFEWo=
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
b612.me/win32api v0.0.1/go.mod h1:MHu0JBQjzxQ2yxpZPUBbn5un45o67eF5iWKa4Q9e0yE=
|
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||||
b612.me/wincmd v0.0.1 h1:4+RCFKHuD/JqAYsdtO6sTNKJs1nQVMQo87h6KhTJjkM=
|
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
|
||||||
b612.me/wincmd v0.0.1/go.mod h1:32xTM7qWAI7jx6qwTrig05rxejSYbSp7CX5WD7qsMxY=
|
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
|
||||||
golang.org/x/crypto v0.0.0-20220313003712-b769efc7c000 h1:SL+8VVnkqyshUSz5iNnXtrBQzvFF2SkROm6t5RczFAE=
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
golang.org/x/crypto v0.0.0-20220313003712-b769efc7c000/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
|
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||||
|
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||||
|
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||||
|
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 h1:y/woIyUBFbpQGKS0u1aHF/40WUDnek3fPOyD08H5Vng=
|
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
|
||||||
|
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
|
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||||
|
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
||||||
|
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
|
||||||
|
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
|
||||||
|
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
|
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
|
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||||
|
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
|
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||||
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
|||||||
+2
-5
@@ -1,7 +1,6 @@
|
|||||||
package starlog
|
package starlog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"b612.me/starmap"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
@@ -13,10 +12,8 @@ var Std *StarLogger
|
|||||||
var stdmu sync.Mutex
|
var stdmu sync.Mutex
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
stacks = starmap.NewStarStack(1024)
|
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
stackStopChan = make(chan int)
|
stackStopChan = make(chan int)
|
||||||
StartStacks()
|
|
||||||
Std = NewStarlog(nil)
|
Std = NewStarlog(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,10 +259,10 @@ func GetWriter() io.Writer {
|
|||||||
return Std.GetWriter()
|
return Std.GetWriter()
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetHandler(f func([]Attr, string)) {
|
func SetHandler(f func(LogData)) {
|
||||||
Std.SetHandler(f)
|
Std.SetHandler(f)
|
||||||
}
|
}
|
||||||
func GetHandler() func([]Attr, string) {
|
func GetHandler() func(LogData) {
|
||||||
return Std.GetHandler()
|
return Std.GetHandler()
|
||||||
}
|
}
|
||||||
func SetSwitching(sw bool) {
|
func SetSwitching(sw bool) {
|
||||||
|
|||||||
+17
-2
@@ -28,10 +28,13 @@ func (logger *StarLogger) GetWriter() io.Writer {
|
|||||||
return logger.logcore.output
|
return logger.logcore.output
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *StarLogger) SetHandler(f func([]Attr, string)) {
|
func (logger *StarLogger) SetHandler(f func(LogData)) {
|
||||||
|
if f != nil {
|
||||||
|
StartStacks()
|
||||||
|
}
|
||||||
logger.handlerFunc = f
|
logger.handlerFunc = f
|
||||||
}
|
}
|
||||||
func (logger *StarLogger) GetHandler() func([]Attr, string) {
|
func (logger *StarLogger) GetHandler() func(LogData) {
|
||||||
return logger.handlerFunc
|
return logger.handlerFunc
|
||||||
}
|
}
|
||||||
func (logger *StarLogger) SetSwitching(sw bool) {
|
func (logger *StarLogger) SetSwitching(sw bool) {
|
||||||
@@ -204,3 +207,15 @@ func (logger *StarLogger) Logf(showLog bool, level int, format string, str ...in
|
|||||||
func (logger *StarLogger) Logln(showLog bool, level int, str ...interface{}) {
|
func (logger *StarLogger) Logln(showLog bool, level int, str ...interface{}) {
|
||||||
logger.logcore.Logln(logger.thread, logger.isStd, showLog, level, logger.handlerFunc, str...)
|
logger.logcore.Logln(logger.thread, logger.isStd, showLog, level, logger.handlerFunc, str...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (logger *StarLogger) Write(str ...interface{}) {
|
||||||
|
logger.logcore.Write(str...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (logger *StarLogger) Writef(format string, str ...interface{}) {
|
||||||
|
logger.logcore.Writef(format, str...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (logger *StarLogger) Writeln(str ...interface{}) {
|
||||||
|
logger.logcore.Writeln(str...)
|
||||||
|
}
|
||||||
|
|||||||
@@ -33,16 +33,18 @@ var (
|
|||||||
LvPanic: "PANIC",
|
LvPanic: "PANIC",
|
||||||
LvFatal: "FATAL",
|
LvFatal: "FATAL",
|
||||||
}
|
}
|
||||||
stacks *starmap.StarStack
|
stacks *starmap.StarChanStack
|
||||||
stackStarted bool = false
|
stackStarted bool = false
|
||||||
stackStopChan chan int
|
stackStopChan chan int
|
||||||
stackMu sync.Mutex
|
stackMu sync.Mutex
|
||||||
stdScreen io.Writer = colorable.NewColorableStdout()
|
stdScreen io.Writer = colorable.NewColorableStdout()
|
||||||
|
errScreen io.Writer = colorable.NewColorableStderr()
|
||||||
)
|
)
|
||||||
|
|
||||||
type starlog struct {
|
type starlog struct {
|
||||||
mu *sync.Mutex
|
mu *sync.Mutex
|
||||||
output io.Writer
|
output io.Writer
|
||||||
|
errOutputLevel int
|
||||||
showFuncName bool
|
showFuncName bool
|
||||||
showThread bool
|
showThread bool
|
||||||
showLevel bool
|
showLevel bool
|
||||||
@@ -53,28 +55,34 @@ type starlog struct {
|
|||||||
onlyColorLevel bool
|
onlyColorLevel bool
|
||||||
stopWriter bool
|
stopWriter bool
|
||||||
id string
|
id string
|
||||||
|
name string
|
||||||
colorList map[int][]Attr
|
colorList map[int][]Attr
|
||||||
colorMe map[int]*Color
|
colorMe map[int]*Color
|
||||||
}
|
}
|
||||||
|
|
||||||
type StarLogger struct {
|
type StarLogger struct {
|
||||||
thread string
|
thread string
|
||||||
handlerFunc func([]Attr, string)
|
handlerFunc func(LogData)
|
||||||
logcore *starlog
|
logcore *starlog
|
||||||
isStd bool
|
isStd bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type logTransfer struct {
|
type logTransfer struct {
|
||||||
handlerFunc func([]Attr, string)
|
handlerFunc func(LogData)
|
||||||
colors []Attr
|
LogData
|
||||||
logStr string
|
}
|
||||||
|
|
||||||
|
type LogData struct {
|
||||||
|
Name string
|
||||||
|
Log string
|
||||||
|
Colors []Attr
|
||||||
}
|
}
|
||||||
|
|
||||||
func newLogCore(out io.Writer) *starlog {
|
func newLogCore(out io.Writer) *starlog {
|
||||||
return &starlog{
|
return &starlog{
|
||||||
mu: &sync.Mutex{},
|
mu: &sync.Mutex{},
|
||||||
output: out,
|
output: out,
|
||||||
|
errOutputLevel: LvError,
|
||||||
showFuncName: true,
|
showFuncName: true,
|
||||||
showThread: true,
|
showThread: true,
|
||||||
showLevel: true,
|
showLevel: true,
|
||||||
@@ -87,7 +95,7 @@ func newLogCore(out io.Writer) *starlog {
|
|||||||
colorList: map[int][]Attr{
|
colorList: map[int][]Attr{
|
||||||
LvDebug: []Attr{FgWhite},
|
LvDebug: []Attr{FgWhite},
|
||||||
LvInfo: []Attr{FgGreen},
|
LvInfo: []Attr{FgGreen},
|
||||||
LvNotice: []Attr{FgBlue},
|
LvNotice: []Attr{FgCyan},
|
||||||
LvWarning: []Attr{FgYellow},
|
LvWarning: []Attr{FgYellow},
|
||||||
LvError: []Attr{FgMagenta},
|
LvError: []Attr{FgMagenta},
|
||||||
LvCritical: []Attr{FgRed, Bold},
|
LvCritical: []Attr{FgRed, Bold},
|
||||||
@@ -97,7 +105,7 @@ func newLogCore(out io.Writer) *starlog {
|
|||||||
colorMe: map[int]*Color{
|
colorMe: map[int]*Color{
|
||||||
LvDebug: NewColor([]Attr{FgWhite}...),
|
LvDebug: NewColor([]Attr{FgWhite}...),
|
||||||
LvInfo: NewColor([]Attr{FgGreen}...),
|
LvInfo: NewColor([]Attr{FgGreen}...),
|
||||||
LvNotice: NewColor([]Attr{FgBlue}...),
|
LvNotice: NewColor([]Attr{FgCyan}...),
|
||||||
LvWarning: NewColor([]Attr{FgYellow}...),
|
LvWarning: NewColor([]Attr{FgYellow}...),
|
||||||
LvError: NewColor([]Attr{FgMagenta}...),
|
LvError: NewColor([]Attr{FgMagenta}...),
|
||||||
LvCritical: NewColor([]Attr{FgRed, Bold}...),
|
LvCritical: NewColor([]Attr{FgRed, Bold}...),
|
||||||
@@ -116,6 +124,18 @@ func NewStarlog(out io.Writer) *StarLogger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (logger *StarLogger) StdErrLevel() int {
|
||||||
|
logger.logcore.mu.Lock()
|
||||||
|
defer logger.logcore.mu.Unlock()
|
||||||
|
return logger.logcore.errOutputLevel
|
||||||
|
}
|
||||||
|
|
||||||
|
func (logger *StarLogger) SetStdErrLevel(level int) {
|
||||||
|
logger.logcore.mu.Lock()
|
||||||
|
defer logger.logcore.mu.Unlock()
|
||||||
|
logger.logcore.errOutputLevel = level
|
||||||
|
}
|
||||||
|
|
||||||
func (logger *StarLogger) NewFlag() *StarLogger {
|
func (logger *StarLogger) NewFlag() *StarLogger {
|
||||||
return &StarLogger{
|
return &StarLogger{
|
||||||
thread: getRandomFlag(false),
|
thread: getRandomFlag(false),
|
||||||
@@ -128,6 +148,16 @@ func (logger *StarLogger) SetNewRandomFlag() {
|
|||||||
logger.thread = getRandomFlag(false)
|
logger.thread = getRandomFlag(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (logger *StarLogger) SetName(name string) {
|
||||||
|
logger.logcore.mu.Lock()
|
||||||
|
defer logger.logcore.mu.Unlock()
|
||||||
|
logger.logcore.name = name
|
||||||
|
}
|
||||||
|
|
||||||
|
func (logger *StarLogger) GetName() string {
|
||||||
|
return logger.logcore.name
|
||||||
|
}
|
||||||
|
|
||||||
func getRandomFlag(isMain bool) string {
|
func getRandomFlag(isMain bool) string {
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
if isMain {
|
if isMain {
|
||||||
@@ -151,9 +181,12 @@ func StartStacks() {
|
|||||||
stackMu.Unlock()
|
stackMu.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
unlock := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
stackStarted = true
|
stackStarted = true
|
||||||
|
stacks = starmap.NewStarChanStack(1024)
|
||||||
stackMu.Unlock()
|
stackMu.Unlock()
|
||||||
|
unlock <- struct{}{}
|
||||||
defer func() {
|
defer func() {
|
||||||
stackStarted = false
|
stackStarted = false
|
||||||
}()
|
}()
|
||||||
@@ -163,17 +196,17 @@ func StartStacks() {
|
|||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
poped := stacks.MustPop()
|
poped, err := stacks.Pop()
|
||||||
if poped == nil {
|
if err != nil {
|
||||||
time.Sleep(time.Microsecond * 500)
|
return
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
val := poped.(logTransfer)
|
val := poped.(logTransfer)
|
||||||
if val.handlerFunc != nil {
|
if val.handlerFunc != nil {
|
||||||
val.handlerFunc(val.colors, val.logStr)
|
val.handlerFunc(val.LogData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
<-unlock
|
||||||
}
|
}
|
||||||
|
|
||||||
func StopStacks() {
|
func StopStacks() {
|
||||||
@@ -184,5 +217,6 @@ func StopStacks() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Stop() {
|
func Stop() {
|
||||||
|
stacks.Close()
|
||||||
StopStacks()
|
StopStacks()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user