# hs.logger

Simple logger for debugging purposes

Note: "methods" in this module are actually "static" functions - see hs.logger.new()


# API Overview

Variables - Configurable values

  • defaultLogLevel

Functions - API calls offered directly by the extension

  • history
  • historySize
  • new
  • printHistory
  • setGlobalLogLevel
  • setModulesLogLevel

Fields - Variables which can only be accessed from an object returned by a constructor

  • level

Methods - API calls which can only be made on an object returned by a constructor

  • d
  • df
  • e
  • ef
  • f
  • getLogLevel
  • i
  • setLogLevel
  • v
  • vf
  • w
  • wf

# API Documentation

# Variables

# defaultLogLevel

Signature hs.logger.defaultLogLevel
Type Variable
Description Default log level for new logger instances.
Notes None
Source extensions/logger/logger.lua line 203

# Functions

# history

Signature hs.logger.history() -> list of log entries
Type Function
Description Returns the global log history
Parameters
  • None
Returns
  • a list of (at most hs.logger.historySize()) log entries produced by all the logger instances, in chronological order;
  • each entry is a table with the following fields:
  • time - timestamp in seconds since the epoch
  • level - a number between 1 (error) and 5 (verbose)
  • id - a string containing the id of the logger instance that produced this entry
  • message - a string containing the logged message
Notes None
Examples None
Source extensions/logger/logger.lua line 94

# historySize

Signature hs.logger.historySize([size]) -> number
Type Function
Description Sets or gets the global log history size
Parameters
  • size - (optional) the desired number of log entries to keep in the history; if omitted, will return the current size; the starting value is 0 (disabled)
Returns
  • the current or new history size
Notes
  • if you change history size (other than from 0) after creating any logger instances, things will likely break
Examples None
Source extensions/logger/logger.lua line 69

# new

Signature hs.logger.new(id, loglevel) -> logger
Type Function
Description Creates a new logger instance
Parameters
  • id - a string identifier for the instance (usually the module name)
  • loglevel - (optional) can be 'nothing', 'error', 'warning', 'info', 'debug', or 'verbose', or a corresponding number between 0 and 5; uses hs.logger.defaultLogLevel if omitted
Returns
  • the new logger instance
Notes
  • the logger instance created by this method is not a regular object, but a plain table with "static" functions;
  • therefore, do not use the colon syntax for so-called "methods" in this module (as in mylogger.setLogLevel(3));
  • you must instead use the regular dot syntax: mylogger.setLogLevel(3)
  • Example:
  • lua</li><li>local log = hs.logger.new('mymodule','debug')</li><li>log.i('Initializing') -- will print "[mymodule] Initializing" to the console
Examples None
Source extensions/logger/logger.lua line 211

# printHistory

Signature hs.logger.printHistory([entries[, level[, filter[, caseSensitive]]]])
Type Function
Description Prints the global log history to the console
Parameters
  • entries - (optional) the maximum number of entries to print; if omitted, all entries in the history will be printed
  • level - (optional) the desired log level (see hs.logger.setLogLevel()); if omitted, defaults to verbose
  • filter - (optional) a string to filter the entries (by logger id or message) via string.find plain matching
  • caseSensitive - (optional) if true, filtering is case sensitive
Returns
  • None
Notes None
Examples None
Source extensions/logger/logger.lua line 139

# setGlobalLogLevel

Signature hs.logger.setGlobalLogLevel(lvl)
Type Function
Description Sets the log level for all logger instances (including objects' loggers)
Parameters
  • lvl
Returns
  • None
Notes None
Examples None
Source extensions/logger/logger.lua line 30

# setModulesLogLevel

Signature hs.logger.setModulesLogLevel(lvl)
Type Function
Description Sets the log level for all currently loaded modules
Parameters
  • lvl
Returns
  • None
Notes
  • This function only affects module-level loggers, object instances with their own loggers (e.g. windowfilters) won't be affected;
  • you can use hs.logger.setGlobalLogLevel() for those
Examples None
Source extensions/logger/logger.lua line 46

# Fields

# level

Signature hs.logger.level
Type Field
Description The log level of the logger instance, as a number between 0 and 5
Notes None
Source extensions/logger/logger.lua line 285

# Methods

# d

Signature hs.logger.d(...)
Type Method
Description Logs debug info to the console
Parameters
  • ... - one or more message strings
Returns
  • None
Notes None
Examples None
Source extensions/logger/logger.lua line 352

# df

Signature hs.logger.df(fmt,...)
Type Method
Description Logs formatted debug info to the console
Parameters
  • fmt - formatting string as per string.format
  • ... - arguments to fmt
Returns
  • None
Notes None
Examples None
Source extensions/logger/logger.lua line 362

# e

Signature hs.logger.e(...)
Type Method
Description Logs an error to the console
Parameters
  • ... - one or more message strings
Returns
  • None
Notes None
Examples None
Source extensions/logger/logger.lua line 289

# ef

Signature hs.logger.ef(fmt,...)
Type Method
Description Logs a formatted error to the console
Parameters
  • fmt - formatting string as per string.format
  • ... - arguments to fmt
Returns
  • None
Notes None
Examples None
Source extensions/logger/logger.lua line 299

# f

Signature hs.logger.f(fmt,...)
Type Method
Description Logs formatted info to the console
Parameters
  • fmt - formatting string as per string.format
  • ... - arguments to fmt
Returns
  • None
Notes None
Examples None
Source extensions/logger/logger.lua line 341

# getLogLevel

Signature hs.logger.getLogLevel() -> number
Type Method
Description Gets the log level of the logger instance
Parameters
  • None
Returns
  • The log level of this logger as a number between 0 and 5
Notes None
Examples None
Source extensions/logger/logger.lua line 275

# i

Signature hs.logger.i(...)
Type Method
Description Logs info to the console
Parameters
  • ... - one or more message strings
Returns
  • None
Notes None
Examples None
Source extensions/logger/logger.lua line 331

# setLogLevel

Signature hs.logger.setLogLevel(loglevel)
Type Method
Description Sets the log level of the logger instance
Parameters
  • loglevel - can be 'nothing', 'error', 'warning', 'info', 'debug', or 'verbose'; or a corresponding number between 0 and 5
Returns
  • None
Notes None
Examples None
Source extensions/logger/logger.lua line 265

# v

Signature hs.logger.v(...)
Type Method
Description Logs verbose info to the console
Parameters
  • ... - one or more message strings
Returns
  • None
Notes None
Examples None
Source extensions/logger/logger.lua line 373

# vf

Signature hs.logger.vf(fmt,...)
Type Method
Description Logs formatted verbose info to the console
Parameters
  • fmt - formatting string as per string.format
  • ... - arguments to fmt
Returns
  • None
Notes None
Examples None
Source extensions/logger/logger.lua line 383

# w

Signature hs.logger.w(...)
Type Method
Description Logs a warning to the console
Parameters
  • ... - one or more message strings
Returns
  • None
Notes None
Examples None
Source extensions/logger/logger.lua line 310

# wf

Signature hs.logger.wf(fmt,...)
Type Method
Description Logs a formatted warning to the console
Parameters
  • fmt - formatting string as per string.format
  • ... - arguments to fmt
Returns
  • None
Notes None
Examples None
Source extensions/logger/logger.lua line 320