Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API question] Printing logs to stdout #45

Closed
felix91gr opened this issue May 25, 2018 · 8 comments
Closed

[API question] Printing logs to stdout #45

felix91gr opened this issue May 25, 2018 · 8 comments

Comments

@felix91gr
Copy link

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
Copy link
Owner

tonystone commented May 26, 2018

@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
Copy link
Author

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

@felix91gr
Copy link
Author

felix91gr commented May 26, 2018

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 👍

@tonystone
Copy link
Owner

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
Copy link
Owner

tonystone commented May 26, 2018

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
Copy link
Author

So as I expected it was the async nature of TraceLog

It was indeed! now it works flawlessly :')

@felix91gr
Copy link
Author

Btw, maybe rename it to tracelog-usage

It is done :)

@felix91gr felix91gr reopened this May 26, 2018
@felix91gr
Copy link
Author

I should write something before closing the issue:

  • Issue was resolved by using Foundation.sleep. The problem was that the call was asyncronous and I didn't realize. I was waiting for logs to happen before the program went on. Apart from that, the API was used allright :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants