ID:1643643
 
(See the best response by Zecronious.)
How would you keep a log of everything that is displayed in the output window without having to go back and find all world << instances and adding something after it to add to a log file?

It should work even when there are no players present.
You could... winget() the text from the output, but I really don't recommend that -- probably best to do what you said and append the code to log things manually.
Best response
You can easily do this. BYOND makes logging very easy.

All you need is a logChat(message) proc and use it wherever output is created that you want to log.

#define CHAT_LOG "chatlog.txt"

mob
Login()
..()

verb
say(message as text)

// Remember to check here if the message is okay. Not too long etc.

chat(message)
logChat(message)

proc
chat(message as text)
for(var/client/C)
if(C.mob)
C.mob << message

proc
logChat(message as text)
text2file(message, CHAT_LOG)
In response to Zecronious
Zecronious wrote:
You can easily do this. BYOND makes logging very easy.

All you need is a logChat(message) proc and use it wherever output is created that you want to log.

> #define CHAT_LOG "chatlog.txt"
>
> mob
> Login()
> ..()
>
> verb
> say(message as text)
>
> // Remember to check here if the message is okay. Not too long etc.
>
> chat(message)
> logChat(message)
>
> proc
> chat(message as text)
> for(var/client/C)
> if(C.mob)
> C.mob << message
>
> proc
> logChat(message as text)
> text2file(message, CHAT_LOG)
>


This is exactly what I did "not" want to do.
In response to Nadrew
Nadrew wrote:
You could... winget() the text from the output, but I really don't recommend that -- probably best to do what you said and append the code to log things manually.

I was hoping I wouldn't have to. I was thinking about wingetting the text and if it's different than the previous text, append the last line. But, that'd be inefficient since you'll be checking for winget multiple times. :/ I guess there's no being lazy this time.
In response to Xirre
Using world << "text" is foolish for two reasons.

1. It's hard to log.
2. It sends messages to things that can't utilize the message.

Instead using the code I posted edited to be better you only ever need to write logChat() once.

ONCE.

From this point on stop using world << "text" and start using chat("text").

Do the smart guy thing :)

#define CHAT_LOG "chatlog.txt"

mob
Login()
..()

verb
say(message as text)

// Remember to check here if the message is okay. Not too long etc.

chat(message)

proc
chat(message as text)

logChat(message)

for(var/client/C)
if(C.mob)
C.mob << message

proc
logChat(message as text)
text2file(message, CHAT_LOG)
Just for reference, using "world <<" doesn't actually output to things that would never be able to utilize said output (non-clients), the << output operator is smart enough to handle that. It's actually faster to use "world <<" than it is to use "view() <<" and the sort due to the lack of intensive calculations being done. However, the idea of not using it is absolutely correct, getting rid of it allows you finer control over how things get outputted.

You can remove the need to loop entirely by keeping a list of clients and using << to output to that.

var/list/clients = list()

client
New()
..()
clients += src
Del()
clients -= src // Redundant since deleting the client would do this too, but just in case.
..()

mob/proc
chat(message)
clients << message
logChat(message)

logChat(message)
if(!message) return
text2file(message,CHAT_LOG)


You also don't really need to output to client.mob, outputting to the client itself does the same thing without having to access their mob at all.
Why keep a list of clients when BYOND internally keeps a list and loops through that?

Seems like the same thing. When you output to a list you're just hiding the fact that you're really doing a loop through that list anyway.

Yeah if client << message works then that's better.
It's not actually looping over the list, at least not in the way you are -- remember, any time you can use an internal method of doing something you should do it, it'll almost always work better than a soft-coded version of the same thing.
That's because soft coded things can sometimes be redundant since it's pretty much made up of the internal methods. I just wish there was a way to override world << and add a log message. Just so I could be lazy for the heck of it.