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

Add an example how to log at different log levels #5

Closed
digulla opened this issue Sep 22, 2015 · 1 comment
Closed

Add an example how to log at different log levels #5

digulla opened this issue Sep 22, 2015 · 1 comment
Labels

Comments

@digulla
Copy link

digulla commented Sep 22, 2015

I thought this should work:

namespace app
Log.AddOutput app DEBUG
subject=info Log "Done"

but it logs at the defaut level (DEBUG) instead of INFO.

@niieani
Copy link
Owner

niieani commented Sep 22, 2015

subject variable is optional, it gives extra info to the logging function so you can identify and filter out or mark with color certain lines. It gives you more flexibility than logging levels traditionally do. If you'd like to imitate traditional logging levels you could do the following:

namespace app
Log.AddOutput DEBUG DEBUG
Log.AddOutput INFO INFO
Log.AddOutput WARN WARN

subject=DEBUG Log "Debugging"
subject=INFO Log "Done"
subject=WARN Log "Problem!"

...and so on. But you can do much more advanced things too, like filter by namespace or even specific function:

namespace app

# when logging with subject "test1" inside of namespace app use DEBUG:
Log.AddOutput app/test1 DEBUG
Log.AddOutput app/someFunction INFO

# will log "Debugging" to DEBUG
subject=test1 Log "Debugging" 

# will log everything within below function to INFO
someFunction() {
     Log "Done"
}

Take a look here for more info:
https://github.com/niieani/bash-oo-framework#advanced-logging

Play around with the tests file ./tests/logging.sh:
https://github.com/niieani/bash-oo-framework/blob/master/tests/logging.sh

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

No branches or pull requests

2 participants