itamarst / eliot

Eliot: the logging system that tells you *why* it happened
https://eliot.readthedocs.io
Apache License 2.0
1.1k stars 66 forks source link

Documentation has me confused on the basics. #434

Closed RoscoeTheDog closed 3 years ago

RoscoeTheDog commented 4 years ago

Hello. I am trying to migrate my project from basic logging to something more advanced and someone recommended this module through reddit. I have been through the quick-start guide and other available documentation and have some very basic questions about the API.

How can I parse the logs and format them for the stdout?

Is there a way to stream what's being written to the log, just like the standard logging module?

I know this should be relatively straightforward but the documentation shows eliot-tree being run through a terminal window instead of being used in native python code. Additionally when I tried the example parse function, it throws an exception saying there is no action type. Shouldn't the docs show an example that covers more than one case use?

The example functions load_messages() and parse() both take the variable logfile_path. Shouldn't this be unnecessary after already pointing to the log file with the to_file() function? Passing whatever load_messages() yields to parse() also does not work- presumably because the exception encountered earlier was because log action's were not configured in documentation's example.

I really want to like this module and I think it could be of great use to my I/O intensive project. However, the API has me confused and the docs don't seem to be noob friendly. I don't even see a clear-cut way of printing the logs without parsing it manually with the JSON module. Of course- I'm guessing that's what the Parser class is supposed to help with.

from eliot import *
from eliot.parse import Parser
import eliot
import eliottree
import json

# declare our file path as a variable
log_path = 'C:\\Users\\Aspen\\Google Drive\\1. Software Engineering\\GitHub\\Samplify\\samplify.log'

# point to file path
to_file(open(log_path, 'w+'))

# write a basic log message
Message.log(key='test message')

# load messages. Takes logpath *after* it's been pointed to??
def load_messages(logfile_path):
   for line in open(logfile_path):
       yield json.loads(line)

# parse messages. Takes logpath as well?
def parse(logfile_path):
    for task in Parser.parse_stream(load_messages(logfile_path)):
        print("Root action type is", task.root().action_type)

# run the functions
load_messages(log_path)
parse(log_path)  # error thrown here
itamarst commented 4 years ago

Would to_file(sys.stdout) do what you want?