Unverified Commit ba8f3af3 authored by SparkSnail's avatar SparkSnail Committed by GitHub
Browse files

Support setting dispatcher log level (#820)

parent 01d609a2
...@@ -44,6 +44,11 @@ function getLogDir(): string{ ...@@ -44,6 +44,11 @@ function getLogDir(): string{
return path.join(getExperimentRootDir(), 'log'); return path.join(getExperimentRootDir(), 'log');
} }
function getLogLevel(): string{
return getExperimentStartupInfo()
.getLogLevel();
}
function getDefaultDatabaseDir(): string { function getDefaultDatabaseDir(): string {
return path.join(getExperimentRootDir(), 'db'); return path.join(getExperimentRootDir(), 'db');
} }
...@@ -360,4 +365,4 @@ async function getVersion(): Promise<string> { ...@@ -360,4 +365,4 @@ async function getVersion(): Promise<string> {
export {countFilesRecursively, getRemoteTmpDir, generateParamFileName, getMsgDispatcherCommand, getCheckpointDir, export {countFilesRecursively, getRemoteTmpDir, generateParamFileName, getMsgDispatcherCommand, getCheckpointDir,
getLogDir, getExperimentRootDir, getJobCancelStatus, getDefaultDatabaseDir, getIPV4Address, getLogDir, getExperimentRootDir, getJobCancelStatus, getDefaultDatabaseDir, getIPV4Address,
mkDirP, delay, prepareUnitTest, parseArg, cleanupUnitTest, uniqueString, randomSelect, getVersion }; mkDirP, delay, prepareUnitTest, parseArg, cleanupUnitTest, uniqueString, randomSelect, getLogLevel, getVersion };
...@@ -35,7 +35,7 @@ import { ...@@ -35,7 +35,7 @@ import {
import { import {
TrainingService, TrialJobApplicationForm, TrialJobDetail, TrialJobMetric, TrialJobStatus TrainingService, TrialJobApplicationForm, TrialJobDetail, TrialJobMetric, TrialJobStatus
} from '../common/trainingService'; } from '../common/trainingService';
import { delay, getCheckpointDir, getExperimentRootDir, getLogDir, getMsgDispatcherCommand, mkDirP } from '../common/utils'; import { delay, getCheckpointDir, getExperimentRootDir, getLogDir, getMsgDispatcherCommand, mkDirP, getLogLevel } from '../common/utils';
import { import {
ADD_CUSTOMIZED_TRIAL_JOB, INITIALIZE, INITIALIZED, KILL_TRIAL_JOB, NEW_TRIAL_JOB, NO_MORE_TRIAL_JOBS, PING, ADD_CUSTOMIZED_TRIAL_JOB, INITIALIZE, INITIALIZED, KILL_TRIAL_JOB, NEW_TRIAL_JOB, NO_MORE_TRIAL_JOBS, PING,
REPORT_METRIC_DATA, REQUEST_TRIAL_JOBS, SEND_TRIAL_JOB_PARAMETER, TERMINATE, TRIAL_END, UPDATE_SEARCH_SPACE REPORT_METRIC_DATA, REQUEST_TRIAL_JOBS, SEND_TRIAL_JOB_PARAMETER, TERMINATE, TRIAL_END, UPDATE_SEARCH_SPACE
...@@ -276,7 +276,8 @@ class NNIManager implements Manager { ...@@ -276,7 +276,8 @@ class NNIManager implements Manager {
let nniEnv = { let nniEnv = {
NNI_MODE: mode, NNI_MODE: mode,
NNI_CHECKPOINT_DIRECTORY: dataDirectory, NNI_CHECKPOINT_DIRECTORY: dataDirectory,
NNI_LOG_DIRECTORY: getLogDir() NNI_LOG_DIRECTORY: getLogDir(),
NNI_LOG_LEVEL: getLogLevel()
}; };
let newEnv = Object.assign({}, process.env, nniEnv); let newEnv = Object.assign({}, process.env, nniEnv);
const tunerProc: ChildProcess = spawn(command, [], { const tunerProc: ChildProcess = spawn(command, [], {
......
...@@ -34,12 +34,20 @@ def _load_env_args(): ...@@ -34,12 +34,20 @@ def _load_env_args():
'trial_job_id': os.environ.get('NNI_TRIAL_JOB_ID'), 'trial_job_id': os.environ.get('NNI_TRIAL_JOB_ID'),
'log_dir': os.environ.get('NNI_LOG_DIRECTORY'), 'log_dir': os.environ.get('NNI_LOG_DIRECTORY'),
'role': os.environ.get('NNI_ROLE'), 'role': os.environ.get('NNI_ROLE'),
'log_level': os.environ.get('NNI_LOG_LEVEL')
} }
return namedtuple('EnvArgs', args.keys())(**args) return namedtuple('EnvArgs', args.keys())(**args)
env_args = _load_env_args() env_args = _load_env_args()
'''Arguments passed from environment''' '''Arguments passed from environment'''
logLevelMap = {
'fatal': logging.FATAL,
'error': logging.ERROR,
'warning': logging.WARNING,
'info': logging.INFO,
'debug': logging.DEBUG
}
_time_format = '%m/%d/%Y, %I:%M:%S %P' _time_format = '%m/%d/%Y, %I:%M:%S %P'
class _LoggerFileWrapper(TextIOBase): class _LoggerFileWrapper(TextIOBase):
...@@ -53,7 +61,6 @@ class _LoggerFileWrapper(TextIOBase): ...@@ -53,7 +61,6 @@ class _LoggerFileWrapper(TextIOBase):
self.file.flush() self.file.flush()
return len(s) return len(s)
def init_logger(logger_file_path): def init_logger(logger_file_path):
"""Initialize root logger. """Initialize root logger.
This will redirect anything from logging.getLogger() as well as stdout to specified file. This will redirect anything from logging.getLogger() as well as stdout to specified file.
...@@ -63,6 +70,12 @@ def init_logger(logger_file_path): ...@@ -63,6 +70,12 @@ def init_logger(logger_file_path):
logger_file_path = 'unittest.log' logger_file_path = 'unittest.log'
elif env_args.log_dir is not None: elif env_args.log_dir is not None:
logger_file_path = os.path.join(env_args.log_dir, logger_file_path) logger_file_path = os.path.join(env_args.log_dir, logger_file_path)
if env_args.log_level and logLevelMap.get(env_args.log_level):
log_level = logLevelMap[env_args.log_level]
else:
log_level = logging.INFO #default log level is INFO
logger_file = open(logger_file_path, 'w') logger_file = open(logger_file_path, 'w')
fmt = '[%(asctime)s] %(levelname)s (%(name)s/%(threadName)s) %(message)s' fmt = '[%(asctime)s] %(levelname)s (%(name)s/%(threadName)s) %(message)s'
logging.Formatter.converter = time.localtime logging.Formatter.converter = time.localtime
...@@ -72,10 +85,10 @@ def init_logger(logger_file_path): ...@@ -72,10 +85,10 @@ def init_logger(logger_file_path):
root_logger = logging.getLogger() root_logger = logging.getLogger()
root_logger.addHandler(handler) root_logger.addHandler(handler)
root_logger.setLevel(logging.DEBUG) root_logger.setLevel(log_level)
# these modules are too verbose # these modules are too verbose
logging.getLogger('matplotlib').setLevel(logging.INFO) logging.getLogger('matplotlib').setLevel(log_level)
sys.stdout = _LoggerFileWrapper(logger_file) sys.stdout = _LoggerFileWrapper(logger_file)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment