I found a nice Perl script to log every IRC message in Irssi. To set it up:

$ cd ~/.irssi/scripts
$ wget https://scripts.irssi.org/scripts/irssi_logger.pl
$ ln -s $PWD/irssi_logger.pl autorun/irssi_logger.pl
$ cpan -T DBI DBD::Pg

It will log irssi messages in a Postgres database (the name of the database can be tweaked in irssi_logger.pl). Now I can do:

$ psql -c "select channel,nick,log from logs"

channel | nick  |                         log
##C     | user1 | user2: how do you mean? you can get a gcc version ...
##C     | user2 | user1 i mean libc shipped with windows
##C     | user3 | If I want to lock on Windows I may do LockFile(fileno(f)
#ruby   | user4 | hi
##C     | user1 | there's this http://plibc.sourceforge.net/ it seems rathe...
##C     | user1 | or you could just go cygwin