mcpcpc / kirc

A tiny IRC client written in POSIX C99.

Home Page:https://mcpcpc.github.io/kirc/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

On logging

097115 opened this issue · comments

When using -o option, kirc seems to handle line breaks in a strange way: it inserts ^M followed by an empty line, like this (the log file opened in Vim):

line-breaks

Is this an intended behaviour? :)

v0.2.2 running on Linux.

Each line from the raw IRC stream is terminated by a carriage return and a line feed character (frequently referred to as CR-LF). kirc prints the entire line from the stream without modifying it, including CR-LF. In vim, the ^M character is the carriage return character by default. So printing this character is intended behavior.

In most practical applications for output logging, the raw steam data will be parsed/modified; therefore, printing this character will cause little interference to the end-user. I am open to removing these characters though if you have particular example application in mind where this would cause problems. There also appears to to be a duplicate line feed (causing the blank line between printed lines), which can be fixed by removing the one also printed by the fprintf() function:

kirc/kirc.c

Line 397 in 9370902

fprintf(out, "%s\n", str);

If you need a quick short-term solution though to remove the ^M character, you can always use the following vim command (note that the ^M character below is inserted using Ctrl+V Ctrl+M):

:s^M$//

Hope this information helps.

There also appears to to be a duplicate line feed (causing the blank line between printed lines), which can be fixed by removing the one also printed by the fprintf() function:

kirc/kirc.c

Line 397 in 9370902

fprintf(out, "%s\n", str);

I think this change should be implemented, since IRC commands already end with a newline. Plus, if someone is trying to use the log to debug an IRC command that does not end with a newline, they may think that it does since the print statement appends one, which could lead to problems.

The extra new line feed has been removed per #96.

I think it makes sense to leave the CR-LF for the same argument you made above regarding debugging (since it is “expected” per the IRC protocol). I will merge the PR sometime tomorrow (after i have had a chance to consider a few additional changes) and 0.2.3 tarballs will be made available.

@mcpcpc Thanks for the info!

And while we are here, one more thought: may be the log entries should also contain timestamps, what do you think? When browsing a log from time to time to check for the missed conversations, timestamps could help to understand where exactly are we right now... (I'm sort of trying to use the log file as you've suggested, grepping for #channel PRIVMSGs).

@mcpcpc Thanks for the info!

And while we are here, one more thought: may be the log entries should also contain timestamps, what do you think? When browsing a log from time to time to check for the missed conversations, timestamps could help to understand where exactly are we right now... (I'm sort of trying to use the log file as you've suggested, grepping for #channel PRIVMSGs).

I was wondering when someone was going to request this. lol. Added per 20a7e3b and will be released with 0.2.3 later today.

Format will be as such:

[WEEKDAY] [MONTH] [HH:MM:SS] [YEAR]:[IRC RAW MESSAGE][CR-LF]

For example:

Fri Dec 18 13:34:55 2020::moon.freenode.net 372 kirc :- Thank you for using freenode!

:)

Thanks!