Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
logging.hh File Reference
#include "nix/util/error.hh"
#include "nix/util/configuration.hh"
#include "nix/util/file-descriptor.hh"
#include "nix/util/finally.hh"
#include "nix/util/fun.hh"
#include <filesystem>
#include <span>
#include <type_traits>
#include <nlohmann/json_fwd.hpp>

Go to the source code of this file.

Classes

class  nix::LoggerSettings
class  nix::Logger
struct  nix::Logger::Field
struct  nix::Logger::Suspension
struct  nix::Activity
struct  nix::PushActivity

Macros

#define logErrorInfo(level, errorInfo...)
#define logError(errorInfo...)
#define logWarning(errorInfo...)
#define printMsgUsing(loggerParam, level, args...)
#define printMsg(level, args...)
#define printError(args...)
#define notice(args...)
#define printInfo(args...)
#define printTalkative(args...)
#define debug(args...)
#define vomit(args...)
#define warnOnce(haveWarned, args...)

Typedefs

typedef uint64_t nix::ActivityId

Enumerations

enum  ActivityType {
  actUnknown = 0 , actCopyPath = 100 , actFileTransfer = 101 , actRealise = 102 ,
  actCopyPaths = 103 , actBuilds = 104 , actBuild = 105 , actOptimiseStore = 106 ,
  actVerifyPaths = 107 , actSubstitute = 108 , actQueryPathInfo = 109 , actPostBuildHook = 110 ,
  actBuildWaiting = 111 , actFetchTree = 112 , actFetchToStore = 113 , actLast = actFetchToStore
}
enum  ResultType {
  resFileLinked = 100 , resBuildLogLine = 101 , resUntrustedPath = 102 , resCorruptedPath = 103 ,
  resSetPhase = 104 , resProgress = 105 , resSetExpected = 106 , resPostBuildLogLine = 107 ,
  resFetchStatus = 108 , resFetchToStore = 109 , resLast = resFetchToStore
}

Functions

ActivityId nix::getCurActivity ()
void nix::setCurActivity (const ActivityId activityId)
std::unique_ptr< Logger > nix::makeSimpleLogger (bool printBuildLogs=true)
std::unique_ptr< Logger > nix::makeTeeLogger (std::unique_ptr< Logger > mainLogger, std::vector< std::unique_ptr< Logger > > &&extraLoggers)
std::unique_ptr< Logger > nix::makeJSONLogger (Descriptor fd, bool includeNixPrefix=true)
std::unique_ptr< Logger > nix::makeJSONLogger (const std::filesystem::path &path, bool includeNixPrefix=true)
void nix::applyJSONLogger ()
std::optional< nlohmann::json > nix::parseJSONMessage (std::string_view msg, std::string_view source)
bool nix::handleJSONLogMessage (const nlohmann::json &json, const Activity &act, std::map< ActivityId, Activity > &activities, std::string_view source, bool trusted)
bool nix::handleJSONLogMessage (std::string_view msg, const Activity &act, std::map< ActivityId, Activity > &activities, std::string_view source, bool trusted)
bool nix::handleJSONLogMessage (const std::string &msg, const Activity &act, std::map< ActivityId, Activity > &activities, std::string_view source, bool trusted)
template<typename... Args>
void nix::warn (const std::string &fs, const Args &... args)
void nix::writeToStderr (std::string_view s) noexcept

Variables

LoggerSettings nix::loggerSettings
Logger * nix::logger = makeSimpleLogger(true).release()
Verbosity nix::verbosity = lvlInfo

Macro Definition Documentation

◆ debug

#define debug ( args...)
Value:
printMsg(lvlDebug, args)

◆ logError

#define logError ( errorInfo...)
Value:
logErrorInfo(lvlError, errorInfo)
#define logErrorInfo(level, errorInfo...)
Definition logging.hh:353

◆ logErrorInfo

#define logErrorInfo ( level,
errorInfo... )
Value:
do { \
if ((level) <= nix::verbosity) { \
logger->logEI((level), errorInfo); \
} \
} while (0)
Verbosity verbosity
Definition logging.cc:174

Print a message with the standard ErrorInfo format. In general, use these 'log' macros for reporting problems that may require user intervention or that need more explanation. Use the 'print' macros for more lightweight status messages.

◆ logWarning

#define logWarning ( errorInfo...)
Value:
logErrorInfo(lvlWarn, errorInfo)

◆ notice

#define notice ( args...)
Value:
printMsg(lvlNotice, args)

◆ printError

#define printError ( args...)
Value:
printMsg(lvlError, args)

◆ printInfo

#define printInfo ( args...)
Value:
printMsg(lvlInfo, args)

◆ printMsg

#define printMsg ( level,
args... )
Value:
printMsgUsing(logger, level, args)
#define printMsgUsing(loggerParam, level, args...)
Definition logging.hh:368

◆ printMsgUsing

#define printMsgUsing ( loggerParam,
level,
args... )
Value:
do { \
auto __lvl = level; \
if (__lvl <= nix::verbosity) { \
loggerParam->log(__lvl, fmt(args)); \
} \
} while (0)

Print a string message if the current log level is at least the specified level. Note that this has to be implemented as a macro to ensure that the arguments are evaluated lazily.

◆ printTalkative

#define printTalkative ( args...)
Value:
printMsg(lvlTalkative, args)

◆ vomit

#define vomit ( args...)
Value:
printMsg(lvlVomit, args)

◆ warnOnce

#define warnOnce ( haveWarned,
args... )
Value:
if (!haveWarned) { \
haveWarned = true; \
warn(args); \
}

Function Documentation

◆ handleJSONLogMessage() [1/2]

bool nix::handleJSONLogMessage ( const nlohmann::json & json,
const Activity & act,
std::map< ActivityId, Activity > & activities,
std::string_view source,
bool trusted )
Parameters
sourceA noun phrase describing the source of the message, e.g. "the builder".

◆ handleJSONLogMessage() [2/2]

bool nix::handleJSONLogMessage ( std::string_view msg,
const Activity & act,
std::map< ActivityId, Activity > & activities,
std::string_view source,
bool trusted )
Parameters
sourceA noun phrase describing the source of the message, e.g. "the builder".

◆ makeTeeLogger()

std::unique_ptr< Logger > nix::makeTeeLogger ( std::unique_ptr< Logger > mainLogger,
std::vector< std::unique_ptr< Logger > > && extraLoggers )

Create a logger that sends log messages to mainLogger and the list of loggers in extraLoggers. Only mainLogger is used for writing to stdout and getting user input.

◆ parseJSONMessage()

std::optional< nlohmann::json > nix::parseJSONMessage ( std::string_view msg,
std::string_view source )
Parameters
sourceA noun phrase describing the source of the message, e.g. "the builder".

◆ warn()

template<typename... Args>
void nix::warn ( const std::string & fs,
const Args &... args )
inline

if verbosity >= lvlWarn, print a message with a yellow 'warning:' prefix.

Variable Documentation

◆ logger

Logger * nix::logger = makeSimpleLogger(true).release()

This is a raw pointer to allow it to leak. Avoids races in activity teardown.

◆ verbosity

Verbosity nix::verbosity = lvlInfo

suppress msgs > this