Modules@robinpath/log
log

@robinpath/log

0.1.2Node.jsPublic

Structured logging with levels, file output, JSON format, timers, and grouping

Log

Structured logging with levels, file output, JSON format, timers, and grouping

Package: @robinpath/log | Category: Other | Type: Utility

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the log module when you need to:

  • Log a message at DEBUG level to stdout -- Use log.debug to perform this operation
  • Log a message at INFO level to stdout -- Use log.info to perform this operation
  • Log a message at WARN level to stderr -- Use log.warn to perform this operation
  • Log a message at ERROR level to stderr -- Use log.error to perform this operation
  • Log a message at FATAL level to stderr -- Use log.fatal to perform this operation

Quick Reference

FunctionDescriptionReturns
debugLog a message at DEBUG level to stdoutTrue after logging
infoLog a message at INFO level to stdoutTrue after logging
warnLog a message at WARN level to stderrTrue after logging
errorLog a message at ERROR level to stderrTrue after logging
fatalLog a message at FATAL level to stderrTrue after logging
setLevelSet the minimum log level; messages below this level are suppressedTrue after setting the level
getLevelGet the current minimum log level as a stringCurrent log level name (debug, info, warn, error, fatal, or silent)
setFileSet a file path to append log output to in addition to stdout/stderrTrue after setting the file
setFormatSet the output format for log messagesTrue after setting the format
clearReset all log settings to defaults (info level, no file, text format)True after resetting
tablePretty-print an array of objects as a table to stdoutTrue after printing the table
groupPrint a group header and increase indentation for subsequent log messagesTrue after opening the group
groupEndEnd the current group and decrease indentationTrue after closing the group
timeStart a named timerTrue after starting the timer
timeEndStop a named timer and log the elapsed time in millisecondsElapsed time in milliseconds

Functions

debug

Log a message at DEBUG level to stdout

Module: log | Returns: boolean -- True after logging

log.debug "variable x =" $x
ParameterTypeRequiredDescription
messagesstringYesOne or more messages to log

info

Log a message at INFO level to stdout

Module: log | Returns: boolean -- True after logging

log.info "Server started on port" $port
ParameterTypeRequiredDescription
messagesstringYesOne or more messages to log

warn

Log a message at WARN level to stderr

Module: log | Returns: boolean -- True after logging

log.warn "Deprecated function called"
ParameterTypeRequiredDescription
messagesstringYesOne or more messages to log

error

Log a message at ERROR level to stderr

Module: log | Returns: boolean -- True after logging

log.error "Failed to connect:" $err
ParameterTypeRequiredDescription
messagesstringYesOne or more messages to log

fatal

Log a message at FATAL level to stderr

Module: log | Returns: boolean -- True after logging

log.fatal "Unrecoverable error, shutting down"
ParameterTypeRequiredDescription
messagesstringYesOne or more messages to log

setLevel

Set the minimum log level; messages below this level are suppressed

Module: log | Returns: boolean -- True after setting the level

log.setLevel "warn"
ParameterTypeRequiredDescription
levelstringYesLog level: debug, info, warn, error, fatal, or silent

getLevel

Get the current minimum log level as a string

Module: log | Returns: string -- Current log level name (debug, info, warn, error, fatal, or silent)

log.getLevel
ParameterTypeRequiredDescription
(none)NoCall with no arguments

setFile

Set a file path to append log output to in addition to stdout/stderr

Module: log | Returns: boolean -- True after setting the file

log.setFile "/tmp/app.log"
ParameterTypeRequiredDescription
filePathstringYesPath to the log file

setFormat

Set the output format for log messages

Module: log | Returns: boolean -- True after setting the format

log.setFormat "json"
ParameterTypeRequiredDescription
formatstringYesFormat: text (default) or json

clear

Reset all log settings to defaults (info level, no file, text format)

Module: log | Returns: boolean -- True after resetting

log.clear
ParameterTypeRequiredDescription
(none)NoCall with no arguments

table

Pretty-print an array of objects as a table to stdout

Module: log | Returns: boolean -- True after printing the table

log.table $rows
ParameterTypeRequiredDescription
dataarrayYesArray of objects to display as a table

group

Print a group header and increase indentation for subsequent log messages

Module: log | Returns: boolean -- True after opening the group

log.group "Request handling"
ParameterTypeRequiredDescription
labelstringYesLabel for the group

groupEnd

End the current group and decrease indentation

Module: log | Returns: boolean -- True after closing the group

log.groupEnd
ParameterTypeRequiredDescription
(none)NoCall with no arguments

time

Start a named timer

Module: log | Returns: boolean -- True after starting the timer

log.time "db-query"
ParameterTypeRequiredDescription
labelstringYesLabel for the timer

timeEnd

Stop a named timer and log the elapsed time in milliseconds

Module: log | Returns: number -- Elapsed time in milliseconds

log.timeEnd "db-query"
ParameterTypeRequiredDescription
labelstringYesLabel of the timer to stop

Error Handling

All functions throw on failure. Common errors:

ErrorCause
Invalid format: ${fmt}. Valid formats: text, jsonCheck the error message for details
Invalid log level: .... Valid levels: ...Check the error message for details
Timer "..." does not existCheck the error message for details
@desc "Debug and validate result"
do
  set $result as log.debug "variable x =" $x
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. List and iterate Level

Retrieve all items and loop through them.

@desc "Get level and iterate results"
do
  set $result as log.getLevel
  each $item in $result
    print $item
  end
enddo

2. Multi-step Log workflow

Chain multiple log operations together.

@desc "Debug, info, and more"
do
  set $r_debug as log.debug "variable x =" $x
  set $r_info as log.info "Server started on port" $port
  set $r_warn as log.warn "Deprecated function called"
  print "All operations complete"
enddo

3. Safe debug with validation

Check results before proceeding.

@desc "Debug and validate result"
do
  set $result as log.debug "variable x =" $x
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.2latest1 months ago
Install
$ robinpath add @robinpath/log

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.2
LicenseMIT
Unpacked Size5.8 KB
Versions1
Weekly Downloads22
Total Downloads22
Stars0
Last Publish1 months ago
Created1 months ago

Keywords

Category

utilities