https://github.com/alinz/react-native-logger
Async aware logger for react-native with grouping and filter feature
https://github.com/alinz/react-native-logger
async filter grouping logger react-native
Last synced: about 1 year ago
JSON representation
Async aware logger for react-native with grouping and filter feature
- Host: GitHub
- URL: https://github.com/alinz/react-native-logger
- Owner: alinz
- Created: 2016-01-21T18:15:30.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-04-15T21:42:55.000Z (about 9 years ago)
- Last Synced: 2025-04-10T00:43:22.963Z (about 1 year ago)
- Topics: async, filter, grouping, logger, react-native
- Language: JavaScript
- Homepage:
- Size: 4.39 MB
- Stars: 20
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# React-Native-Logger
Sync or Async Aware logger for react-native
This Project address couple of issues
- Simple to use
- Group logs
- Filter Logs by name
- Async aware
### Installation (NPM or Yarn)
```bash
npm install react-native-logger --save
```
```bash
yarn add react-native-logger
```
### Usage
```js
import { logger } from 'react-native-logger'
```
There are 3 functions.
#### log: (...args: Array) => void
similar to `console.log`. for example
``` js
logger.log('this is awesome', 10, 10)
// logs as
// this is awesome 10 10
```
#### group: (name: string, title: string, log: LogFn) => void
it accepts 3 arguments. `name` is an identifier which you can use in `setFilters`. `title` is a simple description about the log it self. and `log` is a function which your loggin happening. The signiture of LogFn is
```js
type LogFn: (log: (...args: Array) => void) => void | Promise
```
It basically group related logs into one. also you can return a promise which cause the logs waits until you tell it so.
```js
logger.group('api', 'loads users list', async (log) => {
const users = await apis.getAllUsers();
log('list of users', users);
actions.updateUsersList(users);
});
```
#### setFilters: (...names: Array): void
simply filters out everything except those names that you pass to logs. to clear the filter simply call it without arguments.
```js
logger.filters('api')
```
cheers,