Simple Logger(Console and file) for Swift

Simple Logger(Console and file) for Swift.

When things are simple and easy to use then everyone uses it

Yogesh Bhople

--

When we think about logger then one think come to mind is “print” statement. It is very powerful. Let us see How?

Features -

1. You can have different level for log DEBUG,INFO,ERROR,EXCEPTION,WARNING

2. You can configure it for DEBUG, RELEASE or any configurations

3. You can configure statements for console logging.

4. You can use file logger.

5. You can configure statements for file logger.

6. you can configure timestamp, filename, function name and line to be added or not

Why to use this logger? because you don’t need to spend time to understand How to use it if you are aware of how to use “print”

How to use ?

just use print statement with different log levels.

Print function is very powerful

You can pass any object to print not only strings.

then use that powerful feature with with this logger.

You can pass many arguments to print so use it with print.

Console Output

Configure debug, info, error.. Statements

But now you might be thinking that all debug, info, error..etc are not needed in release, debug or any configuration. Then configure it as follow -

Configure timestamp, filename, function name and line to be added or not

Output

File Logging

Now let us see How we can use same logger for file logging.

Configure which statements should be added in file logging. And that’s it.

The amazing feature is it will create separate log files for each day.

/Users/…/Library/Developer/CoreSimulator/Devices/3A6B7665–9838–4E89–87A2–6DAEBAE09861/data/Containers/Data/Application/B03E2ECA-1C18–4B78-A97D-CD01E0041A36/Documents/20170723YBLogger.txt

Find the full source code on github.

If you can add some more exciting features or any improvement, you are welcome. Please fill free to add in git repo.

--

--