Skip to content

Commit

Permalink
release 4.23.21108
Browse files Browse the repository at this point in the history
  • Loading branch information
klahnakoski committed Apr 18, 2021
2 parents ebf0c47 + c76832b commit 8bc5c00
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.idea
*.iml
vendor
/mo_logs/__pycache__
26 changes: 18 additions & 8 deletions mo_logs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from __future__ import absolute_import, division, unicode_literals

import os
import platform
import sys
from datetime import datetime

Expand Down Expand Up @@ -414,7 +413,6 @@ def _annotate(cls, item, timestamp, stack_depth):
:return:
"""
item.timestamp = timestamp
item.machine = machine_metadata
item.template = strings.limit(item.template, 10000)

item.format = strings.limit(item.format, 10000)
Expand All @@ -426,6 +424,7 @@ def _annotate(cls, item, timestamp, stack_depth):
format = CR + format

if cls.trace:
item.machine = machine_metadata()
log_format = item.format = (
"{{machine.name}} (pid {{machine.pid}}) - {{timestamp|datetime}} -"
' {{thread.name}} - "{{location.file}}:{{location.line}}" -'
Expand Down Expand Up @@ -477,12 +476,23 @@ def _same_frame(frameA, frameB):


# GET THE MACHINE METADATA
machine_metadata = dict_to_data({
"pid": os.getpid(),
"python": text(platform.python_implementation()),
"os": text(platform.system() + platform.release()).strip(),
"name": text(platform.node()),
})
_machine_metadata = None


def machine_metadata():
global _machine_metadata
if _machine_metadata:
return _machine_metadata

import platform

_machine_metadata = dict_to_data({
"pid": os.getpid(),
"python": text(platform.python_implementation()),
"os": text(platform.system() + platform.release()).strip(),
"name": text(platform.node()),
})
return _machine_metadata


def raise_from_none(e):
Expand Down
14 changes: 6 additions & 8 deletions mo_logs/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@

from __future__ import absolute_import, division, unicode_literals

import cgi
import json as _json
import math
import re
import string
from datetime import date, datetime as builtin_datetime, timedelta
from json.encoder import encode_basestring

from mo_dots import (
Data,
coalesce,
get_module,
is_data,
is_list,
to_data,
Expand Down Expand Up @@ -61,8 +58,10 @@ def _late_import():
global _Duration

try:
from mo_dots import get_module

_json_encoder = get_module("mo_json.encoder").json_encoder
except Exception:
except Exception as cause:
_json_encoder = lambda value, pretty: _json.dumps(value)
from mo_logs import Log as _Log
from mo_logs.exceptions import Except as _Except
Expand Down Expand Up @@ -158,6 +157,8 @@ def html(value):
"""
convert FROM unicode TO HTML OF THE SAME
"""
import cgi

return cgi.escape(value)


Expand Down Expand Up @@ -502,10 +503,7 @@ def quote(value):
"""
if value == None:
output = ""
elif is_text(value):
output = encode_basestring(value)
else:
output = _json.dumps(value)
output = _json.dumps(value)
return output


Expand Down

0 comments on commit 8bc5c00

Please sign in to comment.