Skip to content

Commit

Permalink
fixed CM logger issue
Browse files Browse the repository at this point in the history
  • Loading branch information
gfursin committed Nov 3, 2024
1 parent 675140c commit 1ed4c44
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
3 changes: 3 additions & 0 deletions cm/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## V3.3.3
- fixed CM logger issue

## V3.3.2
- moved "CMX stack error" to -log
- improved error reporting
Expand Down
2 changes: 1 addition & 1 deletion cm/cmind/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Written by Grigori Fursin

__version__ = "3.3.2"
__version__ = "3.3.3"

from cmind.core import access
from cmind.core import x
Expand Down
26 changes: 13 additions & 13 deletions cm/cmind/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def __init__(self, repos_path = '', debug = False):

# Logging
self.logger = None
self.xlogger = None

# Index
self.index = None
Expand Down Expand Up @@ -172,18 +173,18 @@ def errorx(self, r):

message = ''

if not self.logger == None or (module_path != '' and lineno != ''):
if not self.xlogger == None or (module_path != '' and lineno != ''):
call_stack = self.state.get('call_stack', [])

if not self.logger == None:
if not self.xlogger == None:

self.log(f"x error call stack: {call_stack}", "debug")
self.log(f"x error: {r}", "debug")

# sys.stderr.write('^'*60 + '\n')
sys.stderr.write('\n')

if not self.logger == None:
if not self.xlogger == None:
sys.stderr.write('CMX call stack:\n')

for cs in call_stack:
Expand Down Expand Up @@ -296,7 +297,7 @@ def log(self, s, t = 'info'):
None
"""

logger = self.logger
logger = self.xlogger

if logger != None:
if t == 'debug':
Expand Down Expand Up @@ -353,10 +354,9 @@ def access(self, i, out = None):
if self.cfg['flag_debug'] in i:
self.debug = True

# Not used in CM but used in CMX
# # Check if log
# if self.logger is None:
# self.logger = logging.getLogger("cm")
# Check if log
if self.logger is None:
self.logger = logging.getLogger("cm")

# Parse as command line if string or list
if type(i) == str or type(i) == list:
Expand Down Expand Up @@ -905,7 +905,7 @@ def x(self, i, out = None):
meta = ii)

# Check logging
if self.logger is None:
if self.xlogger is None:
log_level = None

if use_log == "false":
Expand All @@ -931,7 +931,7 @@ def x(self, i, out = None):
log_level = logging.INFO

# Configure
self.logger = logging.getLogger("cmx")
self.xlogger = logging.getLogger("cmx")
logging.basicConfig(filename = log_file, filemode = 'w', level = log_level)

# Check if force out programmatically (such as from CLI)
Expand All @@ -944,7 +944,7 @@ def x(self, i, out = None):
recursion = self.state.get('recursion', 0)
self.state['recursion'] = recursion + 1

if not self.logger == None:
if not self.xlogger == None:
log_action = i.get('action', '')
log_automation = i.get('automation', '')
log_artifact = i.get('artifact', '')
Expand All @@ -968,7 +968,7 @@ def x(self, i, out = None):
r['return'] = 1
r['error'] = delayed_error

if not self.logger == None:
if not self.xlogger == None:
self.log(f"x output: {r}", "debug")

self.state['recursion'] = recursion
Expand Down Expand Up @@ -1343,7 +1343,7 @@ def _x(self, i, control):
loaded_common_automation = True

# Finalize automation class initialization
if not self.logger == None:
if not self.xlogger == None:
self.log(f"x automation_full_path: {automation_full_path}", "info")

initialized_automation = loaded_automation_class(self, automation_full_path)
Expand Down
4 changes: 2 additions & 2 deletions cm/cmind/repo/automation/repo/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ def pull(self, i):

warnings = []

if not self.cmind.logger == None:
self.cmind.log(f"x repo log: {pull_repos}", "debug")
# if not self.cmind.xlogger == None:
# self.cmind.log(f"x repo log: {pull_repos}", "debug")

for repo in pull_repos:
alias = repo['alias']
Expand Down

0 comments on commit 1ed4c44

Please sign in to comment.