-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(logging)_: enable log namespaces configuration (#6161)
closes: #6128
- Loading branch information
Showing
13 changed files
with
159 additions
and
17 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
appdatabase/migrations/sql/1732905829_add_log_namespaces.up.sql
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 @@ | ||
ALTER TABLE log_config ADD COLUMN log_namespaces VARCHAR DEFAULT ''; |
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
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,11 @@ | ||
package requests | ||
|
||
import "github.com/status-im/status-go/logutils" | ||
|
||
type SetLogNamespaces struct { | ||
LogNamespaces string `json:"logNamespaces"` | ||
} | ||
|
||
func (c *SetLogNamespaces) Validate() error { | ||
return logutils.ValidateNamespaces(c.LogNamespaces) | ||
} |
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,63 @@ | ||
import re | ||
import time | ||
from test_cases import StatusBackend | ||
import pytest | ||
import os | ||
|
||
@pytest.mark.rpc | ||
@pytest.mark.skip("waiting for status-backend to be executed on the same host/container") | ||
class TestLogging: | ||
|
||
@pytest.mark.init | ||
def test_logging(self, tmp_path): | ||
await_signals = [ | ||
"mediaserver.started", | ||
"node.started", | ||
"node.ready", | ||
"node.login", | ||
] | ||
|
||
backend_client = StatusBackend(await_signals) | ||
assert backend_client is not None | ||
|
||
# Init and login | ||
backend_client.init_status_backend(data_dir=str(tmp_path)) | ||
backend_client.create_account_and_login(data_dir=str(tmp_path)) | ||
key_uid = self.ensure_logged_in(backend_client) | ||
|
||
# Configure logging | ||
backend_client.rpc_valid_request("wakuext_setLogLevel", [{"logLevel": "ERROR"}]) | ||
backend_client.rpc_valid_request("wakuext_setLogNamespaces", [{"logNamespaces": "test1.test2:debug,test1.test2.test3:info"}]) | ||
|
||
# Re-login (logging settings take effect after re-login) | ||
backend_client.logout() | ||
backend_client.login(str(key_uid)) | ||
self.ensure_logged_in(backend_client) | ||
|
||
# Test logging | ||
backend_client.rpc_valid_request("wakuext_logTest") | ||
self.expect_logs(tmp_path / "geth.log", "test message", [ | ||
r"DEBUG\s+test1\.test2", | ||
r"INFO\s+test1\.test2", | ||
r"INFO\s+test1\.test2\.test3", | ||
r"WARN\s+test1\.test2", | ||
r"WARN\s+test1\.test2\.test3", | ||
r"ERROR\s+test1", | ||
r"ERROR\s+test1\.test2", | ||
r"ERROR\s+test1\.test2\.test3", | ||
]) | ||
|
||
def expect_logs(self, log_file, filter_keyword, expected_logs): | ||
with open(log_file, 'r') as f: | ||
log_content = f.read() | ||
|
||
filtered_logs = [line for line in log_content.splitlines() if filter_keyword in line] | ||
for expected_log in expected_logs: | ||
assert any(re.search(expected_log, log) for log in filtered_logs), f"Log entry not found: {expected_log}" | ||
|
||
def ensure_logged_in(self, backend_client): | ||
login_response = backend_client.wait_for_signal("node.login") | ||
backend_client.verify_json_schema(login_response, "signal_node_login") | ||
key_uid = login_response.get("event", {}).get("account", {}).get("key-uid") | ||
assert key_uid is not None, "key-uid not found in login response" | ||
return key_uid |