Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/oyvinev/log.sh

Logging library for Bash
https://github.com/oyvinev/log.sh

Last synced: 15 days ago
JSON representation

Logging library for Bash

Awesome Lists containing this project

README

        

log.sh
======

**log.sh** is a Bash library for easy logging with preset configurations.

Installation
------------

make install

You can also use `PREFIX=$HOME` to install `log.sh` to `~/bin`, or any other location.

Example
-------

Please run the `example.sh`, the following screenshot was taken from the output of version 0.1.

![Screenshot from v0.1 example.sh](http://1.bp.blogspot.com/-C4ina8EsnG8/Tx11fpAzEcI/AAAAAAAAC_Y/_-9WjbSOZgs/s1600/2012-01-23--22%253A51%253A57.png)

Usage
-----

source /path/to/log.sh
# You are good to go
LSERROR Test error message
# or you can pipe the message
echo Test error message via pipe | LSERROR

### Logging levels

LS_DEBUG_LEVEL=10
LS_INFO_LEVEL=20
LS_WARNING_LEVEL=30
LS_ERROR_LEVEL=40
LS_CRITICAL_LEVEL=50

The default logging level is `LS_WARNING_LEVEL` and the value is stored at `LS_LEVEL`. If you need debug or info message, set `LS_LEVEL` to them.

### Default levels logging functions

LSDEBUG
LSINFO
LSWARNING
LSERROR
LSCRITICAL

All arguments supplied to these function are treated as the message. There is also a general logging function `LSLOG`:

LSLOG 35 A message for level 35

The first parameter is the level. You do not need to use preset levels actually, as long as the level is equal to or greater than `LS_LEVEL`, the message will be printed out.

### Changing the output target

The default `LS_OUTPUT` is set to `/dev/stdout`, you can change it to `/dev/stderr` or any filename. Note that, it overwrites the file.

Support
-------

Please use Issues to request features or to report bugs.

Help
----

This library is relatively new and many things may not be considered by mistakes, please feel free to fork it and improve it, then open pull requests. Anything, coding, examples, documentations, ideas, even typo fixing are all welcome.

License
-------

**log.sh** is licensed under the MIT License, please see COPYING.

Copyright (c) 2012 Yu-Jie Lin