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

Passing FileName and LineNumber (Issue #57) #60

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

indieSoftware
Copy link

Adds the possibility to have filename and line numbers added to the log message.

This implements the Feature Request Issue #57.

  • Added parameters and default values for file, function, line and column to all Logger's logging methods.
  • The source parameters are stored into a LogSource struct for easier passing.
  • The LogSource is passed to the LogWriter and LogModifier.
  • Provided a SourceModifier as an example and as a default modifier for adding the log's source to the message.
  • Added tests.
  • Adjusted the example project to show the SourceModifier in action.
  • Updated the readme to reflect the new method interfaces.

…logging methods. These parameters are packed into a LogSource struct and passed to the LogWriter and LogModifier. Provided a SourceModifier as a default modifier for adding the log's source to the message. Added tests for this feature, adjusted the example and updated the readme accordingly.
@rmnblm
Copy link

rmnblm commented Feb 19, 2020

Hi Guys

@cnoon This PR has been open for a long time and hasn't been merged yet. Why?
@indieSoftware Might there also be the possibility to add the object instead of the filename? You know, sometimes there are multiple small classes in a single file. 😅

Cheers
Roman

@indieSoftware
Copy link
Author

@indieSoftware Might there also be the possibility to add the object instead of the filename? You know, sometimes there are multiple small classes in a single file. 😅

Hi @rmnblm, if there are multiple classes in a single file, you're probably doing something wrong 😉

Anyway, as far as I know Swift only provides literals for getting the file, line, column, function and dsohandle. File and line should already be clear and clearly point to the logged location, so no need for an object's name. It's also quite unusual to force a reference to an object in logs, because that's only possible in run-time, while the file and column can already be prepared in compile-time. When using Swift purely as a functional programming language you won't even have an object you could provide.

If you really need to log an object's type name you first have to create the string out of it by yourself. You could do this via String(describing: type(of: myObject)) for example. However, this is kind of costly so I wouldn't recommend to do this all the time with each log call.

Cheers
Sven

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

Successfully merging this pull request may close these issues.

2 participants