Skip to content

Instantly share code, notes, and snippets.

@neelabalan
Created September 21, 2022 15:59
Show Gist options
  • Save neelabalan/a3ea4f7020e114660084fe676815e326 to your computer and use it in GitHub Desktop.
Save neelabalan/a3ea4f7020e114660084fe676815e326 to your computer and use it in GitHub Desktop.
Loguru internal logger object creation
from loguru import _Logger
from loguru import _Core
import ray
def create_logger_obj():
return _Logger(
core=_Core(),
exception=None,
depth=0,
record=False,
lazy=False,
colors=False,
raw=False,
capture=True,
patcher=None,
extra={},
)
@ray.remote
class StartUp:
def __init__(self):
self.logger = create_logger_obj()
self.logger.add(f'logs/{__name__}.log', filter=__name__, rotation='1 week')
def start(self):
for i in range(10):
self.logger.info(i)
def run():
logger.info("started!")
agents = [StartUp.remote() for i in range(4)]
result = []
for count , agent in enumerate(agents):
logger.info(count)
result.append(agent.start.remote())
done_id, _ = ray.wait(result)
logger.info("complete!")
if __name__ == "__main__":
logger = create_logger_obj()
logger.add(f'logs/{__name__}.log', filter=__name__, rotation='1 week')
run()
@neelabalan
Copy link
Author

Delgan/loguru#706

from loguru._logger import Logger
from loguru._logger import Core

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment