# jounx

> A more useful console and/or file logging solution with colors

Latest version **1.2.5** (published 2020-05-30) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install jounx
pnpm add jounx
yarn add jounx
bun add jounx
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.5 |
| Published | 2020-05-30 |
| First published | 2020-05-03 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=12.13.0 |
| Dependencies | 8 |
| Unpacked size | 146.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Deryck Henson |
| Maintainers | lacoolj |
| Keywords | logging, logger, log, console, chalk |

## Links

- npm: https://www.npmjs.com/package/jounx
- Repository: https://github.com/topazjs/jounx
- Homepage: https://github.com/topazjs/jounx#readme
- Issues: https://github.com/topazjs/jounx/issues
- npm.io page: https://npm.io/package/jounx

## Dependencies (8)

- [chalk](https://npm.io/package/chalk.md) ^4.0.0
- [typescript](https://npm.io/package/typescript.md) ^3.9.2
- [@types/chai](https://npm.io/package/@types/chai.md) ^4.2.11
- [@types/node](https://npm.io/package/@types/node.md) ^14.0.1
- [@types/mocha](https://npm.io/package/@types/mocha.md) ^7.0.2
- [@types/eslint](https://npm.io/package/@types/eslint.md) ^6.8.0
- [@typescript-eslint/parser](https://npm.io/package/@typescript-eslint/parser.md) ^2.33.0
- [@typescript-eslint/eslint-plugin](https://npm.io/package/@typescript-eslint/eslint-plugin.md) ^2.33.0

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [@luma.gl/experimental](https://npm.io/package/@luma.gl/experimental.md) — 77.1K weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads

## Recent versions

- 1.2.5 (latest) — 2020-05-30
- 1.2.4 — 2020-05-17
- 1.2.3 — 2020-05-17
- 1.2.1 — 2020-05-17
- 1.2.0 — 2020-05-17
- 1.1.1 — 2020-05-16
- 1.0.4 — 2020-05-16
- 1.0.3 — 2020-05-09
- 1.0.1 — 2020-05-03
- 1.0.0 — 2020-05-03

## README

# jounx

## Reqz

- Node.js 12+ (cuz syntax)
- Linux (not really but if you're already doin stuff why not)
-

## Makes use of

- The amazing `chalk` library to make stuff pretty ([check it out](https://github.com/chalk/chalk))
- [TypeScript](https://www.typescriptlang.org/) throughout (finally - *but still kind of a work in progress for the moment*)
- [ESLint](https://eslint.org/) for the code stdz
- [Mocha](https://mochajs.org/) & [Chai](https://www.chaijs.com/) to make testing a little less terrible

### Random things

- Made in Ubuntu so I may have left some linux-specific stuff in the tests or other places.  Just upgrade to linux if you haven't already and nothin to worry about

## Usage

In your project's root directory, run:
```bash
yarn add jounx
# or
npm install --save jounx
```

In your app, import and initialize at the top:
```javascript
// import module
const { Logger } = require('jounx');

// grab an instance
const logger = new Jounx();

// ...or include an options object (see below)
const logger = new Jounx({ "enableLogFile": true, "prefixWithDateTime": false });

/**
 * Log a simple message
 */
logger.info(`Sweet`);

/** 
 * Or multiple messages in a row
 */
logger.info(`First`, `Then the second`, `Annnnd on and on`); // , ..., ..., etc

/** 
 * Error messages
 */
logger.error(`Could not connect to Google`, { "aBunchOfInfo": `About some stuff` });

/**
 * Debug - doesnt really do anything but will use console.trace() if the `dev`
 * option is `true`.  Also will continue to log to its own file even without `dev`
 */
logger.debug(`Let's investigate`, new Error(`Might as well quit`));
```

### Options

```javascript
{
    /**
     * Controls if user is shown the output for Logger.debug() in console or not (enabling log 
     * files will write either way)
     */
    "dev": $NODE_ENV === `development`,

    /**
     * Enables log file to be written while app is running
     */
    "enableLogFile": false,

    /**
     * Determines which method to use for writing the log to the
     * filesystem.
     *  - writeFileAsync - async file write using fs.appendFile
     * *experimental*
     *  - writeFileStream - keep file stream open and pipe new writes on demand
     */
    "fileWriteMode": "writeFileAsync",

    "logFilename": "info.log",

    /**
     * Directory to store the log files if `enableLogFile` is `true`
     *
     * - absolute path
     *  "/var/log/www"
     *
     * - relative path
     *  "../../home/my-logs"
     *
     * - empty path will use current working directory
     *  path.join(__dirname, ".")
     *  path.join(__dirname, "./logs")
     *
     */
    "logDirectory": "./logs",

    /**
     * Pretty much the main point of this lib but maybe you don't want
     * words in your terminal and here's how to stop em
     */
    "enableConsole": true,

    /**
     * *experimental*
     * Max amount of text that will attempt to fit on one line before a line break
     * is inserted
     */
    "consoleMaxWidth": [width of terminal window or 120 if unavailable],

    /**
     * *experimental*
     * Put the prefix info (date/time, PID, etc) on its own line above the
     * primary (first argument provided to one of the loggers) message.
     *
     * - "as-needed" tries to do it only if the prefix info is more than half the 
     *   terminal width
     * 
     * **Only affects console output - file primary messages will remain on the same line as prefix**
     */
    "consoleMultiLine": `always`, // or `never` or `as-needed`

    /**
     * The message will be prepended with a locale-formatted datetime
     */
    "prefixWithDateTime": true,

    /**
     * All-caps notifier of what type of message is being logged
     */
    "prefixWithMessageType": true,

    /**
     * Process ID in system
     */
    "pidPrefix": String(process.pid),

    /**
     * Port the server is bound to - ... or whatever data you want it to be lol
     */
    "portPrefix": ``,

    /**
     * Ways to customize the appearance in the console for each type of data piece
     * Each item in the array needs to be a valid chalk instance method.
     * 
     * const chalk = require('chalk');
     * const consoleChalk = new chalk.Instance({ 'level': 3 });
     * 
     * const coloredText = consoleChalk.[COLOR].[STYLE].[BGCOLOR]
     * 
     * Bold, red text on a black background:
     *  - consoleChalk.red.bgBlack.bold('Hello, world!');
     * 
     * For these options, that would be equivalent to:
     * "xyzFormat": [ `red`, `bgBlack`, `bold` ]
     * 
     * See more at the [chalk site](https://github.com/chalk/chalk)
     * 
     * **Complex combinations like using chalk.rgb(200, 100, 255) are not supported yet**
     */
    "labelFormat": [ `bold` ],

    "pidFormat": [ `white` ],

    "portFormat": [ `bold` ],

    "dateFormat": [ `grey` ],

    "timeFormat": [ `yellow` ],

    "timerFormat": [ `green`, `inverse` ],

    "infoMessageFormat": [ `blueBright` ],

    "infoSecondaryFormat": [ `whiteBright` ],

    "errorMessageFormat": [ `bold`, `redBright` ],

    "errorSecondaryFormat": [ `yellowBright` ],

    "debugMessageFormat": [ `cyanBright` ],

    "debugSecondaryFormat": [ `whiteBright` ],
}
```

## Development

- Set it up

```bash
npm install
```

- Write some code...
- etc.

- Lint it

```bash
npm run lint:test
# or to auto-fix what can be fixed
npm run lint:fix
```

- Test it

```bash
npm test
```

---
_Source: https://npm.io/package/jounx · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
