Skip to content

Commit

Permalink
fix: update log lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Neeraj319 committed Nov 12, 2024
1 parent 10a41f7 commit 7a8271b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
18 changes: 9 additions & 9 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,33 @@ import (

func (l *BaseLocatr) addCachedLocatrs(url string, locatrName string, locatrs []string) {
if _, ok := l.cachedLocatrs[url]; !ok {
l.logger.Debug(fmt.Sprintf("Domain %s not found in cache... Creating new cachedLocatrsDto", url))
l.logger.Debug(fmt.Sprintf("Domain `%s` not found in cache... Creating new cachedLocatrsDto", url))
l.cachedLocatrs[url] = []cachedLocatrsDto{}
}
found := false
for i, v := range l.cachedLocatrs[url] {
if v.LocatrName == locatrName {
l.logger.Debug(fmt.Sprintf("Found locatr %s in cache... Updating locators", locatrName))
l.logger.Debug(fmt.Sprintf("Found locatr `%s` in cache... Updating locators", locatrName))
l.cachedLocatrs[url][i].Locatrs = GetUniqueStringArray(append(l.cachedLocatrs[url][i].Locatrs, locatrs...))
return
}
}
if !found {
l.logger.Debug(fmt.Sprintf("Locatr %s not found in cache... Creating new locatr", locatrName))
l.logger.Debug(fmt.Sprintf("Locatr `%s` not found in cache... Creating new locatr", locatrName))
l.cachedLocatrs[url] = append(l.cachedLocatrs[url], cachedLocatrsDto{LocatrName: locatrName, Locatrs: locatrs})
}
}
func (l *BaseLocatr) getLocatrsFromState(key string, currentUrl string) ([]string, error) {
if locatrs, ok := l.cachedLocatrs[currentUrl]; ok {
for _, v := range locatrs {
if v.LocatrName == key {
l.logger.Debug(fmt.Sprintf("Key %s found in cache", key))
l.logger.Debug(fmt.Sprintf("Key `%s` found in cache", key))
return v.Locatrs, nil
}
}
}
l.logger.Debug(fmt.Sprintf("Key %s not found in cache", key))
return nil, fmt.Errorf("key %s not found in cache", key)
l.logger.Debug(fmt.Sprintf("Key `%s not found in cache", key))
return nil, fmt.Errorf("key `%s` not found in cache", key)
}
func (l *BaseLocatr) loadLocatrsFromCache(userReq string) (string, error) {
requestInitatedAt := time.Now()
Expand All @@ -60,7 +60,7 @@ func (l *BaseLocatr) loadLocatrsFromCache(userReq string) (string, error) {
LocatrRequestCompletedAt: time.Now(),
}
l.locatrResults = append(l.locatrResults, result)
l.logger.Info(fmt.Sprintf("Cache hit, key: %s, value: %s", userReq, validLocator))
l.logger.Info(fmt.Sprintf("Cache hit, key: `%s`, value: `%s`", userReq, validLocator))
return validLocator, nil
} else {
l.logger.Error(fmt.Sprintf("Failed to find valid locator in cache: %v", err))
Expand All @@ -81,11 +81,11 @@ func (l *BaseLocatr) loadLocatorsCache(cachePath string) error {
defer file.Close()
byteValue, err := io.ReadAll(file)
if err != nil {
return fmt.Errorf("failed to read cache file (%s): %v", cachePath, err)
return fmt.Errorf("failed to read cache file `(%s)`: %v", cachePath, err)
}
err = json.Unmarshal(byteValue, &l.cachedLocatrs)
if err != nil {
return fmt.Errorf("failed to unmarshal cache file (%s): %v", cachePath, err)
return fmt.Errorf("failed to unmarshal cache file `(%s)`: %v", cachePath, err)
}
return nil
}
Expand Down
12 changes: 6 additions & 6 deletions locatr.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (l *BaseLocatr) getLocatorStr(userReq string) (string, error) {
return "", ErrUnableToLoadJsScripts
}
l.initializeState()
l.logger.Info(fmt.Sprintf("Getting locator for user request: %s", userReq))
l.logger.Info(fmt.Sprintf("Getting locator for user request: `%s`", userReq))
currentUrl := l.getCurrentUrl()
locatr, err := l.loadLocatrsFromCache(userReq)
if err == nil {
Expand Down Expand Up @@ -175,8 +175,8 @@ func (l *BaseLocatr) getLocatorStr(userReq string) (string, error) {
)...,
)
if l.options.UseCache {
l.logger.Info(fmt.Sprintf("Adding locatrs of %s to cache", userReq))
l.logger.Debug(fmt.Sprintf("Adding Locars of %s: %v to cache", userReq, locators))
l.logger.Info(fmt.Sprintf("Adding locatrs of `%s to cache", userReq))
l.logger.Debug(fmt.Sprintf("Adding Locars of `%s`: `%v` to cache", userReq, locators))
l.addCachedLocatrs(currentUrl, userReq, locators)
value, err := json.Marshal(l.cachedLocatrs)
if err != nil {
Expand Down Expand Up @@ -219,7 +219,7 @@ func (l *BaseLocatr) getMinifiedDomAndLocatorMap() (*ElementSpec, *IdToLocatorMa
func (l *BaseLocatr) getValidLocator(locators []string) (string, error) {
for _, locator := range locators {
if value, _ := l.plugin.evaluateJsFunction(fmt.Sprintf("isValidLocator('%s')", locator)); value == "true" {
l.logger.Debug(fmt.Sprintf("Valid locator found: %s", locator))
l.logger.Debug(fmt.Sprintf("Valid locator found: `%s`", locator))
return locator, nil
}
}
Expand Down Expand Up @@ -344,7 +344,7 @@ func (l *BaseLocatr) locateElementId(htmlDOM string, userReq string) ([]locatrOu
domToProcess = htmlDOM
}

l.logger.Debug(fmt.Sprintf("%d attempt to find locatr with reranking", attempt+1))
l.logger.Debug(fmt.Sprintf("attempt no (%d) to find locatr with reranking", attempt+1))
requestCompletedAt := time.Now()

result, err := l.llmGetElementId(domToProcess, userReq)
Expand All @@ -363,7 +363,7 @@ func (l *BaseLocatr) locateElementId(htmlDOM string, userReq string) ([]locatrOu
return llmOutputs, nil
}

l.logger.Error(fmt.Sprintf("Failed to get locatr in attempt(s) %d: %s", attempt+1, result.Error))
l.logger.Error(fmt.Sprintf("Failed to get locatr in %d attempt(s) : %s", attempt+1, result.Error))
}
return llmOutputs, ErrLocatrRetrievalAttemptsExhausted
}
Expand Down

0 comments on commit 7a8271b

Please sign in to comment.