Post

ConLog() console log management and utility tool for JavaScript

ConLog() console log management and utility tool for JavaScript

dependencies 👈🥳 npm v GitHub Clones npm downloads last commit

@codump/conlog is a JavaScript library designed to enhance terminal logging by introducing colors, styles, and advanced formatting to standard console output. It facilitates easier debugging and monitoring in JavaScript/TypeScript environments by supporting namespace grouping and various log levels for visual distinction. For more details, visit the package on npm.



Run npm i @codump/conlog

We are launching our website with demo and documentation! https://codump.github.io/conlog/

Minimal to go

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const { ConLog, ConLogStartMsg } = require('@codump/conlog')

/**
 * This is so minimal you can even remove it, just do that *after* setting things up.
 * Otherwise the startup message (that shows your settings) won't appear.
 * You can also drop ConLogStartMsg from the import if you don't need it.
 */
ConLogStartMsg(true)

/**
 * And here's the core feature:
 * ConLog() that's it, that simple!
 */
ConLog('Confirm! Type 2 => ok in console', 2)

/**
 * Okay I trolled a bit earlier, the real minimal example is even shorter.
 * But we’re looking out for newcomers here so please forgive me
 */

For real this time

1
2
3
const { ConLog } = require(`@codump/conlog`)

ConLog(`Sorry! Hope I didn't upset you again with an error!?`, 1);

How to use in frontend

ConLog() works in both back- and frontend. We can use the ESM>CDN to import it to the front with zero install needed! Browser needs to support ES6.

1
2
3
4
// script.js
import { ConLog } from `https://esm.sh/@codump/conlog`

ConLog(`It's the same as in the backend, all details are below.`, 2);

Make sure the script where you are importing it has the module type.

1
<script type='module' src='script.js'></script>

Let’s check the full details

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
 * ConLog - Console log management and utility tool
 * 
 * In the repo example.js is set with require(`./lib/`) but copy paste the code below
 * when you use it after a `npm install @codump/conlog`
 */
const { ConLogInit, ConLogSet, ConLog, ConLogStartMsg } = require(`@codump/conlog`)

// ================================
// INITIALIZATION
// ================================

/**
 * Initialize ConLog with global enable/disable setting
 * 
 * @param {boolean} status - Master switch for all console logging
 *   - true: Enable all ConLog output (default)
 *   - false: Completely disable all ConLog output
 *   - Every ConLog after ConLogInit(false) stops working
 */
ConLogInit(true)

// ================================
// CONFIGURATION
// ================================

/**
 * Configure which log types are displayed
 * All parameters default to true, so you only need to specify false values
 * 
 * @param {boolean} error - Display error messages (type 1)
 * @param {boolean} ok - Display success/OK messages (type 2)  
 * @param {boolean} warning - Display warning messages (type 3)
 * @param {boolean} object - Display object dumps (type 4)
 * @param {boolean} color - Enable colored console output
 * 
 */
ConLogSet({error: true, ok: true, warning: true, object: true, color: true})

/**
 * Display startup message showing current ConLog settings
 * Useful for debugging or confirming ConLog is properly initialized
 * 
 * @param {boolean} status - Whether to display startup message (default: false)
 */
ConLogStartMsg(true)

// ================================
// LOGGING EXAMPLES
// ================================

/**
 * Main logging function - ConLog(text, type)
 * 
 * TYPE OPTIONS:
 * - Error:   1, `er`, `err`, `error`
 * - Success: 2, `ok` 
 * - Warning: 3, `wa`, `war`, `warn`, `warning`
 * - Object:  4, `so`, `ob`, `obj`, `object`, `showobject`
 *   - Gives a stringify to the output. Don't set any type if you want to log the raw object. 
 * 
 * USAGE:
 * - ConLog(text, type) - Typed logging with formatting
 * - ConLog(text) - Simple logging without type (always displayed unless ConLogInit is false)
 */

// Sample data for object logging
const nestedData = [{ nestedObj: `inside nested structure` }]
const complexObject = [{ 
    test: `valid test data`, 
    nested: nestedData,
    timestamp: new Date().toISOString()
}];

/ Error logging - displayed in red
ConLog(`Example... Database connection failed.`, 1)
ConLog(`Example... Invalid user credentials provided.`, `error`)

// Success logging - displayed in green
ConLog(`Example... User successfully authenticated.`, 2)
ConLog(`Example... File upload completed.`,`ok`)

// Warning logging - displayed in yellow with warning icon
ConLog(`Example... API rate limit approaching.`, 3)
ConLog(`Example... Deprecated function usage detected.`, `warning`)

// Object logging - formatted JSON display
ConLog(complexObject, 4)
ConLog({ userId: 123, status: `active`, permissions: [`read`, `write`] }, `object`)

// Simple logging - no special formatting, always displayed (unless ConLogInit is false)
ConLog(`Example... Processing user request...`)
This post is licensed under CC BY 4.0 by the author.