Logging¶
This section describes logging configuration, that can be applied for below Lime-CRM server services:
- Web Server
- Search Indexer
- Event Handler
- Task Handler
- Task Scheduler
- Importer
Logging can be configured through environmental variables and the service configuration. Environmental variables take precedence over the service configuration.
Configuration¶
As a result, the root logger is configured.
| Environmental Variable | Configuration key (under logging section) |
Description | Default value |
|---|---|---|---|
LOGLEVEL |
level |
Sets the logging level. Accepted values are: DEBUG, INFO, WARNING, ERROR, CRITICAL. |
WARNING |
| N/A | loggers |
Fine-tunes logging level. See below. Only available in configuration file. | None |
LIME_LOG_STDOUT_HANDLER |
stdout_handler |
Indicates whether log messages should be printed to the standard output (usually console). | True |
LIME_LOG_STDOUT_HANDLER_JSON_FORMAT |
stdout_handler_json_format |
Indicates whether log messages printed to the standard output should be json-formatted. | False |
LIME_LOG_ROTATING_FILE_HANDLER |
rotating_file_handler |
Indicates whether log messages should be saved to a file that is being rotated, based on its size. | False |
LIME_LOG_ROTATING_FILE_NAME |
rotating_file_name |
Sets a name for the rotating file. | logs.log |
LIME_LOG_ROTATING_FILE_MAX_SIZE |
rotating_file_max_size |
Sets a maximum size of the rotating file, in megabytes. | 10 |
LIME_LOG_ROTATING_FILE_BACKUP_COUNT |
rotating_file_backup_count |
Sets a maximum number of rotating files. | 10 |
LIME_LOG_ROTATING_JSON_FILE_HANDLER |
rotating_json_file_handler |
Indicates whether log messages should be saved to a json file that is being rotated, based on its size. | False |
LIME_LOG_ROTATING_JSON_FILE_NAME |
rotating_json_file_name |
Sets a name for the rotating json file. | logs.json.log |
LIME_LOG_ROTATING_JSON_FILE_MAX_SIZE |
rotating_json_file_max_bytes |
Sets a maximum size of the rotating json file, in megabytes. | 10 |
LIME_LOG_ROTATING_JSON_FILE_BACKUP_COUNT |
rotating_json_file_backup_count |
Sets a maximum number of rotating json files. | 10 |
LIME_LOG_TIMED_ROTATING_FILE_HANDLER |
timed_rotating_file_handler |
Indicates whether log messages should be saved to a file that is being periodically rotated. | False |
LIME_LOG_TIMED_ROTATING_FILE_NAME |
timed_rotating_file_name |
Sets a name for the timed rotating file. | logs-timed.log |
LIME_LOG_TIMED_ROTATING_FILE_INTERVAL |
timed_rotating_file_interval |
Sets an interval (in minutes) for the timed rotating file, after which a new file will be created. | 60 |
LIME_LOG_TIMED_ROTATING_FILE_BACKUP_COUNT |
timed_rotating_file_backup_count |
Sets a maximum number of timed rotating files. | 6 |
LIME_LOG_REDIRECT_STDOUT |
redirect_stdout |
Indicates whether messages from standard output (like prints) should be redirected to the logger. | False |
Fine-Tuning Log Levels¶
To adjust the logging levels for specific parts of the product, use the loggers subsection within the logging section of your service configuration.
Example Configuration¶
This configuration does the following:
- Suppresses request logging from the
werkzeugpackage. - Enables debug-level logging for the
lime_databasepackage. - Outputs detailed information about SQL connection management and SQL statements from
sqlalchemy.
You can fine-tune the log output further by using more specific logger names. These names are visible in the log output itself.
Example Log Output¶
2025-06-20 09:22:22,691: DEBUG: sqlalchemy.engine.Engine ...
2025-06-20 09:22:22,705: DEBUG: sqlalchemy.pool.impl.QueuePool ...
To enable debug logging only for SQL connection pooling, and reduce verbosity elsewhere, you can use:
Silencing Specific Loggers¶
To completely silence a specific logger, set propagate: false. This stops the logger's messages from reaching the root logger.
For more details on the loggers syntax, refer to the Python logging configuration documentation.
Structured Log Fields¶
Info
The rules below apply from lime-core 26.118.2.
With JSON formatted logs, stdout_handler_json_format or rotating_json_file_handler, each key in extra is written as a field of the log record. Keep the message a string, and put the context in extra:
import logging
logger = logging.getLogger(__name__)
def sync_order(order_id: int, lines: list, status_code: int) -> None:
logger.info(
"Order synced to ERP",
extra={
"erp.order_id": order_id,
"erp.line_count": len(lines),
"erp.status_code": status_code,
},
)
How a value in extra is written:
- A string, a number, a boolean,
None, a list of strings, or a list of numbers is written as given. - A dotted key such as
erp.order_idis written as given. Use dotted keys to group fields, not a nested dict. - Any other value, such as a dict, a list that mixes types or a date, is written as a string: the JSON of a dict or list, the text of other values.
- A dict passed as the message,
logger.info({"order_id": 1}), is written as one JSON string inmessage.
Guidelines:
- Take field names from your code, never from data.
- Keep the type of a field the same in every log call.
- Never log a full limeobject, request body or API response. Select the values you need.
A key in extra that is an attribute of Python's LogRecord, such as name, message or args, raises a KeyError in the logging call.