tonystone / tracelog

TraceLog is a highly configurable, flexible, portable, and simple to use debug logging system for Swift and Objective-C applications running on Linux, macOS, iOS, watchOS, and tvOS.
https://tonystone.io/tracelog
Apache License 2.0
53 stars 15 forks source link

[API question] Printing logs to `stdout` #45

Closed felix91gr closed 6 years ago

felix91gr commented 6 years ago

Hi again :)

Not wanting to clutter up #44 unnecessarily, I've opened this issue.

I'm learning the basics of TraceLog by writing a Swift script. So far, it compiles, but I can't seem to be able to print the logs to stdout and I don't really know why. Here's what I have so far. I must be missing a config step or something?

Thanks :)

tonystone commented 6 years ago

@felix91gr, do you have a project file you can point me to? Trying to figure out how this is executed and packaged. Btw, I don't see anything obvious from the gist.

Remember that currently TraceLog is asynchronous so there is a possibility that the message did not have a chance to print before the script finished.

felix91gr commented 6 years ago

Yes, I'll upload it to github. Gimme a couple of minutes :)

felix91gr commented 6 years ago

Here it is

Sorry for the name, but I was thinking of offering it to you as a TraceLog showcase project after I figured out how to use it :) The idea would be to show the most common use cases of the library.

If you want me to, I can change the name np :+1:

tonystone commented 6 years ago

So as I expected it was the async nature of TraceLog. Try this (and I know it is not the right solution but it will show the issue with a script):

import Foundation
import TraceLog

TraceLog.configure(writers: [ConsoleWriter()], environment: ["LOG_ALL": "TRACE4"])

print("Hello!")

for _ in 0..<100 {
    logError { "Hey, I'm logging stuff! :D" }
}

print("Goodbye!")

sleep(20)

So it would be very easy to add a sync mode for script usage.

tonystone commented 6 years ago

Btw, maybe rename it to tracelog-usage so it matches other modules and repos that I may create for it. Also may be easier to find it looking for tracelog specifically

felix91gr commented 6 years ago

So as I expected it was the async nature of TraceLog

It was indeed! now it works flawlessly :')

felix91gr commented 6 years ago

Btw, maybe rename it to tracelog-usage

It is done :)

felix91gr commented 6 years ago

I should write something before closing the issue: