@@ -10,6 +10,10 @@ import * as path from "path";
1010import { argv , platform } from "process" ;
1111import { promisify } from "util" ;
1212
13+ import log , { LoggingLevel } from "./core/log.js" ;
14+
15+ const LOG_TAG = "CLI" ;
16+
1317// The name of the directory which will contain the Python virtual environment
1418// used to run the glean-parser.
1519const VIRTUAL_ENVIRONMENT_DIR = ".venv" ;
@@ -100,7 +104,7 @@ function getPythonVenvBinariesPath(venvRoot: string): string {
100104 * is accessible, `false` otherwise.
101105 */
102106async function checkPythonVenvExists ( venvPath : string ) : Promise < boolean > {
103- console . log ( `Checking for a Glean virtual environment at ${ venvPath } ` ) ;
107+ log ( LOG_TAG , `Checking for a Glean virtual environment at ${ venvPath } ` ) ;
104108
105109 const venvPython =
106110 path . join ( getPythonVenvBinariesPath ( venvPath ) , getSystemPythonBinName ( ) ) ;
@@ -124,7 +128,7 @@ async function checkPythonVenvExists(venvPath: string): Promise<boolean> {
124128 * @returns `true` if the environment was correctly created, `false` otherwise.
125129 */
126130async function createPythonVenv ( venvPath : string ) : Promise < boolean > {
127- console . log ( `Creating a Glean virtual environment at ${ venvPath } ` ) ;
131+ log ( LOG_TAG , `Creating a Glean virtual environment at ${ venvPath } ` ) ;
128132
129133 const pipFilename = ( platform === "win32" ) ? "pip3.exe" : "pip3" ;
130134 const venvPip =
@@ -140,10 +144,10 @@ async function createPythonVenv(venvPath: string): Promise<boolean> {
140144 } ) ;
141145
142146 stopSpinner ( spinner ) ;
143- console . log ( `${ stdout } ` ) ;
147+ log ( LOG_TAG , `${ stdout } ` ) ;
144148
145149 if ( err ) {
146- console . error ( `${ stderr } ` ) ;
150+ log ( LOG_TAG , `${ stderr } ` ) ;
147151 return false ;
148152 }
149153 }
@@ -162,9 +166,9 @@ async function setup(projectRoot: string) {
162166
163167 const venvExists = await checkPythonVenvExists ( venvRoot ) ;
164168 if ( venvExists ) {
165- console . log ( `Using Glean virtual environment at ${ venvRoot } ` ) ;
169+ log ( LOG_TAG , `Using Glean virtual environment at ${ venvRoot } ` ) ;
166170 } else if ( ! await createPythonVenv ( venvRoot ) ) {
167- console . error ( `Failed to create a Glean virtual environment at ${ venvRoot } ` ) ;
171+ log ( LOG_TAG , `Failed to create a Glean virtual environment at ${ venvRoot } ` ) ;
168172 process . exit ( 1 ) ;
169173 }
170174}
@@ -186,10 +190,10 @@ async function runGlean(projectRoot: string, parserArgs: string[]) {
186190 });
187191
188192 stopSpinner(spinner);
189- console . log ( `${ stdout } ` ) ;
193+ log(LOG_TAG, ` $ { stdout } `);
190194
191195 if (err) {
192- console . error ( `${ stderr } ` ) ;
196+ log(LOG_TAG, ` $ { stderr } `);
193197 process.exit(1);
194198 }
195199}
@@ -232,7 +236,7 @@ async function run(args: string[]) {
232236 try {
233237 await setup(projectRoot);
234238 } catch (err) {
235- console . error ( "Failed to setup the Glean build environment" , err ) ;
239+ log(LOG_TAG, [ "Failed to setup the Glean build environment.\n ", err], LoggingLevel.Error );
236240 process.exit(1);
237241 }
238242
@@ -241,6 +245,6 @@ async function run(args: string[]) {
241245
242246// For discoverability, try to leave this function as the last one on this file.
243247run(argv).catch(e => {
244- console . error ( "There was an error running Glean" , e ) ;
248+ log(LOG_TAG, [ "There was an error running Glean.\n ", e], LoggingLevel.Error );
245249 process . exit ( 1 ) ;
246250} ) ;
0 commit comments