/

User Identification

Associate logs with user identity for better debugging and monitoring. Track authenticated users and anonymous visitors across your application.

Setting User Identity

Authenticated Users

Java
import com.bytehide.logs.models.AuthUser;

AuthUser user = new AuthUser();
user.setId("usr_123");
user.setEmail("john@example.com");
user.setName("John Doe");
Log.setUser(user);

// All subsequent logs will include user information
Log.info("User performed action");

Anonymous Users

Java
Log.setUser(null);
Log.setAnonymousId("anon_visitor_456");
Log.info("Anonymous visitor action");

User Lifecycle

Login

Java
public void onLogin(String userId, String email, String name) {
    AuthUser user = new AuthUser();
    user.setId(userId);
    user.setEmail(email);
    user.setName(name);
    Log.setUser(user);
    
    Log.info("User authenticated");
}

Logout

Java
public void onLogout() {
    Log.info("User logging out");
    Log.setUser(null);
    Log.info("User logged out");
}

Combining with Other Features

Java
AuthUser user = new AuthUser();
user.setId("usr_123");
user.setEmail("john@example.com");
Log.setUser(user);

// User context is automatically included with all logs
Log.withTags("payment", "success")
   .withContext("orderId", "ORD-001")
   .info("Payment completed");

Privacy Best Practices

Privacy Considerations

  • Only include necessary user information
  • Use user IDs instead of full names when possible
  • Consider data masking for email addresses
  • Comply with GDPR/privacy regulations
  • Clear user identity on logout

Next Steps

Previous
Data Masking