externalLog
Index
Constructors
externalconstructor
- Parameters- externaloptionaloptions: Partial<LoggerOptions>
 - Returns Log
Properties
externalreadonlyLEVELS
Map of available log levels that's useful for easy setting of appropriate log levels.
Each log level is represented internally by a number. Eg. log.LEVELS.DEBUG === 5.
Methods
externaldebug
- Logs a - DEBUGmessage. By default, it will not be written to the console. To see- DEBUGmessages in the console, set the log level to- DEBUGeither using the- log.setLevel(log.LEVELS.DEBUG)method or using the environment variable- APIFY_LOG_LEVEL=DEBUG. Data are stringified and appended to the message.- Parameters- externalmessage: string
- externaloptionaldata: AdditionalData
 - Returns void
externaldeprecated
- Logs given message only once as WARNING. It's used to warn user that some feature he is using has been deprecated. - Parameters- externalmessage: string
 - Returns void
externalerror
- Logs an - ERRORmessage. Use this method to log error messages that are not directly connected to an exception. For logging exceptions, use the- log.exceptionmethod.- Parameters- externalmessage: string
- externaloptionaldata: AdditionalData
 - Returns void
externalexception
- Logs an - ERRORlevel message with a nicely formatted exception. Note that the exception is the first parameter here and an additional message is only optional.- Parameters- externalexception: Error
- externalmessage: string
- externaloptionaldata: AdditionalData
 - Returns void
externalgetLevel
- Returns the currently selected logging level. This is useful for checking whether a message will actually be printed to the console before one actually performs a resource intensive operation to construct the message, such as querying a DB for some metadata that need to be added. If the log level is not high enough at the moment, it doesn't make sense to execute the query. - Returns number
externalgetOptions
- Returns the logger configuration. - Returns Required<LoggerOptions>
externalchild
- Creates a new instance of logger that inherits settings from a parent logger. - Parameters- externaloptions: Partial<LoggerOptions>
 - Returns Log
externalinfo
- Logs an - INFOmessage.- INFOis the default log level so info messages will be always logged, unless the log level is changed. Data are stringified and appended to the message.- Parameters- externalmessage: string
- externaloptionaldata: AdditionalData
 - Returns void
externalinternal
- Parameters- externallevel: LogLevel
- externalmessage: string
- externaloptionaldata: any
- externaloptionalexception: any
 - Returns void
externalperf
- Parameters- externalmessage: string
- externaloptionaldata: AdditionalData
 - Returns void
externalsetLevel
- Sets the log level to the given value, preventing messages from less important log levels from being printed to the console. Use in conjunction with the - log.LEVELSconstants such as- log.setLevel(log.LEVELS.DEBUG);- Default log level is INFO. - Parameters- externallevel: LogLevel
 - Returns void
externalsetOptions
- Configures logger. - Parameters- externaloptions: Partial<LoggerOptions>
 - Returns void
externalsoftFail
- Parameters- externalmessage: string
- externaloptionaldata: AdditionalData
 - Returns void
externalwarning
- Logs a - WARNINGlevel message. Data are stringified and appended to the message.- Parameters- externalmessage: string
- externaloptionaldata: AdditionalData
 - Returns void
externalwarningOnce
- Logs a - WARNINGlevel message only once.- Parameters- externalmessage: string
 - Returns void
The log instance enables level aware logging of messages and we advise to use it instead of
console.log()and its aliases in most development scenarios.A very useful use case for
logis usinglog.debugliberally throughout the codebase to get useful logging messages only when appropriate log level is set and keeping the console tidy in production environments.The available logging levels are, in this order:
DEBUG,INFO,WARNING,ERROR,OFFand can be referenced from thelog.LEVELSconstant, such aslog.LEVELS.ERROR.To log messages to the system console, use the
log.level(message)invocation, such aslog.debug('this is a debug message').To prevent writing of messages above a certain log level to the console, simply set the appropriate level. The default log level is
INFO, which means thatDEBUGmessages will not be printed, unless enabled.Example:
Another very useful way of setting the log level is by setting the
APIFY_LOG_LEVELenvironment variable, such asAPIFY_LOG_LEVEL=DEBUG. This way, no code changes are necessary to turn on your debug messages and start debugging right away.To add timestamps to your logs, you can override the default logger settings:
You can customize your logging further by extending or replacing the default logger instances with your own implementations.