How to use Infof method of logger Package

Best Gauge code snippet using logger.Infof

bodyweight.go

Source:bodyweight.go Github

copy

Full Screen

...40func (u bodyweight) Create(ctx context.Context, weight, date, userID string, fh *multipart.FileHeader) (bodyweightID uint, err error) {41 m := models.BodyWeight{}42 timeDate, err := time.Parse(time.RFC3339, date)43 if err != nil {44 logger.Infof("could not parse time: %s", err.Error())45 return 0, err46 }47 m.Date = timeDate48 weightInt, err := strconv.ParseFloat(weight, 64)49 if err != nil {50 logger.Infof("could not parse weight string to float64: %s", err.Error())51 return 0, err52 }53 m.Weight = float64(weightInt)54 userIDInt, err := strconv.Atoi(userID)55 unixTime := time.Now().Unix()56 if err != nil {57 logger.Infof("could not parse weight string to float64: %s", err.Error())58 return 0, err59 }60 m.UserID = uint(userIDInt)61 if fh == nil {62 m.Image = constants.ImageDefault63 } else {64 f, err := fh.Open()65 if err != nil {66 logger.Infof("could not open file header %s", err.Error())67 return 0, err68 }69 defer f.Close()70 ft := fh.Header.Get("Content-Type")71 _, err = s3.GetS3Client().PutObjectWithContext(72 ctx,73 "static-luqmanul",74 fmt.Sprintf("refit/users/%s/bodyweights/%d.%s", userID, unixTime, helpers.GetExtensionFile(ft)),75 f,76 fh.Size,77 minio.PutObjectOptions{78 ContentType: ft,79 UserMetadata: map[string]string{80 "x-amz-acl": "public-read",81 },82 },83 )84 if err != nil {85 logger.Infof("could not put object to spaces: %s", err.Error())86 return 0, err87 }88 m.Image = fmt.Sprintf("https://static.luqmanul.com/refit/users/%s/bodyweights/%d.%s", userID, unixTime, helpers.GetExtensionFile(fh.Header.Get("Content-Type")))89 }90 m.CreatedAt = time.Now()91 bodyweightID, err = u.repository.BodyWeight().Create(ctx, &m)92 if err != nil {93 logger.Infof("could not create bodyweight repository: %s", err.Error())94 return 0, err95 }96 return bodyweightID, nil97}98func (u bodyweight) FindOneByID(ctx context.Context, bodyWeightID string) (m *models.BodyWeight, err error) {99 err = validation.Validate(bodyWeightID, validation.Match(regexNumberOnly))100 if err != nil {101 logger.Infof("could not validate: %s", err.Error())102 return nil, errors.New("invalid bodyweight_id param, should be number only")103 }104 m, err = u.repository.BodyWeight().FindOneByID(ctx, bodyWeightID)105 if err != nil {106 switch {107 case err == sql.ErrNoRows:108 logger.Infof("could not find bodyweight by id: %s", err.Error())109 return nil, errors.New("bodyweight_id not exists")110 default:111 logger.Infof("could not find bodyweight by id: %s", err.Error())112 return nil, err113 }114 }115 return m, nil116}117func (u bodyweight) FindAll(ctx context.Context, limit, offset, order, userID string) (lm []*models.BodyWeight, count uint, err error) {118 err = helpers.ValidationQueryParamFindAll(limit, offset, order)119 if err != nil {120 logger.Infof("could not validate: %s", err.Error())121 return nil, 0, err122 }123 lm, err = u.repository.BodyWeight().FindAll(ctx, limit, offset, order, userID)124 if err != nil {125 switch {126 case err == sql.ErrNoRows:127 logger.Infof("could not find all BodyWeight: %s", err.Error())128 return nil, 0, errors.New("no row exists")129 default:130 logger.Infof("could not find all BodyWeight: %s", err.Error())131 return nil, 0, err132 }133 }134 count, err = u.repository.BodyWeight().Count(ctx, userID)135 if err != nil {136 switch {137 case err == sql.ErrNoRows:138 logger.Infof("could not find all body_weight: %s", err.Error())139 return nil, 0, errors.New("no row exists")140 default:141 logger.Infof("could not find all body_weight: %s", err.Error())142 return nil, 0, err143 }144 }145 return lm, count, nil146}147func (u bodyweight) UpdateByID(ctx context.Context, weight, date, bodyweightID string, fh *multipart.FileHeader) (err error) {148 mb, err := u.repository.BodyWeight().FindOneByID(ctx, bodyweightID)149 if err != nil {150 switch {151 case err == sql.ErrNoRows:152 logger.Infof("could not find bodyweight by id: %s", err.Error())153 return errors.New("bodyweight_id not exists")154 default:155 logger.Infof("could not find bodyweight by id: %s", err.Error())156 return err157 }158 }159 var (160 unixTime = time.Now().Unix()161 image = ""162 )163 if fh == nil {164 image = mb.Image165 } else {166 f, err := fh.Open()167 if err != nil {168 logger.Infof("could not open file header %s", err.Error())169 return err170 }171 defer f.Close()172 ft := fh.Header.Get("Content-Type")173 _, err = s3.GetS3Client().PutObjectWithContext(174 ctx,175 "static-luqmanul",176 fmt.Sprintf("refit/users/%d/bodyweights/%d.%s", mb.UserID, unixTime, helpers.GetExtensionFile(ft)),177 f,178 fh.Size,179 minio.PutObjectOptions{180 ContentType: ft,181 UserMetadata: map[string]string{182 "x-amz-acl": "public-read",183 },184 },185 )186 if err != nil {187 logger.Infof("could not put object to spaces: %s", err.Error())188 return err189 }190 image = fmt.Sprintf("https://static.luqmanul.com/refit/users/%d/bodyweights/%d.%s", mb.UserID, unixTime, helpers.GetExtensionFile(fh.Header.Get("Content-Type")))191 }192 t, err := time.Parse(time.RFC3339, date)193 if err != nil {194 logger.Infof("could not parse date: %s", err.Error())195 return errors.New("invalid date")196 }197 intBodyWeightID, err := strconv.Atoi(bodyweightID)198 if err != nil {199 logger.Infof("could not parse bodyweight_id: %s", err.Error())200 return errors.New("invalid date")201 }202 intWeight, err := strconv.Atoi(weight)203 if err != nil {204 logger.Infof("could not parse weight: %s", err.Error())205 return errors.New("invalid date")206 }207 rm := models.BodyWeight{208 ID: uint(intBodyWeightID),209 Weight: float64(intWeight),210 UserID: mb.UserID,211 CreatedAt: mb.CreatedAt,212 Date: t,213 Image: image,214 }215 _, err = u.repository.BodyWeight().UpdateByID(ctx, &rm)216 if err != nil {217 logger.Infof("could not update bodyweight by id: %s", err.Error())218 return err219 }220 return nil221}222func (u bodyweight) DeleteByID(ctx context.Context, bodyweightID string) (err error) {223 err = validation.Validate(bodyweightID, validation.Match(regexNumberOnly))224 if err != nil {225 logger.Infof("could not validate: %s", err.Error())226 return errors.New("invalid bodyweight_id param, should be number only")227 }228 _, err = u.repository.BodyWeight().DeleteByID(ctx, bodyweightID)229 if err != nil {230 switch {231 case err == sql.ErrNoRows:232 logger.Infof("could not delete bodyweight by id: %s", err.Error())233 return errors.New("bodyweight_id not exists")234 default:235 logger.Infof("could not delete bodyweight by id: %s", err.Error())236 return err237 }238 }239 return nil240}...

Full Screen

Full Screen

users.go

Source:users.go Github

copy

Full Screen

...40// FindOneByID services users41func (u users) FindOneByID(ctx context.Context, userID string) (mu *models.User, err error) {42 err = validation.Validate(userID, validation.Match(regexNumberOnly))43 if err != nil {44 logger.Infof("could not validate: %s", err.Error())45 return nil, errors.New("invalid userID param, should be number only")46 }47 mu, err = u.repository.Users().FindOneByID(ctx, userID)48 if err != nil {49 switch {50 case err == sql.ErrNoRows:51 logger.Infof("could not find user by id: %s", err.Error())52 return nil, errors.New("userID not exists")53 default:54 logger.Infof("could not find user by id: %s", err.Error())55 return nil, err56 }57 }58 // Remove sensitive data59 mu.Password = ""60 return mu, nil61}62// Create services users63func (u users) Create(ctx context.Context, ru *models.User) (userID uint, err error) {64 err = ru.ValidateCreate()65 if err != nil {66 logger.Infof("could not validate: %s", err.Error())67 return 0, err68 }69 passwordHashed, err := bcrypt.GenerateFromPassword([]byte(ru.Password), bcrypt.DefaultCost)70 if err != nil {71 logger.Infof("could not hash password: %s", err.Error())72 return 0, errors.New("could not hash password")73 }74 ru.Password = string(passwordHashed)75 ru.RoleID = 2 // Set role_id to Normal User by default76 ru.CreatedAt = time.Now()77 ru.UpdatedAt = time.Now()78 userID, err = u.repository.Users().Create(ctx, ru)79 fmt.Print(err)80 if err != nil {81 if strings.Contains(err.Error(), "Duplicate") {82 logger.Infof("invalid email: email already used")83 return 0, errors.New("invalid email: email already used")84 }85 logger.Infof("could not create user to db: %s", err.Error())86 return 0, err87 }88 return userID, nil89}90// AuthLoginWithEmail services users91func (u users) AuthLoginWithEmail(ctx context.Context, ru *models.User) (token string, err error) {92 err = validation.ValidateStruct(ru,93 validation.Field(&ru.Email, validation.Required, is.Email),94 validation.Field(&ru.Password, validation.Required),95 )96 if err != nil {97 logger.Infof("could not validate: %s", err.Error())98 return "", err99 }100 mu, err := u.repository.Users().FindOneByEmail(ctx, ru.Email)101 if err != nil {102 switch {103 case err == sql.ErrNoRows:104 logger.Infof("could not find user by email: %s", err.Error())105 return "", errors.New("email or password is wrong")106 default:107 logger.Infof("could not find user by email: %s", err.Error())108 return "", err109 }110 }111 err = bcrypt.CompareHashAndPassword([]byte(mu.Password), []byte(ru.Password))112 if err != nil {113 logger.Warnf("could not compare hash password: %s", err.Error())114 return "", errors.New("password yang Anda masukkan salah")115 }116 claims := helpers.JWTPayload{117 UserID: mu.ID,118 StandardClaims: &jwt.StandardClaims{119 Audience: "MOBILE",120 Issuer: "Luqmanul Hakim API",121 IssuedAt: time.Now().Unix(),122 ExpiresAt: time.Now().Add(time.Minute * time.Duration(1440)).Unix(),123 },124 }125 token, err = helpers.GetJWTTokenGenerator().GenerateToken(claims)126 if err != nil {127 logger.Infof("could not generate token: %s", err.Error())128 return "", err129 }130 return token, nil131}132// FindAll service users133func (u users) FindAll(ctx context.Context, limit, offset, order string) (lmu []*models.User, count uint, err error) {134 err = helpers.ValidationQueryParamFindAll(limit, offset, order)135 if err != nil {136 logger.Infof("could not validate: %s", err.Error())137 return nil, 0, err138 }139 lmu, err = u.repository.Users().FindAll(ctx, limit, offset, order)140 if err != nil {141 switch {142 case err == sql.ErrNoRows:143 logger.Infof("could not find all user: %s", err.Error())144 return nil, 0, errors.New("no row exists")145 default:146 logger.Infof("could not find all user: %s", err.Error())147 return nil, 0, err148 }149 }150 // remove sensitive information151 for i := range lmu {152 lmu[i].Password = ""153 }154 count, err = u.repository.Users().Count(ctx)155 if err != nil {156 switch {157 case err == sql.ErrNoRows:158 logger.Infof("could not find all user: %s", err.Error())159 return nil, 0, errors.New("no row exists")160 default:161 logger.Infof("could not find all user: %s", err.Error())162 return nil, 0, err163 }164 }165 return lmu, count, nil166}167//168func (u users) UpdateByID(ctx context.Context, ru *models.User, userID string) (err error) {169 err = ru.ValidateUpdate()170 if err != nil {171 logger.Infof("could not validate: %s", err.Error())172 return err173 }174 mu, err := u.repository.Users().FindOneByID(ctx, userID)175 if err != nil {176 switch {177 case err == sql.ErrNoRows:178 logger.Infof("could not find user by id: %s", err.Error())179 return errors.New("userID not exists")180 default:181 logger.Infof("could not find user by id: %s", err.Error())182 return err183 }184 }185 ru.Email = mu.Email186 ru.RoleID = mu.RoleID187 ru.Password = mu.Password188 ru.UpdatedAt = time.Now()189 _, err = u.repository.Users().UpdateByID(ctx, ru, userID)190 if err != nil {191 logger.Infof("could not update user by id: %s", err.Error())192 return err193 }194 return nil195}196func (u users) DeleteByID(ctx context.Context, userID string) (err error) {197 err = validation.Validate(userID, validation.Match(regexNumberOnly))198 if err != nil {199 logger.Infof("could not validate: %s", err.Error())200 return errors.New("invalid userID param, should be number only")201 }202 _, err = u.repository.Users().DeleteByID(ctx, userID)203 if err != nil {204 switch {205 case err == sql.ErrNoRows:206 logger.Infof("could not delete user by id: %s", err.Error())207 return errors.New("userID not exists")208 default:209 logger.Infof("could not delete user by id: %s", err.Error())210 return err211 }212 }213 return nil214}...

Full Screen

Full Screen

logger.go

Source:logger.go Github

copy

Full Screen

...24type Logger struct {25 baseCl client.Interface26}27func (l *Logger) CreateOrder(ctx context.Context, order *acme.Order) (*acme.Order, error) {28 klog.Infof("Calling CreateOrder")29 return l.baseCl.CreateOrder(ctx, order)30}31func (l *Logger) GetOrder(ctx context.Context, url string) (*acme.Order, error) {32 klog.Infof("Calling GetOrder")33 return l.baseCl.GetOrder(ctx, url)34}35func (l *Logger) GetCertificate(ctx context.Context, url string) ([][]byte, error) {36 klog.Infof("Calling GetCertificate")37 return l.baseCl.GetCertificate(ctx, url)38}39func (l *Logger) WaitOrder(ctx context.Context, url string) (*acme.Order, error) {40 klog.Infof("Calling WaitOrder")41 return l.baseCl.WaitOrder(ctx, url)42}43func (l *Logger) FinalizeOrder(ctx context.Context, finalizeURL string, csr []byte) (der [][]byte, err error) {44 klog.Infof("Calling FinalizeOrder")45 return l.baseCl.FinalizeOrder(ctx, finalizeURL, csr)46}47func (l *Logger) AcceptChallenge(ctx context.Context, chal *acme.Challenge) (*acme.Challenge, error) {48 klog.Infof("Calling AcceptChallenge")49 return l.baseCl.AcceptChallenge(ctx, chal)50}51func (l *Logger) GetChallenge(ctx context.Context, url string) (*acme.Challenge, error) {52 klog.Infof("Calling GetChallenge")53 return l.baseCl.GetChallenge(ctx, url)54}55func (l *Logger) GetAuthorization(ctx context.Context, url string) (*acme.Authorization, error) {56 klog.Infof("Calling GetAuthorization")57 return l.baseCl.GetAuthorization(ctx, url)58}59func (l *Logger) WaitAuthorization(ctx context.Context, url string) (*acme.Authorization, error) {60 klog.Infof("Calling WaitAuthorization")61 return l.baseCl.WaitAuthorization(ctx, url)62}63func (l *Logger) CreateAccount(ctx context.Context, a *acme.Account) (*acme.Account, error) {64 klog.Infof("Calling CreateAccount")65 return l.baseCl.CreateAccount(ctx, a)66}67func (l *Logger) GetAccount(ctx context.Context) (*acme.Account, error) {68 klog.Infof("Calling GetAccount")69 return l.baseCl.GetAccount(ctx)70}71func (l *Logger) HTTP01ChallengeResponse(token string) (string, error) {72 klog.Infof("Calling HTTP01ChallengeResponse")73 return l.baseCl.HTTP01ChallengeResponse(token)74}75func (l *Logger) DNS01ChallengeRecord(token string) (string, error) {76 klog.Infof("Calling DNS01ChallengeRecord")77 return l.baseCl.DNS01ChallengeRecord(token)78}79func (l *Logger) Discover(ctx context.Context) (acme.Directory, error) {80 klog.Infof("Calling Discover")81 return l.baseCl.Discover(ctx)82}83func (l *Logger) UpdateAccount(ctx context.Context, a *acme.Account) (*acme.Account, error) {84 klog.Infof("Calling UpdateAccount")85 return l.baseCl.UpdateAccount(ctx, a)86}...

Full Screen

Full Screen

Infof

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 f, err := os.Create("log.txt")4 if err != nil {5 log.Fatal(err)6 }7 log.SetOutput(f)8 logger := log.New(f, "logger: ", log.Lshortfile)9 logger.Println("This is a regular message")10 logger.Infof("This is a %s message", "formatted")11}

Full Screen

Full Screen

Infof

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 f, err := os.Create("info.log")4 if err != nil {5 fmt.Println(err)6 }7 log.SetOutput(f)8 log.SetPrefix("Info: ")9 log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)10 log.Println("This is a log message")11 log.Fatalln("This is a fatal log message")12 log.Panicln("This is a panic log message")13}

Full Screen

Full Screen

Infof

Using AI Code Generation

copy

Full Screen

1import (2func main() {3logger := log.New(os.Stdout, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile)4logger.Infof("This is an informational message")5}6import (7func main() {8logger := log.New(os.Stdout, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)9logger.Errorf("This is an error message")10}11import (12func main() {13logger := log.New(os.Stdout, "FATAL: ", log.Ldate|log.Ltime|log.Lshortfile)14logger.Fatalf("This is a fatal message")15}16import (17func main() {18logger := log.New(os.Stdout, "PANIC: ", log.Ldate|log.Ltime|log.Lshortfile)

Full Screen

Full Screen

Infof

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 log.SetFlags(log.LstdFlags | log.Lshortfile)4 log.Printf("Hello, %s", "world")5}6import (7func main() {8 log.Panicf("Hello, %s", "world")9}10panic(0x4c6a60, 0xc82000e1e0)11main.main()12import (13func main() {14 log.Fatalf("Hello, %s", "world")15}16import (17func main() {18 log.SetFlags(log.LstdFlags | log.Lshortfile)19 log.Println("Hello, world")

Full Screen

Full Screen

Infof

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World")4 log.Printf("This is a log message")5}6import (7func main() {8 fmt.Println("Hello World")9 log.Fatal("This is a log message")10}11import (12func main() {13 fmt.Println("Hello World")14 log.Panic("This is a log message")15}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gauge automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful