Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/leomp12/console-files
Simple package to handle console output to files
https://github.com/leomp12/console-files
error-log javascript-console js-logger log-files node-debug nodejs-console
Last synced: about 2 months ago
JSON representation
Simple package to handle console output to files
- Host: GitHub
- URL: https://github.com/leomp12/console-files
- Owner: leomp12
- License: mit
- Created: 2018-11-10T00:52:03.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-03T05:02:20.000Z (almost 2 years ago)
- Last Synced: 2024-10-12T07:32:10.998Z (3 months ago)
- Topics: error-log, javascript-console, js-logger, log-files, node-debug, nodejs-console
- Language: JavaScript
- Homepage:
- Size: 172 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# console-files
Simple Node.js package to write application outputs to files.
It works as a default JavaScript
[`Console`](https://developer.mozilla.org/en-US/docs/Web/API/Console) object,
but with special handlers for `.log` and `.error` methods,
saving output to configured files.It also treats application fatal errors
(`uncaughtException`), appending error message to file
before exiting process.## Using
```bash
npm i --save console-files
``````js
const logger = require('console-files')/*
Do the stuff
*/logger.log('Hello console-files!')
/*
More work to do
*/logger.error(new Error('Keep calm, it is just a test ;)'))
```## Configuration
It's configurable through the following
environment variables:Environment variable | Method | Default
--- | --- | ---
`LOGGER_OUTPUT` | `.log` | `./logger.out`
`LOGGER_ERRORS` | `.error` | `./logger.err`
`LOGGER_FATAL_ERRORS` | - | `./_stderr`
`LOGGER_SKIP_FATAL` | - | -## Development and production
`console-files` checks the `NODE_ENV`
to work differently for production and development modes:```js
const devMode = process.env.NODE_ENV !== 'production'
```- On dev mode it'll output to default console,
unless the `LOGGER_OUTPUT` or `LOGGER_FATAL_ERRORS`
env variable is explicitly set;- On production mode it'll output only to files;