logqueue


Namelogqueue JSON
Version 0.0.4 PyPI version JSON
download
home_page
SummaryLog Queue
upload_time2023-11-09 08:08:56
maintainer
docs_urlNone
author
requires_python>=3.10
license
keywords log log q log queue logger logger q logger queue logging logging q logging queue logqueue queue
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # logqueue
Log Queue

## Initialize
Declare thread function.  
```python  
def logger_function(log_dict):
    print(log_dict)
    # ...
```
Initialize
```python  
import logqueue
logqueue.initialize(logger_function)
# ...
```
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  

## Close and Join
```python  
logqueue.close()
logqueue.join()
```
ex) Use signal.
```python  
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
```python  
logqueue.put_info("start")
# or
logqueue.info("start")
```  

### Parameters
use user variables
```python  
logqueue.info("hi", alarm_message="alarm", input_database=True)
```  
```python 
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': 'hi',  
'alarm_meesage': "alarm", # user variable  
'input_database': True} # user variable  

### Log types
Base 'put()'  
```python  
logqueue.put(log_type:str, *objs:object, **kwargs)
```
```python  
logqueue.info(*objs:object, **kwargs)
logqueue.put_info(*objs:object, **kwargs)
logqueue.put(LogType.INFORMATION, *objs:object, **kwargs)
```
```python  
logqueue.debug(*objs:object, **kwargs)
logqueue.put_debug(*objs:object, **kwargs)
logqueue.put(LogType.DEBUG, *objs:object, **kwargs)
```
```python  
logqueue.warning(*objs:object, **kwargs)
logqueue.put_warning(*objs:object, **kwargs)
logqueue.put(LogType.WARNING, *objs:object, **kwargs)
```
```python  
logqueue.exception(*objs:object, **kwargs)
logqueue.put_exception(*objs:object, **kwargs)
logqueue.put(LogType.EXCEPTION, *objs:object, **kwargs)
# 'trace_back' into log data. (logqueue.get())
```
```python  
logqueue.signal(*objs:object, **kwargs)
logqueue.put_signal(*objs:object, **kwargs)
logqueue.put(LogType.SIGNAL, *objs:object, **kwargs)
# line break when parse().
```

## Parse
```python  
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  

### Parse Formatter
```python
log_formatter = logqueue.get_log_formatter() # 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
```python  
logqueue.clear_log_formatter()
```
Append Formatters
```python  
date_formatter = f"{{{logqueue.LogFormatterKey.date}}}"
time_formatter = f"{{{logqueue.LogFormatterKey.time}}}"
append_log_formatter(date_formatter)
append_log_formatter(time_formatter)
log_formatter = logqueue.get_log_formatter()
# {date} {time}
```
```python  
pid_formatter = logqueue.get_process_id_formatter()
# == f"{{{logqueue.LogFormatterKey.process_id}:0{{{logqueue.LogFormatterKey.process_id_max_length}}}d}}:PID"
file_name_formatter = f"{{{logqueue.LogFormatterKey.file_name}:>{{{logqueue.LogFormatterKey.file_name_length}}}}}"
text = logqueue.get_text_formatter()
logqueue.append_log_formatters(pid_formatter, file_name_formatter, text)
log_formatter = logqueue.get_log_formatter()
# {date} {time} {process_id:0{process_id_max_length}d}:PID {file_name:>{file_name_length}} {text}
```
Replace Formatter
```python  
logqueue.replace_log_formatter(pid_formatter)
log_formatter = logqueue.get_log_formatter()
# {date} {time} {file_name:>{file_name_length}}
```
```python  
logqueue.replace_log_formatter(time_formatter, pid_formatter)
log_formatter = logqueue.get_log_formatter()
# {date} {process_id:0{process_id_max_length}d}:PID {file_name:>{file_name_length}}
```
Change each formatter
```python
logqueue.set_date_formatter("%y-%m-%d")
date_formatter = logqueue.get_date_formatter()
# %y-%m-%d
logqueue.set_process_id_formatter(f"{{{logqueue.LogFormatterKey.process_id}:0{{{logqueue.LogFormatterKey.process_id_max_length}}}d}}:PID")
process_id_formatter = logqueue.get_process_id_formatter()
# {process_id:0{process_id_max_length}d}:PID
```

## Keys
```python
class LogDictKey:
    log_type
    timestamp
    process_id
    thread_id
    cpu_usage
    memory_usage
    file_name
    file_lineno
    text
    trace_back
```
```python
class LogFormatterKey:
    date
    time
    timestamp
    process_id
    process_id_max_length
    thread_id
    thread_id_max_length
    cpu_usage
    cpu_usage_max_length
    memory_usage
    memory_usage_max_length
    log_type
    log_type_max_length
    file_info
    file_name
    file_name_length
    file_lineno
    file_lineno_length
    text
    trace_back
```
            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "logqueue",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "log,log q,log queue,logger,logger q,logger queue,logging,logging q,logging queue,logqueue,queue",
    "author": "",
    "author_email": "Chor <chorong8883@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/c8/47/6cf6eb0cb6a83b1bae7b0b2993483146614d4aced18c55a70d2e110a3d73/logqueue-0.0.4.tar.gz",
    "platform": null,
    "description": "# logqueue\nLog Queue\n\n## Initialize\nDeclare thread function.  \n```python  \ndef logger_function(log_dict):\n    print(log_dict)\n    # ...\n```\nInitialize\n```python  \nimport logqueue\nlogqueue.initialize(logger_function)\n# ...\n```\noutput:  \n{'log_type': 'exception',  \n'timestamp': 1700000000.100001,  \n'process_id': 1234,  \n'thread_id': 1234567890,  \n'cpu_usage': 12, # if exist psutil  \n'memory_usage': 12, # if exist psutil  \n'file_name': 'test.py',  \n'file_lineno': 1,  \n'text': 'start',  \n'trace_back': 'error'} # if exception  \n\n## Close and Join\n```python  \nlogqueue.close()\nlogqueue.join()\n```\nex) Use signal.\n```python  \nimport signal\nimport logqueue\n\ndef signal_handler(_, frame):\n    logqueue.close()\n\nsignal.signal(signal.SIGINT, signal_handler)\nsignal.signal(signal.SIGABRT, signal_handler)\nsignal.signal(signal.SIGTERM, signal_handler)\n\n# ... \nlogqueue.join()\n```\n\n## Logging\n```python  \nlogqueue.put_info(\"start\")\n# or\nlogqueue.info(\"start\")\n```  \n\n### Parameters\nuse user variables\n```python  \nlogqueue.info(\"hi\", alarm_message=\"alarm\", input_database=True)\n```  \n```python \nlog_dict = logqueue.get()\nprint(log_dict)\n```\noutput:  \n{'timestamp': 1700000000.100001,  \n'process_id': 1234,  \n'thread_id': 1234567890,  \n'log_type': 'information',  \n'file_name': 'test.py',  \n'file_lineno': 1,  \n'text': 'hi',  \n'alarm_meesage': \"alarm\", # user variable  \n'input_database': True} # user variable  \n\n### Log types\nBase 'put()'  \n```python  \nlogqueue.put(log_type:str, *objs:object, **kwargs)\n```\n```python  \nlogqueue.info(*objs:object, **kwargs)\nlogqueue.put_info(*objs:object, **kwargs)\nlogqueue.put(LogType.INFORMATION, *objs:object, **kwargs)\n```\n```python  \nlogqueue.debug(*objs:object, **kwargs)\nlogqueue.put_debug(*objs:object, **kwargs)\nlogqueue.put(LogType.DEBUG, *objs:object, **kwargs)\n```\n```python  \nlogqueue.warning(*objs:object, **kwargs)\nlogqueue.put_warning(*objs:object, **kwargs)\nlogqueue.put(LogType.WARNING, *objs:object, **kwargs)\n```\n```python  \nlogqueue.exception(*objs:object, **kwargs)\nlogqueue.put_exception(*objs:object, **kwargs)\nlogqueue.put(LogType.EXCEPTION, *objs:object, **kwargs)\n# 'trace_back' into log data. (logqueue.get())\n```\n```python  \nlogqueue.signal(*objs:object, **kwargs)\nlogqueue.put_signal(*objs:object, **kwargs)\nlogqueue.put(LogType.SIGNAL, *objs:object, **kwargs)\n# line break when parse().\n```\n\n## Parse\n```python  \nlog_str = logqueue.parse(log_dict)\nprint(log_str)\n```\noutput:  \n2023-11-15 07:13:20.100001 12%:CPU 12%:Mem 234:PID 4567890:TID info test.py:1 start  \n\n### Parse Formatter\n```python\nlog_formatter = logqueue.get_log_formatter() # default log formatters\n# {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}\n```\nClear\n```python  \nlogqueue.clear_log_formatter()\n```\nAppend Formatters\n```python  \ndate_formatter = f\"{{{logqueue.LogFormatterKey.date}}}\"\ntime_formatter = f\"{{{logqueue.LogFormatterKey.time}}}\"\nappend_log_formatter(date_formatter)\nappend_log_formatter(time_formatter)\nlog_formatter = logqueue.get_log_formatter()\n# {date} {time}\n```\n```python  \npid_formatter = logqueue.get_process_id_formatter()\n# == f\"{{{logqueue.LogFormatterKey.process_id}:0{{{logqueue.LogFormatterKey.process_id_max_length}}}d}}:PID\"\nfile_name_formatter = f\"{{{logqueue.LogFormatterKey.file_name}:>{{{logqueue.LogFormatterKey.file_name_length}}}}}\"\ntext = logqueue.get_text_formatter()\nlogqueue.append_log_formatters(pid_formatter, file_name_formatter, text)\nlog_formatter = logqueue.get_log_formatter()\n# {date} {time} {process_id:0{process_id_max_length}d}:PID {file_name:>{file_name_length}} {text}\n```\nReplace Formatter\n```python  \nlogqueue.replace_log_formatter(pid_formatter)\nlog_formatter = logqueue.get_log_formatter()\n# {date} {time} {file_name:>{file_name_length}}\n```\n```python  \nlogqueue.replace_log_formatter(time_formatter, pid_formatter)\nlog_formatter = logqueue.get_log_formatter()\n# {date} {process_id:0{process_id_max_length}d}:PID {file_name:>{file_name_length}}\n```\nChange each formatter\n```python\nlogqueue.set_date_formatter(\"%y-%m-%d\")\ndate_formatter = logqueue.get_date_formatter()\n# %y-%m-%d\nlogqueue.set_process_id_formatter(f\"{{{logqueue.LogFormatterKey.process_id}:0{{{logqueue.LogFormatterKey.process_id_max_length}}}d}}:PID\")\nprocess_id_formatter = logqueue.get_process_id_formatter()\n# {process_id:0{process_id_max_length}d}:PID\n```\n\n## Keys\n```python\nclass LogDictKey:\n    log_type\n    timestamp\n    process_id\n    thread_id\n    cpu_usage\n    memory_usage\n    file_name\n    file_lineno\n    text\n    trace_back\n```\n```python\nclass LogFormatterKey:\n    date\n    time\n    timestamp\n    process_id\n    process_id_max_length\n    thread_id\n    thread_id_max_length\n    cpu_usage\n    cpu_usage_max_length\n    memory_usage\n    memory_usage_max_length\n    log_type\n    log_type_max_length\n    file_info\n    file_name\n    file_name_length\n    file_lineno\n    file_lineno_length\n    text\n    trace_back\n```",
    "bugtrack_url": null,
    "license": "",
    "summary": "Log Queue",
    "version": "0.0.4",
    "project_urls": {
        "Homepage": "https://github.com/chorong8883/logqueue"
    },
    "split_keywords": [
        "log",
        "log q",
        "log queue",
        "logger",
        "logger q",
        "logger queue",
        "logging",
        "logging q",
        "logging queue",
        "logqueue",
        "queue"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8a14e3f8b8e3542061c0342e54ca6a58cd8c5a10e6fcc1bd4716d9df1064ba53",
                "md5": "a2928f23a4c3857df5da6d47af4fafd0",
                "sha256": "86debef41962f099e4189531eef1dc0b42d2a399cf08b67da312d4268c836554"
            },
            "downloads": -1,
            "filename": "logqueue-0.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a2928f23a4c3857df5da6d47af4fafd0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 7093,
            "upload_time": "2023-11-09T08:08:54",
            "upload_time_iso_8601": "2023-11-09T08:08:54.858500Z",
            "url": "https://files.pythonhosted.org/packages/8a/14/e3f8b8e3542061c0342e54ca6a58cd8c5a10e6fcc1bd4716d9df1064ba53/logqueue-0.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c8476cf6eb0cb6a83b1bae7b0b2993483146614d4aced18c55a70d2e110a3d73",
                "md5": "46c0b2df595ae1cd5f20e412104d89ee",
                "sha256": "4093c5e20e726ca8dd8b85877614291b4fc1758bc2f6a9cdec2317c95772ea31"
            },
            "downloads": -1,
            "filename": "logqueue-0.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "46c0b2df595ae1cd5f20e412104d89ee",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 7902,
            "upload_time": "2023-11-09T08:08:56",
            "upload_time_iso_8601": "2023-11-09T08:08:56.580776Z",
            "url": "https://files.pythonhosted.org/packages/c8/47/6cf6eb0cb6a83b1bae7b0b2993483146614d4aced18c55a70d2e110a3d73/logqueue-0.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-09 08:08:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "chorong8883",
    "github_project": "logqueue",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "logqueue"
}
        
Elapsed time: 0.18285s