Skip to content

Commit

Permalink
Merge pull request #14 from DrOctavius/main
Browse files Browse the repository at this point in the history
fixes
  • Loading branch information
DrOctavius authored Aug 9, 2022
2 parents ec114e7 + d5022f5 commit a2f4254
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 10 deletions.
16 changes: 8 additions & 8 deletions core/helpers/filesystem/lock/flock.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
fsPath "github.com/kyaxcorp/go-core/core/helpers/filesystem/path"
"github.com/kyaxcorp/go-core/core/helpers/folder"
"github.com/kyaxcorp/go-core/core/helpers/hash"
"github.com/kyaxcorp/go-core/core/logger/appLog"
"github.com/kyaxcorp/go-core/core/logger/coreLog"
"sync"
)

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

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

Expand All @@ -45,28 +45,28 @@ func getLocksDir() (string, error) {
folder.MkDir(locksPath)
}

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

return locksPath, nil
}

func FLock(lockName string, wait bool) (bool, error) {
appLog.Info().
coreLog.Info().
Str("lock_name", lockName).
Bool("wait", wait).
Msg("FLock called")
defer appLog.Info().Msg("leaving...")
defer coreLog.Info().Msg("leaving...")
lockNameHash := getLockName(lockName)
appLog.Info().
coreLog.Info().
Str("lock_name_hashed", lockNameHash).
Msg("lock name hashed, getting lock path")
lockPath, lockPathErr := getLockPath(lockName)
if lockPathErr != nil {
appLog.Error().Err(lockPathErr).Msg("failed to get lock path")
coreLog.Error().Err(lockPathErr).Msg("failed to get lock path")
return false, lockPathErr
}

appLog.Info().Str("lock_path", lockPath).Msg("lock path retrieved")
coreLog.Info().Str("lock_path", lockPath).Msg("lock path retrieved")

// log.Println(lockPath)
fileLock := flock.New(lockPath)
Expand Down
9 changes: 7 additions & 2 deletions core/listeners/websocket/server/server_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,14 @@ func (c *Client) Disconnect() error {

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

c.pingTicker.Stop()
if c.pingTicker != nil {
c.pingTicker.Stop()
}
// TODO: check if channel closed
c.closeWritePump <- true // Close the write pump!
c.isDisconnecting.True()
if c.isDisconnecting != nil {
c.isDisconnecting.True()
}
c.server.WSRegistrationHub.unregister <- c
// This is a force Close!
return c.conn.Close()
Expand Down
29 changes: 29 additions & 0 deletions core/logger/application/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package application

import (
configEvents "github.com/kyaxcorp/go-core/core/config/events"
"github.com/kyaxcorp/go-core/core/helpers/conv"
"github.com/kyaxcorp/go-core/core/logger"
"github.com/kyaxcorp/go-core/core/logger/application/vars"
loggerConfig "github.com/kyaxcorp/go-core/core/logger/config"
loggerPaths "github.com/kyaxcorp/go-core/core/logger/paths"
"os"
)

// Define variables
var applicationLoggerConfig loggerConfig.Config
var coreLoggerConfig loggerConfig.Config

type MainLogOptions struct {
Level int
Expand All @@ -35,3 +38,29 @@ func RegisterAppLogger() {
CreateAppLogger(MainLogOptions{})
})
}

func CreateCoreLogger() bool {
logLevel := os.Getenv("GO_CORE_LOG_LEVEL")
var lvl int
if logLevel == "" {
lvl = 4
} else {
lvl = conv.StrToInt(logLevel)
}

coreLoggerConfig, _ = loggerConfig.DefaultConfig(&loggerConfig.Config{
IsEnabled: "yes",
Name: "core",
ModuleName: "Core",
Description: "saving all core logs...",
Level: lvl, // take from the environment

FileIsEnabled: "no",
ConsoleIsEnabled: "yes",
})
// This is the Application Logger, it will save all logs
vars.CoreLogger = logger.New(coreLoggerConfig)
return true
}

var _ = CreateCoreLogger()
4 changes: 4 additions & 0 deletions core/logger/application/vars/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ import "github.com/kyaxcorp/go-core/core/logger/model"

// ApplicationLogger -> This is the app logger which handles all logs writing to a single file
var ApplicationLogger *model.Logger

// CoreLogger -> this is the first logger which is been created...
// it's more for debugging lib things
var CoreLogger *model.Logger
6 changes: 6 additions & 0 deletions core/logger/constructor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ func GetAppLogger() *model.Logger {
return vars.ApplicationLogger
}

// GetCoreLogger -> it returns the instance which is the main logger of the app, it centralizes all the data together
func GetCoreLogger() *model.Logger {
// TODO: we can switch loggers when the app logger has started... but there should be a logic of levels...
return vars.CoreLogger
}

//func New(ctx context.Context, config config.Config) *Logger {

// Here we will store writers which handle writing to file, if we don't want to create multiple handlers and have conflict,
Expand Down
63 changes: 63 additions & 0 deletions core/logger/coreLog/logs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package coreLog

import (
"github.com/kyaxcorp/go-core/core/logger"
"github.com/kyaxcorp/go-core/core/logger/model"
"github.com/rs/zerolog"
)

func getApp() *model.Logger {
return logger.GetCoreLogger()
}

//--------------------------\\

func Info() *zerolog.Event {
return getApp().Info()
}

func Warn() *zerolog.Event {
return getApp().Warn()
}

func Error() *zerolog.Event {
return getApp().Error()
}

func Debug() *zerolog.Event {
return getApp().Debug()
}

func Fatal() *zerolog.Event {
return getApp().Fatal()
}

func Panic() *zerolog.Event {
return getApp().Panic()
}

//--------------------------\\

func InfoF(functionName string) *zerolog.Event {
return getApp().InfoF(functionName)
}

func WarnF(functionName string) *zerolog.Event {
return getApp().WarnF(functionName)
}

func ErrorF(functionName string) *zerolog.Event {
return getApp().ErrorF(functionName)
}

func DebugF(functionName string) *zerolog.Event {
return getApp().DebugF(functionName)
}

func FatalF(functionName string) *zerolog.Event {
return getApp().FatalF(functionName)
}

func PanicF(functionName string) *zerolog.Event {
return getApp().PanicF(functionName)
}

0 comments on commit a2f4254

Please sign in to comment.