Storing data in a variable is all fine and well, but it's not logging anything. Logging -> writing to persistent storage (on disk, shm, sqlite db in RAM, sending it over a network, etc)
Also, this will only log what is being typed within the context of a browser window and has no bearing on what users type in other applications.