diff --git a/cache.go b/cache.go index 719e87d..a0595f8 100644 --- a/cache.go +++ b/cache.go @@ -11,19 +11,19 @@ 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}) } } @@ -31,13 +31,13 @@ func (l *BaseLocatr) getLocatrsFromState(key string, currentUrl string) ([]strin 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() @@ -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)) @@ -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 } diff --git a/locatr.go b/locatr.go index 02dce07..f3c0d9c 100644 --- a/locatr.go +++ b/locatr.go @@ -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 { @@ -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 { @@ -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 } } @@ -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) @@ -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 }