Skip to main content

Log Queue

Project description

logqueue

Log Queue

Initialize

Declare thread function.

def logger_function(log_dict):
    print(log_dict)
    # ...

output:
{'log_type': 'exception',
'timestamp': 1700000000.100001,
'process_id': 1234,
'thread_id': 1234567890,
'cpu_usage': 12, # if exist psutil
'memory_usage': 12, # if exist psutil
'file_name': 'test.py',
'file_lineno': 1,
'text': 'start',
'trace_back': 'error'} # if exception

import logqueue
logqueue.initialize(logger_function)
# ...

Close and Join

logqueue.close()
logqueue.join()

Signal

import signal
import logqueue

def signal_handler(_, frame):
    logqueue.close()

signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGABRT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)

# ... 
logqueue.join()

Logging

logqueue.put_info("start")
# or
logqueue.info("start")
log_str = logqueue.parse(log_dict)
print(log_str)

output:
2023-11-15 07:13:20.100001 12%:CPU 12%:Mem 234:PID 4567890:TID info test.py:1 start

**kwargs

logqueue.info("hi", alarm_meesage="alarm", input_database=True)
log_dict = logqueue.get()
print(log_dict)

output:
{'timestamp': 1700000000.100001,
'process_id': 1234,
'thread_id': 1234567890,
'log_type': 'information',
'file_name': 'test.py',
'file_lineno': 1,
'text': 'start',
'alarm_meesage': "alarm",
'input_database': True}

Log function types

logqueue.put(log_type:str, *objs:object, **kwargs)
logqueue.info(*objs:object, **kwargs) # or put_info()
logqueue.debug(*objs:object, **kwargs) # or put_debug()
logqueue.exception(*objs:object, **kwargs) # or put_exception()
logqueue.signal(*objs:object, **kwargs) # or put_signal()

Parse

get_log_formatters() # default log formatters
# {date} {time} {process_id:0{process_id_max_length}d}:PID {thread_id:0{thread_id_max_length}d}:TID {file_name:>{file_name_length}}:{file_lineno:<{file_lineno_length}} {log_type:{log_type_max_length}} {text}
clear_log_formatter()

append_log_formatter(f"{{{LogKey.date}}}")
append_log_formatter(f"{{{LogKey.time}}}")
get_log_formatters()
# {date} {time}
set_date_formatter("%y-%m-%d")
get_date_formatter()
# %y-%m-%d
set_process_id_formatter(f"{{{LogKey.process_id}:0{{{LogKey.process_id_max_length}}}d}}:PID")
get_process_id_formatter()
# {process_id:0{process_id_max_length}d}:PID

LogKeys

LogKey.date  
LogKey.time  
LogKey.timestamp  
LogKey.process_id  
LogKey.process_id_max_length  
LogKey.thread_id  
LogKey.thread_id_max_length  
LogKey.cpu_usage  
LogKey.memory_usage  
LogKey.log_type  
LogKey.log_type_max_length  
LogKey.file_info  
LogKey.file_name  
LogKey.file_name_length  
LogKey.file_lineno  
LogKey.file_lineno_length  
LogKey.text  
LogKey.trace_back  

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

logqueue-0.0.2.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

logqueue-0.0.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file logqueue-0.0.2.tar.gz.

File metadata

  • Download URL: logqueue-0.0.2.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for logqueue-0.0.2.tar.gz
Algorithm Hash digest
SHA256 a0c77c2558af3132225606a5e751cb4c22d4f7375238a8cafc212a135e7e9bc3
MD5 04bbff2288f92634164c5a83cd44dab3
BLAKE2b-256 5ac20bc62a5cb6581d5aea558f44bbbd743598854bd42035c9757c9f9ca75805

See more details on using hashes here.

File details

Details for the file logqueue-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: logqueue-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for logqueue-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7c2a4dc8906cd9e6662b9914b9db9669b512b6c8fbc57b862d868d40e105d537
MD5 d0bcfca1b5544588ddf246a52adda763
BLAKE2b-256 d9dfe43f285def2d33ef7f1d3be6b945b72a601c7742d01f461a111c51188949

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