1.0.0 • Published 1 year ago

logion v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Logion

Install

Install via yarn add logion | npm install logion.

Usage

Create instance:

import Logion from 'logion';

const logger = new Logion(opts);

Logion comes with an easy to use composable API that supports chaining:

logger
  .text('Hello World!')
  .newline(2)
  .text('Good job', 'success')
  .separate()
  .line('One liner')
  .spinner('oh', 'Beatifull spinner');

API

logion

module.exports ⏏

Class representing a logger.

Kind: Exported member

module.exports.Logion

Class representing a logger.

Kind: static class of module.exports

new exports.Logion(options)

Create a logger.

Returns: Instance - a logger instance.

ParamTypeDefaultDescription
optionsobjectOptions object.
options.streamInobjectprocess.stdinInput stream (for scrolling and shortcuts).
options.streamOutobjectprocess.stdoutOutput stream.
options.disabledbooleanautoIs logger disabled (no logging). By default, disabled if not ran in TTY.
options.pausedbooleanfalseIs logger paused (not outputting to console and not listening for key presses, but still collecting logs).
options.renderIntervalnumber80Render interval in ms to update spinners.
options.spinnerColorcolorwhiteSpinner char color.
options.spinnerIndentnumber0Spinner indent length in text chars.
options.spinnerFramesArray.<string>"", "", "", "", "", "", "", "", "", ""Spinner frames characters.
options.spinnerDoneCharstring""Char to replace spinner after it is done (when calling spinnerDone).
options.spinnerDoneAllCharstring""Char to replace active spinners after they are done (when calling spinnerDoneAll).
options.spinnerFormatDonefunction(str) => strCall this function to format the spinner text after it is done, see spinnerFormatDone.

logion.width ⇒ number

Width of a console.

Kind: instance property of Logion
Returns: number - width in chars.
Read only: true

logion.height ⇒ number

Height of a console.

Kind: instance property of Logion
Returns: number - height in chars.
Read only: true

logion.disabled ⇒ boolean

Returns true if a logger is disabled.

Kind: instance property of Logion
Returns: boolean - is disabled.
Read only: true

logion.paused ⇒ boolean

Returns true if a logger is paused.

Kind: instance property of Logion
Returns: boolean - is paused.
Read only: true

logion.styleNames ⇒ object

Shortening style names enum. See Available style names

Kind: instance property of Logion
Returns: object - style names enum.
Read only: true

logion.newline(num, force, identifier) ⇒ Instance

Output a newline(s). Accommodates if line breaks have been used before.

Kind: instance method of Logion
Returns: Instance - a logger instance.

ParamTypeDefaultDescription
numnumber1Number of new lines to output.
forcebooleanfalseDo not accommodate for previous lines.
identifierstring"$random"Identifier for this log message (should be unique).

logion.indent(num, identifier) ⇒ Instance

Output spaces. Can be used in the middle of a line.

Kind: instance method of Logion
Returns: Instance - a logger instance.

ParamTypeDefaultDescription
numnumber2Number of spaces to output.
identifierstring"$random"Identifier for this log message (should be unique).

logion.separate(color, char, identifier) ⇒ Instance

Output a separator on a new line. It fills all the available width.

Kind: instance method of Logion
Returns: Instance - a logger instance.

ParamTypeDefaultDescription
colorcolorgreyA separator character's color.
charstring"-"Character that make up the separator.
identifierstring"$random"Identifier for this log message (should be unique).

logion.text(string, styles, identifier) ⇒ Instance

Output a text with stlies applied. Does not add a new line.

Kind: instance method of Logion
Returns: Instance - a logger instance.

ParamTypeDefaultDescription
stringstring"$space"Text to output.
stylesobject | styleNameStyle object or styleName string.
styles.colorcolorText color (uses Chalk module color).
styles.bgColorcolorBackground color (uses Chalk color).
styles.boldbooleanfalseOutput as bold.
styles.underlinebooleanfalseOutput as underlined.
styles.italicbooleanfalseOutput as italic.
styles.strikethroughbooleanfalseOutput as strike-through.
identifierstring"$random"Identifier for this log message (should be unique).

logion.style(string, styles, identifier) ⇒ string

Style a text string. Shortening names could be one of: "success", "error", "info", "bold", "underline", "italic", "strikethrough".

Kind: instance method of Logion
Returns: string - a styled string (with escape codes).

ParamTypeDefaultDescription
stringstringText to style.
stylesobject | styleNameStyle object or styleName string.
styles.colorcolorText color (uses Chalk module color).
styles.bgColorcolorBackground color (uses Chalk color).
styles.boldbooleanfalseOutput as bold.
styles.underlinebooleanfalseOutput as underlined.
styles.italicbooleanfalseOutput as italic.
styles.strikethroughbooleanfalseOutput as strike-through.
identifierstring"$random"Identifier for this log message (should be unique).

logion.styleReset(string) ⇒ string

Reset all styles for a string.

Kind: instance method of Logion
Returns: string - an unstyled string.

ParamTypeDescription
stringstringString with styled text.

logion.line(string, styles, indt) ⇒ Instance

Output a line of a text with an indent.

Kind: instance method of Logion
Returns: Instance - a logger instance.

ParamTypeDefaultDescription
stringstring"$space"Your text.
stylesobject | stringStyle object or shortening name (as string), same as style.
styles.colorcolorText color (uses Chalk module color).
styles.bgColorcolorBackground color (uses Chalk color).
styles.boldbooleanfalseOutput as bold.
styles.underlinebooleanfalseOutput as underlined.
styles.italicbooleanfalseOutput as italic.
styles.strikethroughbooleanfalseOutput as strike-through.
indtnumber0Line indentation, a number of spaces to output before the text.

logion.clear() ⇒ Instance

Clear all the output.

Kind: instance method of Logion
Returns: Instance - a logger instance.

logion.spinner(identifier, text, config) ⇒ Instance

Create a spinner on a new line. You can mark a spinner as done using its identifier with spinnerDone.

Kind: instance method of Logion
Returns: Instance - a logger instance.

ParamTypeDefaultDescription
identifierstringIdentifier for this spinner (required, should be unique).
textstringText to output after this spinner (on the same line).
configobjectAn object for configuring this spinner.
config.colorcolorwhiteSpinner char color (uses Chalk module color).
config.indentnumber0Amount of spaces to output before this spinner.

logion.spinnerDone(identifier, config) ⇒ Instance

Mark the spinner as done. If text is not provided, uses spinnerFormatDone to format the original text.

Kind: instance method of Logion
Returns: Instance - a logger instance.

ParamTypeDefaultDescription
identifierstringIdentifier for the spinner (previously used to create the spinner in spinner).
configobjectAn object for configuring this spinner.
config.textstringA new text for this spinner (if empty, leaves the original text).
config.colorcolorA new spinner char color (if empty, uses the original color).
config.charstring""A character which replaces the spinner.

logion.spinnerDoneAll(config) ⇒ Instance

Mark all spinners that are not already done as done. Uses spinnerFormatDone to format the original text.

Kind: instance method of Logion
Returns: Instance - a logger instance.

ParamTypeDefaultDescription
configobjectAn object for configuring this spinner.
config.colorcolorA new spinner char color (if empty, uses the original color).
config.charstring""A character which replaces the spinner.

logion.beep() ⇒ Instance

Make a beep sound. May not be played in some consoles.

Kind: instance method of Logion
Returns: Instance - a logger instance.

logion.waitInteraction(text, config) ⇒ Promise.<Instance>

Output a special spinner and waits for a user interaction. Removes the spinner after interaction and resolves a Promise.

Kind: instance method of Logion
Returns: Promise.<Instance> - a promise which resolves after user interaction (resolver returns a logger instance).

ParamTypeDefaultDescription
textstring"Press any key to continue"Text for the spinner
configobjectAn object for configuring the spinner, see spinner.

logion.log(string, identifier) ⇒ Instance

Log a row string. Other methods use this under the hood.

Kind: instance method of Logion
Returns: Instance - a logger instance.

ParamTypeDefaultDescription
stringstringString to output.
identifierstring"$random"Identifier for this log message (should be unique).

logion.removeLog(identifier) ⇒ Instance

Remove a log message with the corresponding identifier.

Kind: instance method of Logion
Returns: Instance - a logger instance.

ParamTypeDescription
identifierstringIdentifier for the log message (used to create it in other methods).

logion.enable() ⇒ Instance

Enable a logger.

Kind: instance method of Logion
Returns: Instance - a logger instance.

logion.disable() ⇒ Instance

Disable a logger. When disabled, it removes all listeners, resets screen buffer, and clears all logs.

Kind: instance method of Logion
Returns: Instance - a logger instance.

logion.resume() ⇒ Instance

Update the console with the last messages, resume spinners and listen for user interactions. Use this after pause.

Kind: instance method of Logion
Returns: Instance - a logger instance.

logion.pause() ⇒ Instance

Pause all logging, remove all listeners. Use this to temporary output something outside a logger instance, or to release a process from events listening (by logion).

Kind: instance method of Logion
Returns: Instance - a logger instance.

module.exports~Instance : object

A logger instance.

Kind: inner typedef of module.exports

module.exports~styleName : "success" | "error" | "info" | "bold" | "underline" | "italic" | "strikethrough"

Available style names.

Kind: inner typedef of module.exports

module.exports~color : "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "blackBright" | "redBright" | "greenBright" | "yellowBright" | "blueBright" | "magentaBright" | "cyanBright" | "whiteBright"

Supported color names.

Kind: inner typedef of module.exports

module.exports~spinnerFormatDone ⇒ string

Format the spinner text when it is marked as done.

Kind: inner typedef of module.exports
Returns: string - a formated spinner text.

TypeDescription
stringCurrent spinner text.

TODO

  • Add more tests.
  • Add a help message for scrolling and document it.
  • Add more text style (colors) variants.
  • Fix flickering and rerender screen only if needed.