Skip to main content

logging

Logger

from dara.core.logging import Logger

class Logger()

Custom Logger class for writing JSON formatted log messages

Methods

getLevel

def getLevel() -> int

Get effective level of the logger

info

def info(title: str, extra: Optional[Dict[str, Any]] = None)

Log a message at the INFO level

Arguments:

  • title: short title for the log message
  • extra: an optional field for any extra info to be passed along

warning

def warning(title: str, extra: Optional[Dict[str, Any]] = None)

Log a message at the WARNING level

Arguments:

  • title: short title for the log message
  • extra: an optional field for any extra info to be passed along

error

def error(title: str,
error: Exception,
extra: Optional[Dict[str, Any]] = None)

Log a message at the ERROR level

Arguments:

  • title: short title for the log message
  • error: the actual error object to print in dev mode
  • extra: an optional field for any extra info to be passed along

debug

def debug(title: str,
description: Optional[str] = None,
extra: Optional[Dict[str, Any]] = None)

Log a message at the DEBUG level

Arguments:

  • title: short title for the log message
  • description: an optional longer description for what this debug message is for
  • extra: an optional field for any extra info to be passed along

LoggingMiddleware

from dara.core.logging import LoggingMiddleware

class LoggingMiddleware(BaseHTTPMiddleware)

A Simple HTTP Middleware for Starlette based services

Usage:

logger = Logger('name')
app.add_middleware(LoggingMiddleware, logger=logger)

DaraProdFormatter

from dara.core.logging import DaraProdFormatter

class DaraProdFormatter(logging.Formatter)

A Logging Formatter for production purposes, it prints the whole log messages as json strings, including timestamps and log levels.

DaraDevFormatter

from dara.core.logging import DaraDevFormatter

class DaraDevFormatter(logging.Formatter)

A Logging Formatter for development purposes, it prettifies the JSON based logs into some readable.

This should not be used in production as there is a performance penalty associated with it.

eng_logger

Logger for engineers working on Dara itself, for debugging purposes.

Production: disabled Dev: disabled Enabled explicitly with --debug=<LEVEL> cli flag.

Level guidelines: ERROR - engineering descriptions of internal errors, logging root causes of errors in internals; example: 'Failed to cancel task' WARNING - internal warnings, something is potentially wrong, wrong parameter type provided?? INFO - logs describing i.e. starting steps of DerivedVariable resolving, example: 'Derived variable X ' DEBUG - very detailed logs, example: logs along the whole way of i.e. DerivedVariable lifecycle, task system

dev_logger

Logger for developers working on applications.

Production: enabled with level=INFO Dev: enabled with level=DEBUG

Level guidelines: ERROR - user-understandable errors, explaining how to fix them if possible; usually logging on the top-level, close to the API surface; example: "Could not find action X, did you forget to register it?" WARNING - warnings users should be aware of, that aren't part of the normal app flow; example: "env file not found, generating a default one" INFO - things happening user should be aware of which are part of the normal application flow, shouldn't print any user data; example: "Rebuilding JS" DEBUG - like INFO but only things useful for debugging, can include user data; example: "Rebuilding because of X and Y flags", "Running py_component X with data Y", "...returning a task"

http_logger

Logger for HTTP requests.

Shows detailed request/response logs on DEBUG, and basic logs on INFO.