function set_log($log = false, $log_file = '', $log_format = 'text', $log_now = false, $log_reset = true) { $this->log = $log; if ($this->log) { log::$log_file = $log_file; log::$log_format = $log_format; log::$log_now = $log_now; if ($log_reset) { log::reset(); } } }
function __construct($configs = array()) { // 先打开以显示验证报错内容 log::$log_show = true; log::$log_file = isset(self::$configs['log_file']) ? self::$configs['log_file'] : PATH_DATA . '/phpspider.log'; // 彩蛋 $included_files = get_included_files(); $content = file_get_contents($included_files[0]); if (!preg_match("#/\\* Do NOT delete this comment \\*/#", $content) || !preg_match("#/\\* 不要删除这段注释 \\*/#", $content)) { log::error("未知错误;请参考文档或寻求技术支持。"); exit; } self::$configs = $configs; self::$configs['name'] = isset(self::$configs['name']) ? self::$configs['name'] : 'phpspider'; self::$configs['proxy'] = isset(self::$configs['proxy']) ? self::$configs['proxy'] : ''; self::$configs['user_agent'] = isset(self::$configs['user_agent']) ? self::$configs['user_agent'] : self::AGENT_PC; self::$configs['interval'] = isset(self::$configs['interval']) ? self::$configs['interval'] : self::INTERVAL; self::$configs['timeout'] = isset(self::$configs['timeout']) ? self::$configs['timeout'] : self::TIMEOUT; self::$configs['max_try'] = isset(self::$configs['max_try']) ? self::$configs['max_try'] : self::MAX_TRY; self::$configs['export'] = isset(self::$configs['export']) ? self::$configs['export'] : array(); // csv、sql、db self::$export_type = isset(self::$configs['export']['type']) ? self::$configs['export']['type'] : ''; self::$export_file = isset(self::$configs['export']['file']) ? self::$configs['export']['file'] : ''; self::$export_table = isset(self::$configs['export']['table']) ? self::$configs['export']['table'] : ''; // 是否设置了并发任务数,并且大于1,而且不是windows环境 if (isset(self::$configs['tasknum']) && self::$configs['tasknum'] > 1 && !util::is_win()) { self::$tasknum = self::$configs['tasknum']; } // 是否设置了保留运行状态 if (isset(self::$configs['save_running_state'])) { self::$save_running_state = self::$configs['save_running_state']; } // 不同项目的采集以采集名称作为前缀区分 if (isset($GLOBALS['config']['redis']['prefix'])) { $GLOBALS['config']['redis']['prefix'] = $GLOBALS['config']['redis']['prefix'] . '-' . md5(self::$configs['name']); } }
public static function init($dir, $file) { self::$log_dir = $dir; self::$log_file = $file; }