0.3.2 • Published 2 years ago

@appku/stashku-log v0.3.2

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
2 years ago

StashKu Log Middleware

This StashKu middleware project provides logging to console and/or to a rolling file directory. It provides support for the various severities of StashKu logging: error, warn, info, and debug.

StashKu Log can also be used independently, without StashKu to simply log in a standardized way that enforces severity level logging (no console.log generalities).

This package supports 2 modes of logging, each can be enabled/disabled and configured independently of one another:

  • "console": Outputs logs to stdout (usually to the terminal). This logger is enabled by default.
  • "file": Writes logs to a log file on a file-system. Currently under development.

Getting Started

npm i --save @appku/stashku-log

To utilize this middleware with stashku, this middleware can be passed to StashKu through the configuration to provide functionality.

import log from '@appku/stashku-log';
let stash = new StashKu({
    middleware: [log],
    '@appku/stashku-log': {
        console: {
            enabled: true,
            severity: 'info',
            colors: true,
            timestamp: true,
            local: true
        },
        file: {
            enabled: false
            path: './'
        }
    }
});

Code Quick-Start

You should utilize your StashKu instance's log property to make logs function calls. In the absence of StashKu, you can make log calls directly with this library:

Within StashKu

let stash = new StashKu( ... ); ///see Configuration section below
stash.log.debug('Look ma! I am debugging.');
stash.log.info('Look ma! I am pretty.');
stash.log.warn('Look ma! I am smoking.');
stash.log.error('Look ma! I am on fire.');

Without StashKu

import log from '@appku/stashku-log';
log.debug('Look ma! I am debugging.');
log.info('Look ma! I am pretty.');
log.warn('Look ma! I am smoking.');
log.error('Look ma! I am on fire.');

Loading After StashKu Initialization

Alternatively, if not loaded by configuration of the StashKu middleware property (as shown above), you can use StashKu's use middleware function:

import log from '@appku/stashku-log';
myStashKuInst.use(log);
...

Without StashKu

If you are using the stashku-log without StashKu, you can still configure the module, as shown below:

import log from '@appku/stashku-log';
//set the configuration object on the module directly
log.config = { 
    console: { ... }, 
    file: { ... }
}
...

To configure the library without StashKu, set the config property on the module or use environmental variables.

Documentation

Formal documentation is available here.

Available Configuration Properties

PropertyENVTypeDefault
consoleObject
↳ console.enabledSTASHKU_LOG_CONSOLE_ENABLEDBooleantrue
↳ console.severitySTASHKU_LOG_CONSOLE_SEVERITYString
↳ console.timestampSTASHKU_LOG_CONSOLE_TIMESTAMPBooleantrue
↳ console.localSTASHKU_LOG_CONSOLE_LOCALBooleantrue
↳ console.colorsSTASHKU_LOG_CONSOLE_COLORSBooleantrue
fileObject
↳ file.enabledSTASHKU_LOG_FILE_ENABLEDBooleanfalse

You can utilize environmental variables or define the values through a configuration object passed to StashKu. This project also loads .env files in it's package directory.

Running

Run npm start

Building

This project uses node.js to run and does not have an explicit build process.

Code Documentation

You can generate a static JSDoc site under the docs/ path using the command npm run docs.

Testing

This project uses jest to perform unit tests.

Running Tests

Run npm test to run jest unit tests.

Run npm run lint to run ESLint, optionally install the Visual Studio Code ESLint extension to have linting issues show in your "Problems" tab and be highlighted.

If you are writing unit tests, you may need to npm install @types/jest to get intellisense in Visual Studio Code if for some reason it did not get installed.

Publishing

Only maintainers with proper access can publish this package to npm. To do so as maintainers, you can publish by running the following command:

npm publish --registry=https://registry.npmjs.org --access=public
0.3.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.2.2

2 years ago

0.1.11

2 years ago

0.1.10

3 years ago

0.1.8

3 years ago

0.1.9

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago