Skip to main content

This lib will help you to send your app's logs to LogCenter.

Project description

LogCenter.Logger

This lib will help you to send your app's logs to LogCenter.

Descrição da imagem

Each log entry is queued and will be sent in order, following a FIFO (First In, First Out) approach.
This ensures that logs are processed sequentially, maintaining the correct logging sequence.

Getting Started

Basic usage

First install the lib from Nuget

pip install LogCenter --no-cache-dir

Initialize the logger with you LogCenter configs

from LogCenter import LogCenterOptions,LogCenterLogger, LogLevel

options = LogCenterOptions(
    url="http://localhost:9200",
    table="example dotnet console",                   # the spaces will be converted to _ (underscore).
    token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9....", # Generate this on LogCenter inteface, on you profile photo.
    consoleLog = True,                                # Log the message on the console as a comon Console.WriteLine(). Default is true
    consoleLogEntireObject = True                     # Log the entire objeti to the Console.WriteLine(). Default is false
)

logger = LogCenterLogger(options)

Logging a simple message in the background without blocking code execution. It'll start a new thread to send the log to LogCenter.

logger.LogAsync(LogLevel.INFO, "Hello World")

Logging an object in the background without blocking code execution. You can use any type of object, which will be converted to JSON before being sent to LogCenter.

logger.LogAsync(LogLevel.CRITICAL, "This is just an example", {
    "nome": "John Doe Jr. da Silva",
    "idade": 30,
    "CPF": "123.456.789-00",
    "email": "john.doe.jr@example.com",
    "telefone": "11 91234-5678",
    "cep": "04545-000",
    "logradouro": "Rua Professor Atílio Innocenti, 165",
    "bairro": "Vila Nova Conceição",
    "cidade": "São Paulo",
    "uf": "SP",
    "pais": "Brasil",
    "dataDeNascimento": str(uuid.uuid4()),  # Simulação de data
    "altura": 1.80,
    "peso": 70.5,
    "descricao": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat"
})

Logging an object in the foreground while blocking code execution. If you want to log in the current thread and wait for LogCenter's confirmation.
Use this if it is the last log execution; otherwise, your app may terminate before your log is sent to LogCenter

logger.Log(LogLevel.ERROR, "Hello World")

TraceID

A Trace ID (Tracing Identifier) is a unique identifier assigned to a request as it flows through a distributed system. It helps track the request across multiple services, making it easier to debug and monitor performance.

🔹 How It Works:

  1. When a request enters a system (e.g., an API call), a Trace ID is generated.
  2. This ID is propagated across all microservices and logs as the request moves through the system.
  3. Developers can use it to trace the full lifecycle of a request across different services.

If you want to reference an ID (a Guid or a string) on LogCenter, you can use the TraceId. Let's see how to and cases:

/* In this case, you configure an ID (a GUID or a custom string) as a global Trace ID for the execution instance of your app.
 * Here, you are assigning the same Trace ID to all logs for that instance's execution.
 */
logger = LogCenterLogger(options, 
                         #trace_id = str(uuid.uuid4()) # It's optional. If empty, it will generate a new one Guid, else, you can you your own traceId, Guid or string
                         )

// AND / OR

/* In this case, you configure an ID (a GUID or a custom string) for each log entry. It will ignore the global Trace ID (above).
 * Here, you are assigning a Trace ID to each execution. It is useful for multiple thread executions in your app.
 * You can generate a Trace ID at the beginning of each thread and pass it to the Log method call.
 */
traceId = str(uuid.uuid4();
logger.LogAsync(LogLevel.Info, "Hello World - Info", traceId);

//OR

/* Same as above, but with a personal/custom string
 */
myTrace = "My custom trace execution ID";
logger.LogAsync(LogLevel.Info, "Hello World - Info", myTrace);

Build Package

On pyproject.toml file directory:

python -m build # must be installed before -> pip install build
twine upload dist/* # must be installed before
pip install LogCenter --no-cache-dir

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

logcenter-0.1.4.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

logcenter-0.1.4-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file logcenter-0.1.4.tar.gz.

File metadata

  • Download URL: logcenter-0.1.4.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for logcenter-0.1.4.tar.gz
Algorithm Hash digest
SHA256 20033441cf3f165f0fe84ba0944c0ecfc1b2203469b499b24c5d154359614b25
MD5 4222823946e1e49fcd1ac935c01dd3eb
BLAKE2b-256 8af88c3c966c41873b3ae431269bc4a466d28f41622816863bcc7bc912fc4301

See more details on using hashes here.

File details

Details for the file logcenter-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: logcenter-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for logcenter-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7d6f03f075b38a8078621a60bef392186da6b9ddefb2577a1e3da77ee078ddae
MD5 ce477b19692d1ea60c3e405ebc161006
BLAKE2b-256 9e4e9a93c2c3829e8899a3d3ab00a71cb636bc8b402b5f719bd15f7b5b9056ce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page