use stderr for logging
This commit is contained in:
		
							
								
								
									
										12
									
								
								src/index.js
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/index.js
									
									
									
									
									
								
							@@ -17,29 +17,29 @@ const LogLevels = {
 | 
			
		||||
let logLevel = LogLevels.error;
 | 
			
		||||
function timestamp() {
 | 
			
		||||
  const d = new Date().toISOString();
 | 
			
		||||
  return [d.substr(5, 5), d.substr(11, 8)].join(' ')
 | 
			
		||||
  return [d.slice(5, 5), d.slice(11, 8)].join(' ')
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class Logger {
 | 
			
		||||
  debug(...args) {
 | 
			
		||||
    if (LogLevels.debug > logLevel) return;
 | 
			
		||||
    const [format, ...rest] = args;
 | 
			
		||||
    console.debug(timestamp(), "D", util.format(format, ...rest));
 | 
			
		||||
    console.error(timestamp(), "D", util.format(format, ...rest));
 | 
			
		||||
  }
 | 
			
		||||
  info(...args) {
 | 
			
		||||
    if (LogLevels.info > logLevel) return;
 | 
			
		||||
    const [format, ...rest] = args;
 | 
			
		||||
    console.debug(timestamp(), "I", util.format(format, ...rest));
 | 
			
		||||
    console.error(timestamp(), "I", util.format(format, ...rest));
 | 
			
		||||
  }
 | 
			
		||||
  warn(...args) {
 | 
			
		||||
    if (LogLevels.warn > logLevel) return;
 | 
			
		||||
    const [format, ...rest] = args;
 | 
			
		||||
    console.debug(timestamp(), "W", util.format(format, ...rest));
 | 
			
		||||
    console.error(timestamp(), "W", util.format(format, ...rest));
 | 
			
		||||
  }
 | 
			
		||||
  error(...args) {
 | 
			
		||||
    if (LogLevels.error > logLevel) return;
 | 
			
		||||
    const [format, ...rest] = args;
 | 
			
		||||
    console.debug(timestamp(), "E", util.format(format, ...rest));
 | 
			
		||||
    console.error(timestamp(), "E", util.format(format, ...rest));
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -139,7 +139,7 @@ class Logger {
 | 
			
		||||
    /** @type TorStream */
 | 
			
		||||
    let tor_stream;
 | 
			
		||||
    if (uri.hostname.endsWith('.onion')) {
 | 
			
		||||
      const onion = uri.hostname.substr(0, uri.hostname.length - 6);
 | 
			
		||||
      const onion = uri.hostname.slice(0, uri.hostname.length - 6);
 | 
			
		||||
      tor_stream = await circuit.create_onion_stream(onion, uri.port);
 | 
			
		||||
    } else {
 | 
			
		||||
      tor_stream = await circuit.create_stream(uri.hostname, uri.port);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user