This commit is contained in:
2025-08-20 05:06:05 +02:00
parent c9a45d3435
commit b3c389e666
5 changed files with 34 additions and 40 deletions

View File

@@ -14,7 +14,7 @@ has some usefull stuff as well
## Installation ## Installation
You can install `herolib` directly from the Git repository using `uv pip` (or `pip`): You can install `herolib` directly from the Git repository using `uv pip`:
```bash ```bash
uv pip install git+https://git.ourworld.tf/herocode/herolib_python.git uv pip install git+https://git.ourworld.tf/herocode/herolib_python.git
@@ -36,6 +36,10 @@ import herolib.core.loghandler.mylogging
from herolib.core.loghandler.mylogging import MyLogger from herolib.core.loghandler.mylogging import MyLogger
``` ```
## how to integrate python in other projects
see [Python Herolib Integration](pythonsetup/README.md)
## Version Control ## Version Control
This library follows standard Git version control practices. Releases can be managed by tagging specific commits in the Git repository. Users installing directly from the Git URL can specify a particular branch, tag, or commit hash to get a specific version. For example: This library follows standard Git version control practices. Releases can be managed by tagging specific commits in the Git repository. Users installing directly from the Git URL can specify a particular branch, tag, or commit hash to get a specific version. For example:

View File

@@ -24,7 +24,7 @@ def search(l: Logger, args_: SearchArgs) -> List[LogItem]:
raise ValueError('category cannot be longer than 10 chars') raise ValueError('category cannot be longer than 10 chars')
from_time = args.timestamp_from.unix() if args.timestamp_from else 0 from_time = args.timestamp_from.unix() if args.timestamp_from else 0
to_time = args.timestamp_to.unix() if args.timestamp_to else ourtime_new('2100-01-01').unix() to_time = args.timestamp_to.unix() + 1 if args.timestamp_to else ourtime_new('2100-01-01').unix()
if from_time > to_time: if from_time > to_time:
raise ValueError(f'from_time cannot be after to_time: {from_time} > {to_time}') raise ValueError(f'from_time cannot be after to_time: {from_time} > {to_time}')
@@ -62,52 +62,41 @@ def search(l: Logger, args_: SearchArgs) -> List[LogItem]:
if len(result) >= args.maxitems: if len(result) >= args.maxitems:
break break
if not line.strip() and current_item: # Helper to add current_item to result if it matches criteria
if from_time <= current_item.timestamp.unix() <= to_time: def _add_item_if_matches():
if (not args.cat or args.cat == current_item.cat) and \ nonlocal current_item
(not args.log or args.log.lower() in current_item.log.lower()) and \
(args.logtype is None or args.logtype == current_item.logtype):
result.append(current_item)
current_item = None
continue
if not line.startswith(' ') and not line.startswith('E'):
if current_item: if current_item:
if from_time <= current_item.timestamp.unix() <= to_time: if from_time <= current_item.timestamp.unix() <= to_time:
if (not args.cat or args.cat == current_item.cat) and \ if (not args.cat or args.cat == current_item.cat) and \
(not args.log or args.log.lower() in current_item.log.lower()) and \ (not args.log or args.log.lower() in current_item.log.lower()) and \
(args.logtype is None or args.logtype == current_item.logtype): (args.logtype is None or args.logtype == current_item.logtype):
result.append(current_item) result.append(current_item)
current_item = None # Reset after processing
if not line.strip(): # Empty line, finalize previous item
_add_item_if_matches()
continue
if not line.startswith(' ') and not line.startswith('E'): # New timestamp line
_add_item_if_matches() # Finalize previous item
try: try:
current_time = ourtime_new(f"{file_time.day()} {line.strip()}") current_time = ourtime_new(f"{file_time.day()} {line.strip()}")
current_item = None
except ValueError: except ValueError:
current_time = None current_time = None
current_item = None current_item = None # Reset for new item
elif current_time: elif current_time:
if line.startswith(' ') or line.startswith('E'): if len(line) > 14 and line[13] == '-': # New log entry line
if len(line) > 14 and line[13] == '-': _add_item_if_matches() # Finalize previous item
if current_item:
if from_time <= current_item.timestamp.unix() <= to_time: is_error = line.startswith('E')
if (not args.cat or args.cat == current_item.cat) and \ logtype = LogType.ERROR if is_error else LogType.STDOUT
(not args.log or args.log.lower() in current_item.log.lower()) and \ cat = line[2:12].strip()
(args.logtype is None or args.logtype == current_item.logtype): log_content = line[15:]
result.append(current_item)
is_error = line.startswith('E')
logtype = LogType.ERROR if is_error else LogType.STDOUT
cat = line[2:12].strip()
log_content = line[15:]
current_item = LogItem(timestamp=current_time, cat=cat, log=log_content.strip(), logtype=logtype) current_item = LogItem(timestamp=current_time, cat=cat, log=log_content.strip(), logtype=logtype)
elif current_item: elif current_item: # Continuation line
current_item.log += "\n" + (line[15:] if len(line) >15 else line) current_item.log += "\n" + (line[15:] if len(line) >15 else line)
if current_item: _add_item_if_matches() # Finalize the last item in the file
if from_time <= current_item.timestamp.unix() <= to_time:
if (not args.cat or args.cat == current_item.cat) and \
(not args.log or args.log.lower() in current_item.log.lower()) and \
(args.logtype is None or args.logtype == current_item.logtype):
result.append(current_item)
return result return result

View File

@@ -93,6 +93,7 @@ def new(time_str: str) -> OurTime:
'%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M:%S',
'%Y-%m-%d %H:%M', '%Y-%m-%d %H:%M',
'%Y-%m-%d %H', '%Y-%m-%d %H',
'%Y-%m-%d-%H', # Add this format for dayhour parsing
'%Y-%m-%d', '%Y-%m-%d',
'%d-%m-%Y %H:%M:%S', '%d-%m-%Y %H:%M:%S',
'%d-%m-%Y %H:%M', '%d-%m-%Y %H:%M',