Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lindsaykwardell/consoleback
Improved logging for Javascript applications
https://github.com/lindsaykwardell/consoleback
Last synced: about 2 months ago
JSON representation
Improved logging for Javascript applications
- Host: GitHub
- URL: https://github.com/lindsaykwardell/consoleback
- Owner: lindsaykwardell
- License: mit
- Created: 2019-10-01T20:29:03.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-03-04T19:32:27.000Z (almost 3 years ago)
- Last Synced: 2024-11-17T11:56:34.196Z (2 months ago)
- Language: TypeScript
- Size: 125 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# consoleback
### **Improved logging for Javascript applications**
- Uses console.log, console.warn, console.error, console.info, and console.debug
- Adds timestamp and log type to message (if desired)
- Time formatted to a local string with date-fns
- Allows callback that gives the application access to the log.## Usage
```javascript
// ES6
import consoleback from "consoleback";// CommonJS
const consoleback = require("consoleback");// Usage
consoleback()// All logs are now captured by consoleback
consoleback: (opts?: {
callback?: (type: string, message: any, ...optionalParams: any[]) => void;
showMsgType?: boolean;
showTime?: boolean;
}) => terminateterminate: () => void
```
All options are optional.`callback?: (type: string, message: any, ...optionalParams: any[]) => void;`
The callback that will provide the logged data.
- type: The type of log (log, warn, error)
- message/optionalParams: The logged information`showMsgType?: boolean;`
Whether to show a message type or not (defaults to true)
When true, [ LOG ], [ WRN ], or [ ERR ] will appear appended to the start of each log.
`showTime?: boolean;`
Whether to show time information (defaults to false)
`terminate: () => void`
Restores normal logging.
## Example
```javascript
const terminateLog = consoleback({
callback: (type, message, optionalParams) => {
// Perform actions on logged messages
},
showMsgType: true,
showTime: true
})console.log("The time is...");
// [ 2019-10-01T20:38:04.586Z ] [ LOG ] The time is...
terminateLog();
console.log("Goodbye!");// Goodbye!
```
## License
This project is MIT Licensed.