All Projects → ivanseidel → Node Draftlog

ivanseidel / Node Draftlog

Licence: mit
📜 Create updatable log lines into the terminal, and give life to your logs!

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Node Draftlog

Console Logging
Better, prettier commandline logging for Python--with colors! 👻
Stars: ✭ 111 (-90.06%)
Mutual labels:  console, logging
Clog
Package clog is a channel-based logging package for Go
Stars: ✭ 151 (-86.48%)
Mutual labels:  console, logging
Chromephp
class for logging PHP variables to Google Chrome console
Stars: ✭ 1,339 (+19.87%)
Mutual labels:  console, logging
Yurnalist
An elegant console reporter, borrowed from Yarn
Stars: ✭ 88 (-92.12%)
Mutual labels:  console, logging
Console
OS X console application.
Stars: ✭ 298 (-73.32%)
Mutual labels:  console, logging
Logging
Powershell Logging Module
Stars: ✭ 167 (-85.05%)
Mutual labels:  console, logging
Quicklogger
Library for logging on files, console, memory, email, rest, eventlog, syslog, slack, telegram, redis, logstash, elasticsearch, influxdb, graylog, Sentry, Twilio, ide debug messages and throw events for Delphi/Firemonkey/freepascal/.NET (Windows/Linux/OSX/IOS/Android).
Stars: ✭ 137 (-87.74%)
Mutual labels:  console, logging
Logging Helpers
Basic template helpers for printing messages out to the console. Useful for debugging context in templates. Should work with any template engine.
Stars: ✭ 5 (-99.55%)
Mutual labels:  console, logging
Home
Project Glimpse: Node Edition - Spend less time debugging and more time developing.
Stars: ✭ 260 (-76.72%)
Mutual labels:  console, logging
Chromelogger Python
Python library for logging variables to Google Chrome console
Stars: ✭ 232 (-79.23%)
Mutual labels:  console, logging
Electron Log
Just a simple logging module for your Electron application
Stars: ✭ 765 (-31.51%)
Mutual labels:  console, logging
Loglevelnext
A modern logging library for Node.js that provides log level mapping to the console
Stars: ✭ 33 (-97.05%)
Mutual labels:  console, logging
Pygelf
Python logging handlers with GELF (Graylog Extended Log Format) support
Stars: ✭ 56 (-94.99%)
Mutual labels:  logging
Pioneer Console Boilerplate
Dependency injection, logging and configuration in a .NET Core console application.
Stars: ✭ 60 (-94.63%)
Mutual labels:  logging
Ios Sdk
AppSpector is a debugging service for mobile apps
Stars: ✭ 56 (-94.99%)
Mutual labels:  logging
Autologging
一个非常强大的监控日志输出框架,支持 SpringAOP 和动态字节码注入两种方式输出方法执行的监控日志,而且包含链路追踪功能,只要一个注解即可开启所有功能
Stars: ✭ 56 (-94.99%)
Mutual labels:  logging
Hslogger
Logging framework for Haskell
Stars: ✭ 60 (-94.63%)
Mutual labels:  logging
Log Viewer
Web UI to viewing logs
Stars: ✭ 59 (-94.72%)
Mutual labels:  logging
Rang
A Minimal, Header only Modern c++ library for terminal goodies 💄✨
Stars: ✭ 1,080 (-3.31%)
Mutual labels:  console
Gin Glog
Gin middleware to use glog
Stars: ✭ 53 (-95.26%)
Mutual labels:  logging

DraftLog

Build Status Dependency Status

Because Logging can be pretty and fun

DraftLog GIF

Installation

$ npm install draftlog

What it does

It allows you to re-write a line of your log after being written. Just like post 'updating'. This is the building block for any dynamic element such as progress bars, loading status, animations, checkboxes and so on.

It does that by keeping track of the current lines of code written through the stream, and moving the cursor up to the line of the LogDraft you created previously, and updating its content.

Look in the examples folders to see how easy it is, to create anything. No strict and fixed widgets are given to you. Instead, use your creativity with this tool to create anything you want! Share the results later with an example ;)

Looking for CUTE Unicode chars? Check out Unicute.

How the HECK is that even possible?

Usage

// Setup
const DraftLog = require('draftlog')
DraftLog(console)

// Or, in a single line:
require('draftlog').into(console)

// Account for manual line breaks with:
require('draftlog').into(console).addLineListener(process.stdin)

To create a updatable log, use the draft method injected into the provided console:

// Create a Draft log
var update = console.draft('Hi, my name is')

// You can call logs after it
console.log('Something else')

// Use the received callback to update it as many times as you want
update('Hi, my name is Ivan!')

Here are some interesting examples:

// Prints a clock incrementing one every second in the same line
var draft = console.draft()
var elapsed = 1
setInterval( () => {
  draft('Elapsed', elapsed++, 'seconds')
}, 1000)

console.log('It doesn`t matter')
console.log('How \n many \n lines \n it uses')

Or maybe, to show an flow process?

function someAsyncFunction(){ 
  var TAG = '[someAsyncFunction]'
  var log = console.draft(TAG, 'init')

  function a() {
    setTimeout(() => {
      log(TAG, 'calling b')
      b()
    }, 500)
  }

  function b() {
    setTimeout(() => {
      log(TAG, 'finished')
    })
  }
}

You can create your own progress bar, just like "that":

require('draftlog').into(console)

// Input progess goes from 0 to 100
function ProgressBar(progress) {
  // Make it 50 characters length
  var units = Math.round(progress / 2)
  return '[' + '='.repeat(units) + ' '.repeat(50 - units) + '] ' + progress + '%'
}

var barLine = console.draft('Starting download...')
downloadFile(function (progress) {
  barLine(ProgressBar(progress))
})

// Will show something like: (being updated in realtime)
// [============================                      ] 56%

Learn from examples!

We have a few of them ready for you to use! Take a look at the examples folder. Remember to replace require('../') with require('draftlog').

Also, install chalk to get colors on your terminal ;)

Important things to know

Because of the way Terminals are built, it is not possible to update a text outside the viewing area of the terminal.

That said, DraftLogs are setup to automagically be rewritten on a new line if they reach the end of the viewport. Note that, you can disable that behavior, by setting DraftLog.defaults.canReWrite = false

Also, if the NodeJS environment cannot detect the number of rows of your terminal automatically, it will use the default height on DraftLog.defaults.maximumLinesUp. Modify that if needed.

When using into(console).addLineListener(process.stdin), your code will no longer exit automatically, because the stream is being "read". To stop your own code, you can call process.exit(0) or pause the stream when you want with: process.stdin.pause().

Discouragements

This library is awesome for development, cli tools and what ever you want to created, that is NOT an optimized "slave" server. Please, disable it passing true as a second parameter to the DraftLog initialization:

// Disable Initialization (true = production; false = development)
DraftLog(console, true)
// Or, with one line require-init:
require('draftlog').into(console, true)

Creator

Ivan Seidel

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].