Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DISABLED log level for Python and Node clients #399

Draft
wants to merge 1 commit into
base: python_node/integ_lotjonat_disable_logging_option
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions node/src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const LEVEL: Map<LevelOptions | undefined, Level | undefined> = new Map([
["trace", Level.Trace],
[undefined, undefined],
]);
type LevelOptions = "error" | "warn" | "info" | "debug" | "trace";
type LevelOptions = "disabled" | "error" | "warn" | "info" | "debug" | "trace";

/*
* A singleton class that allows logging which is consistent with logs from the internal rust core.
Expand All @@ -26,7 +26,7 @@ export class Logger {
private static logger_level = 0;

private constructor(level?: LevelOptions, fileName?: string) {
Logger.logger_level = InitInternalLogger(LEVEL.get(level), fileName);
Logger.logger_level = level == "disabled" ? -1 : InitInternalLogger(LEVEL.get(level), fileName);
}

/**
Expand All @@ -46,6 +46,8 @@ export class Logger {
new Logger();
}

if (logLevel == "disabled") return;

const level = LEVEL.get(logLevel) || 0;
if (!(level <= Logger.logger_level)) return;
log(level, logIdentifier, message);
Expand Down
8 changes: 8 additions & 0 deletions python/python/glide/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


class Level(Enum):
DISABLED = -1
ERROR = internalLevel.Error
WARN = internalLevel.Warn
INFO = internalLevel.Info
Expand All @@ -32,6 +33,9 @@ class Logger:
logger_level: internalLevel

def __init__(self, level: Optional[Level] = None, file_name: Optional[str] = None):
if level and level.value = Level.DISABLED:
Logger.logger_level = level.value
return
level_value = level.value if level else None
Logger.logger_level = py_init(level_value, file_name)

Expand Down Expand Up @@ -63,6 +67,10 @@ def log(cls, log_level: Level, log_identifier: str, message: str):
"""
if not cls._instance:
cls._instance = cls(None)

if log_level.value is Level.DISABLED:
return

if not log_level.value.is_lower(Logger.logger_level):
return
py_log(log_level.value, log_identifier, message)
Expand Down
Loading