0.2.7 • Published 1 year ago

localog v0.2.7

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

Localog

Localog is a developer's utililty to help logging when developing a cli app. It renders logs in another terminal window.

Install

npm i localog

How To

In your package.json:

{
  "scripts": {
    "localog": "localog"
  }
}

Run the server, on a terminal:

npm run localog

Where ever in your app:

import { success } from 'localog'

// success('Hello')

// test this
for(let i = 0; i < 99999; i++)
  success(`${i}: Hello, ${new Date().toISOString()}`)

Methods

Under the hood, localog uses (some) consola functions. It also has some other functionalities:

import {

  // json utilities
  json,
  stringfy,

  // same as consola
  info,
  start,
  warn,
  success,
  error,
  box,

  // utils to set socket file / port
  // to send data to
  setAddress,

  // utils to set separators
  // used in sending data
  setSeparators,

  // utils to close the connection
  // will be done automatically 
  // on exit SIGINT SIGUSR1 SIGUSR2
  close,

} from 'localog'
// or import localog from localog

json

Logging JSON

import { json } from 'localog'

json({ hello: 'world' })
// will print: { hello: 'world' }

stringify

Logging stringified JSON

import { stringify } from 'localog'

stringify({ 
  hello: 'world', 
  message: {
    what: 'is this?',
    oh: 'this is a very complicated json',
    "i will": [
      'need', 'someway',
      'to', 'see', 'all'
    ],
    the: "message",
    "on": new Date()
  } 
})

/* Will output:
{
  "hello": "world",
  "message": {
    "what": "is this?",
    "oh": "this is a very complicated json",
    "i will": [
      "need",
      "someway",
      "to",
      "see",
      "all"
    ],
    "the": "message",
    "on": "2024-06-07T17:03:21.784Z"
  }
}
*/

consola's method

info, start, warn, success, error, and box, are consola's method.

Checkout consola's doc to see how it will look like on the terminal.

setAddress

localog listens and sends data to ./.localog by default. You can change this into any other file, or port number.

{
  "scripts": {
    "localog": "localog --socket='/tmp/my-awesome-socket'"
    // or "localog": "localog --port=5432"
  }
}

In your app:

import { setAddress, success } from 'localog'

// before you log into anything
setAddress('/tmp/my-awesome-socket')
// or setAddress( 5432 )

success('Hello')

setSeparators

localog uses \ufffe and \uffff to separate data from one another. You can set it to any character you want. NOTE: it should be just one character.

{
  "scripts": {
    "localog": "localog --frontSeparator='^' --backSeparator='$'"
  }
}

In your app:

import { setSeparators, success } from 'localog'

// before you log anything
setSeparators('^', '$')

// do your awesome stuff
success('My project is awesome!')

close

The client will open connection to the server. It will keep it open until exit, SIGINT, SIGUSR1, or SIGUSR2 signal is detected.

If you, somehow, need the client localog to shut down connection to it's server, try shutting it down with close.

import { close } from 'localog'

// closing the localog connection
close()

// this will also close the connection
process.exit()

License

MIT

0.2.7

1 year ago

0.2.6

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.17

1 year ago

0.1.16

1 year ago

0.1.15

1 year ago

0.1.14

1 year ago

0.1.13

1 year ago

0.1.12

1 year ago

0.1.11

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago