Skip to content

[HELP] How to make logging from a function or module go only to dedicated sink without propagation to other sinks? #103

@yuyutime

Description

@yuyutime

Help Request

How to log from instances of a function/method/class/module to dynamically created sink only without same messages going to other sinks in application?

Is there a way to implement this scenario in current version (v0.1.6) of logly?
Or can it be considered as a reasonable feature request?

Context

Suppose I have a bunch of async tasks to run: tasks = [ myfunc("task1"), myfunc("task2"), ...]

           await asyncio.wait_for( asyncio.gather(*tasks) )

I'm looking for a way to configure logly logger so that:

  • log messages from each task are written to corresponding file (separate sinks):
    sink1 => logs/task1.log, sink2 => logs/task2.log, ...
    with each file individually rotated, having independant log levels, etc.

  • log messages from these tasks don't go to any other sink configured in application

Using bind and fllter_function is not enough to implement such behaviour, because log messages are still propagated to other configured sinks and filter_function does not treat logs from instances of myfunc separately.

async def myfunc(taskname: str):
   task_logger = logger.bind(name=taskname)
   sink_id = task_logger.add(f"logs/{taskname}", filter_function="myfunc")
   # .....
   task_logger.remove(sink_id)

It is possible in python standard logging and in loguru (not trivial though).

Code Example

Logly Version

0.1.6

Python Version

3.10.12

Operating System

Ububtu 22.04

Additional Information

No response

Solution Interest

I just need help/guidance

Question Type

How-to questions

Specific Questions

No response

Checklist

  • I have searched the documentation and existing issues
  • This is not a bug report (use the bug report template instead)
  • This is not a feature request (use the feature request template instead)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions