• Stars
    star
    589
  • Rank 75,909 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Captures console.log's into a React Component 🔥

console-feed Sponsors

Sponsor this project

npm version npm downloads Demo

A React component that displays console logs from the current page, an iframe or transported across a server.

Demo

Alternative to console-feed

https://github.com/liriliri/chii supports the embedding the entire Chrome devtools.

https://github.com/tachibana-shin/vue-console-feed is a fork for Vue.JS

Who's using it

Features

  • Console formatting - style and give your logs color, and makes links clickable
  • DOM nodes - easily inspect & expand HTML elements, with syntax highlighting
  • console.table - view your logs in a table format
  • Other console methods:
    • console.time - view the time in milliseconds it takes to complete events
    • console.assert - assert that a statement is truthy
    • console.count - count how many times something occurs
  • Inbuilt JSON serialization - Objects, Functions & DOM elements can be encoded / decoded to and from JSON

Install

yarn add console-feed
# or
npm install console-feed

Basic usage

StackBlitz

import React from 'react'
import { Hook, Console, Decode } from 'console-feed'

class App extends React.Component {
  state = {
    logs: [],
  }

  componentDidMount() {
    Hook(window.console, (log) => {
      this.setState(({ logs }) => ({ logs: [...logs, Decode(log)] }))
    })

    console.log(`Hello world!`)
  }

  render() {
    return (
      <div style={{ backgroundColor: '#242424' }}>
        <Console logs={this.state.logs} variant="dark" />
      </div>
    )
  }
}

OR with hooks:

import React, { useState, useEffect } from 'react'
import { Console, Hook, Unhook } from 'console-feed'

const LogsContainer = () => {
  const [logs, setLogs] = useState([])

  // run once!
  useEffect(() => {
    const hookedConsole = Hook(
      window.console,
      (log) => setLogs((currLogs) => [...currLogs, log]),
      false
    )
    return () => Unhook(hookedConsole)
  }, [])

  return <Console logs={logs} variant="dark" />
}

export { LogsContainer }

Props for <Console /> component

logs: Log[]

An array consisting of Log objects. Required

filter?: Methods[]

Filter the logs, only displaying messages of certain methods.

variant?: 'light' | 'dark'

Sets the font color for the component. Default - light

styles?: Styles

Defines the custom styles to use on the component - see Styles.d.ts

searchKeywords?: string

A string value to filter logs

logFilter?: Function

If you want to use a custom log filter function, you can provide your own implementation

Log methods

Each log has a method assigned to it. The method is used to determine the style of the message and for the filter prop.

type Methods =
  | 'log'
  | 'debug'
  | 'info'
  | 'warn'
  | 'error'
  | 'table'
  | 'clear'
  | 'time'
  | 'timeEnd'
  | 'count'
  | 'assert'

Log object

A log object consists of the following:

type Logs = Log[]

interface Log {
  // The log method
  method: Methods
  // The arguments passed to console API
  data: any[]
}

Serialization

By default when you use the Hook() API, logs are serialized so that they will safely work with JSON.stringify. In order to restore a log back to format compatible with the <Console /> component, you need to call the Decode() method.

Disabling serialization

If the Hook function and the <Console /> component are on the same origin, you can disable serialization to increase performance.

Hook(
  window.console,
  (log) => {
    this.setState(({ logs }) => ({ logs: [...logs, log] }))
  },
  false
)

Limiting serialization

You can limit the number of keys/elements included when serializing objects/arrays.

Hook(
  window.console,
  (log) => {
    this.setState(({ logs }) => ({ logs: [...logs, log] }))
  },
  true,
  100 // limit to 100 keys/elements
)

Developing

To run console-feed locally, simply run:

yarn
yarn start
yarn test:watch

Head over to http://localhost:3000 in your browser, and you'll see the demo page come up. After you make changes you'll need to reload, but the jest tests will automatically restart.

More Repositories

1

gqless

a GraphQL client without queries
TypeScript
3,669
star
2

Wi-PWN

ESP8266 firmware for performing deauthentication attacks, with ease.
C
1,533
star
3

injectify

Perform advanced MiTM attacks on websites with ease 💉
TypeScript
663
star
4

github-icons

API, Chrome Extension & Mac App/CLI that adds icons to your repos
Rust
261
star
5

backdoor-controller

Masking the Sethc.exe backdoor with an anti-detection system.
Batchfile
28
star
6

site_icons

Efficient website icon scraper for rust, with sizes, ordering, and WASM support
Rust
26
star
7

cors-bypass

Bypass the browsers CORS restrictions, without needing to setup a server-side proxy.
TypeScript
24
star
8

comlink-extension

Use comlink with chrome extensions
TypeScript
20
star
9

Windows-10-SVM

Pixel-perfect replica of Windows 10, simulated in the browser with Vanilla JS.
HTML
15
star
10

xCMDx

xCMDx monitors the clipboard for commands and prompts to execute when received.
Batchfile
12
star
11

native-menu

ReactJS context menu component, that doesn't break native browser actions
JavaScript
12
star
12

unseen-data

Convert data to an unseen zero-width binary string 0️⃣
TypeScript
9
star
13

NumkeyMacro

Native macro key support without any extra hardware. CUE SDK enhanced
AutoHotkey
9
star
14

repositories-app

WIP: Mac app which allows you to access any file from github, without cloning
Rust
8
star
15

zombesp

TypeScript
8
star
16

MirumX

A complex framework that unifies & simplifies the creation of Batch File interfaces.
Batchfile
7
star
17

mix-classes

Seamlessly combine class inheritance with composition, guaranteed to work with any class
TypeScript
7
star
18

HologramPlusAPI

Enhance the Hologram.io Rest API for sending messages by adding useful features & variables.
PHP
5
star
19

samdenty-old

Personal website
JavaScript
4
star
20

huawei-mifi-indicator

JavaScript
4
star
21

repo_icons

Get project icons from any repository on github
Rust
4
star
22

virtual-cursor

A virtual cursor implemented in JavaScript
TypeScript
4
star
23

samdenty.github.io

JavaScript
3
star
24

raspi-frontend

Created with CodeSandbox
TypeScript
3
star
25

react-virtual

React virtualized list component based on mobx
TypeScript
2
star
26

fakerql

TypeScript
2
star
27

huawei-4g-lock

TypeScript
2
star
28

material-xsl

Who said you needed Javascript for modular, reusable Material design web apps?
XSLT
2
star
29

code-stepper

Proof-of-concept js-based debugger with pausing, breakpoints and context evaluation
TypeScript
2
star
30

node-kwa6mk

Created with StackBlitz ⚡️
1
star
31

yarn-repro

1
star
32

context-scope

Context support for Javascript / Typescript
TypeScript
1
star
33

social-bot

Easy-to-install popup embeds for your favorite social websites
TypeScript
1
star
34

SIGWINCH-test

JavaScript
1
star
35

dotfiles

Shell
1
star
36

empty-repo

1
star
37

samdenty

TypeScript
1
star
38

sd-security

Batch-file runtime
Batchfile
1
star
39

linaria-cyclic

JavaScript
1
star