Skip to content

Commit d5022f5

Browse files
committed
fixes
1 parent 4e702e3 commit d5022f5

File tree

6 files changed

+117
-10
lines changed

6 files changed

+117
-10
lines changed

Diff for: core/helpers/filesystem/lock/flock.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
fsPath "github.com/kyaxcorp/go-core/core/helpers/filesystem/path"
88
"github.com/kyaxcorp/go-core/core/helpers/folder"
99
"github.com/kyaxcorp/go-core/core/helpers/hash"
10-
"github.com/kyaxcorp/go-core/core/logger/appLog"
10+
"github.com/kyaxcorp/go-core/core/logger/coreLog"
1111
"sync"
1212
)
1313

@@ -33,7 +33,7 @@ func getLockPath(lockName string) (string, error) {
3333
func getLocksDir() (string, error) {
3434
var pathErr error
3535
locksPath := config.GetConfig().Application.LocksPath
36-
appLog.Info().Str("application_locks_path", locksPath).Msg("application locks path")
36+
coreLog.Info().Str("application_locks_path", locksPath).Msg("application locks path")
3737

3838
locksPath, pathErr = fsPath.GenRealPath(locksPath, true)
3939

@@ -45,28 +45,28 @@ func getLocksDir() (string, error) {
4545
folder.MkDir(locksPath)
4646
}
4747

48-
appLog.Info().Str("locks_dir", locksPath).Msg("application generated real path")
48+
coreLog.Info().Str("locks_dir", locksPath).Msg("application generated real path")
4949

5050
return locksPath, nil
5151
}
5252

5353
func FLock(lockName string, wait bool) (bool, error) {
54-
appLog.Info().
54+
coreLog.Info().
5555
Str("lock_name", lockName).
5656
Bool("wait", wait).
5757
Msg("FLock called")
58-
defer appLog.Info().Msg("leaving...")
58+
defer coreLog.Info().Msg("leaving...")
5959
lockNameHash := getLockName(lockName)
60-
appLog.Info().
60+
coreLog.Info().
6161
Str("lock_name_hashed", lockNameHash).
6262
Msg("lock name hashed, getting lock path")
6363
lockPath, lockPathErr := getLockPath(lockName)
6464
if lockPathErr != nil {
65-
appLog.Error().Err(lockPathErr).Msg("failed to get lock path")
65+
coreLog.Error().Err(lockPathErr).Msg("failed to get lock path")
6666
return false, lockPathErr
6767
}
6868

69-
appLog.Info().Str("lock_path", lockPath).Msg("lock path retrieved")
69+
coreLog.Info().Str("lock_path", lockPath).Msg("lock path retrieved")
7070

7171
// log.Println(lockPath)
7272
fileLock := flock.New(lockPath)

Diff for: core/listeners/websocket/server/server_client.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,14 @@ func (c *Client) Disconnect() error {
6969

7070
info().Msg("closing the client connection...")
7171

72-
c.pingTicker.Stop()
72+
if c.pingTicker != nil {
73+
c.pingTicker.Stop()
74+
}
75+
// TODO: check if channel closed
7376
c.closeWritePump <- true // Close the write pump!
74-
c.isDisconnecting.True()
77+
if c.isDisconnecting != nil {
78+
c.isDisconnecting.True()
79+
}
7580
c.server.WSRegistrationHub.unregister <- c
7681
// This is a force Close!
7782
return c.conn.Close()

Diff for: core/logger/application/app.go

+29
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ package application
22

33
import (
44
configEvents "github.com/kyaxcorp/go-core/core/config/events"
5+
"github.com/kyaxcorp/go-core/core/helpers/conv"
56
"github.com/kyaxcorp/go-core/core/logger"
67
"github.com/kyaxcorp/go-core/core/logger/application/vars"
78
loggerConfig "github.com/kyaxcorp/go-core/core/logger/config"
89
loggerPaths "github.com/kyaxcorp/go-core/core/logger/paths"
10+
"os"
911
)
1012

1113
// Define variables
1214
var applicationLoggerConfig loggerConfig.Config
15+
var coreLoggerConfig loggerConfig.Config
1316

1417
type MainLogOptions struct {
1518
Level int
@@ -35,3 +38,29 @@ func RegisterAppLogger() {
3538
CreateAppLogger(MainLogOptions{})
3639
})
3740
}
41+
42+
func CreateCoreLogger() bool {
43+
logLevel := os.Getenv("GO_CORE_LOG_LEVEL")
44+
var lvl int
45+
if logLevel == "" {
46+
lvl = 4
47+
} else {
48+
lvl = conv.StrToInt(logLevel)
49+
}
50+
51+
coreLoggerConfig, _ = loggerConfig.DefaultConfig(&loggerConfig.Config{
52+
IsEnabled: "yes",
53+
Name: "core",
54+
ModuleName: "Core",
55+
Description: "saving all core logs...",
56+
Level: lvl, // take from the environment
57+
58+
FileIsEnabled: "no",
59+
ConsoleIsEnabled: "yes",
60+
})
61+
// This is the Application Logger, it will save all logs
62+
vars.CoreLogger = logger.New(coreLoggerConfig)
63+
return true
64+
}
65+
66+
var _ = CreateCoreLogger()

Diff for: core/logger/application/vars/logger.go

+4
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ import "github.com/kyaxcorp/go-core/core/logger/model"
44

55
// ApplicationLogger -> This is the app logger which handles all logs writing to a single file
66
var ApplicationLogger *model.Logger
7+
8+
// CoreLogger -> this is the first logger which is been created...
9+
// it's more for debugging lib things
10+
var CoreLogger *model.Logger

Diff for: core/logger/constructor.go

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ func GetAppLogger() *model.Logger {
2323
return vars.ApplicationLogger
2424
}
2525

26+
// GetCoreLogger -> it returns the instance which is the main logger of the app, it centralizes all the data together
27+
func GetCoreLogger() *model.Logger {
28+
// TODO: we can switch loggers when the app logger has started... but there should be a logic of levels...
29+
return vars.CoreLogger
30+
}
31+
2632
//func New(ctx context.Context, config config.Config) *Logger {
2733

2834
// Here we will store writers which handle writing to file, if we don't want to create multiple handlers and have conflict,

Diff for: core/logger/coreLog/logs.go

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package coreLog
2+
3+
import (
4+
"github.com/kyaxcorp/go-core/core/logger"
5+
"github.com/kyaxcorp/go-core/core/logger/model"
6+
"github.com/rs/zerolog"
7+
)
8+
9+
func getApp() *model.Logger {
10+
return logger.GetCoreLogger()
11+
}
12+
13+
//--------------------------\\
14+
15+
func Info() *zerolog.Event {
16+
return getApp().Info()
17+
}
18+
19+
func Warn() *zerolog.Event {
20+
return getApp().Warn()
21+
}
22+
23+
func Error() *zerolog.Event {
24+
return getApp().Error()
25+
}
26+
27+
func Debug() *zerolog.Event {
28+
return getApp().Debug()
29+
}
30+
31+
func Fatal() *zerolog.Event {
32+
return getApp().Fatal()
33+
}
34+
35+
func Panic() *zerolog.Event {
36+
return getApp().Panic()
37+
}
38+
39+
//--------------------------\\
40+
41+
func InfoF(functionName string) *zerolog.Event {
42+
return getApp().InfoF(functionName)
43+
}
44+
45+
func WarnF(functionName string) *zerolog.Event {
46+
return getApp().WarnF(functionName)
47+
}
48+
49+
func ErrorF(functionName string) *zerolog.Event {
50+
return getApp().ErrorF(functionName)
51+
}
52+
53+
func DebugF(functionName string) *zerolog.Event {
54+
return getApp().DebugF(functionName)
55+
}
56+
57+
func FatalF(functionName string) *zerolog.Event {
58+
return getApp().FatalF(functionName)
59+
}
60+
61+
func PanicF(functionName string) *zerolog.Event {
62+
return getApp().PanicF(functionName)
63+
}

0 commit comments

Comments
 (0)