-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server-utils): add logging configuration to server_utils to be u…
…sed by servers.
- Loading branch information
Showing
23 changed files
with
521 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"""Common environment data about the robot.""" | ||
|
||
import os | ||
import sys | ||
|
||
from enum import Enum, auto | ||
from typing import Optional | ||
from pathlib import Path | ||
|
||
IS_WIN = sys.platform.startswith("win") | ||
IS_OSX = sys.platform == "darwin" | ||
IS_LINUX = sys.platform.startswith("linux") | ||
IS_ROBOT = bool( | ||
IS_LINUX | ||
and (os.environ.get("RUNNING_ON_PI") or os.environ.get("RUNNING_ON_VERDIN")) | ||
) | ||
#: This is the correct thing to check to see if we’re running on a robot | ||
IS_VIRTUAL = bool(os.environ.get("ENABLE_VIRTUAL_SMOOTHIE")) | ||
|
||
class SystemArchitecture(Enum): | ||
HOST = auto() | ||
BUILDROOT = auto() | ||
YOCTO = auto() | ||
|
||
|
||
class SystemOS(Enum): | ||
WIN = auto() | ||
OSX = auto() | ||
LINUX = auto() | ||
|
||
|
||
OS: SystemOS = SystemOS.LINUX | ||
if IS_WIN: | ||
OS = SystemOS.WIN | ||
elif IS_OSX: | ||
OS = SystemOS.OSX | ||
|
||
ARCHITECTURE: SystemArchitecture = SystemArchitecture.HOST | ||
#: The system architecture running | ||
|
||
OT_SYSTEM_VERSION = "0.0.0" | ||
#: The semver string of the system | ||
|
||
if IS_ROBOT: | ||
if "OT_SYSTEM_VERSION" in os.environ: | ||
OT_SYSTEM_VERSION = os.environ["OT_SYSTEM_VERSION"] | ||
ARCHITECTURE = SystemArchitecture.YOCTO | ||
else: | ||
try: | ||
with open("/etc/VERSION.json") as vj: | ||
contents = json.load(vj) | ||
OT_SYSTEM_VERSION = contents["buildroot_version"] | ||
ARCHITECTURE = SystemArchitecture.BUILDROOT | ||
except Exception: | ||
log.exception("Could not find version file in /etc/VERSION.json") | ||
|
||
|
||
__all__ = [ | ||
"OS", | ||
"SystemOS", | ||
"IS_ROBOT", | ||
"ARCHITECTURE", | ||
"SystemArchitecture", | ||
"OT_SYSTEM_VERSION", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from enum import Enum | ||
|
||
VERBOSE = 10 | ||
|
||
class PackageName(Enum): | ||
"""The types of packages to configure logging""" | ||
ROBOT_SERVER = "robot_server" | ||
SYSTEM_SERVER = "system_server" | ||
UPDATE_SERVER = "otupdate" | ||
HARDWARE_SERVER = "opentrons_hardware" | ||
OT3USBBridge = "ot3usb" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""Logging module used accross servers.""" | ||
|
||
import logging | ||
|
||
from ..constants import VERBOSE | ||
from .config import log_init | ||
|
||
|
||
logging.addLevelName(VERBOSE, "VERBOSE") | ||
|
||
|
||
class Logging(logging.Logger): | ||
def __init__(self, *args, **kwargs): | ||
"""initializer""" | ||
super().__init__(*args, **lwargs) | ||
|
||
def verbose(self, msg: str, *args, **kwargs) -> None: | ||
"""Custom log level for very chatty messages like can logs.""" | ||
if self.isEnabledFor(VERBOSE): | ||
self._log(VERBOSE, msg, args, **kwargs) | ||
|
||
|
||
__all__ = [ | ||
"Logging", | ||
"log_init", | ||
] |
Oops, something went wrong.