mirror of
				https://git.hibas.dev/OpenServer/NodeLogging.git
				synced 2025-11-03 22:40:45 +00:00 
			
		
		
		
	platform independant filename extraction
This commit is contained in:
		
							
								
								
									
										14
									
								
								src/index.ts
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								src/index.ts
									
									
									
									
									
								
							@ -1,6 +1,7 @@
 | 
			
		||||
import * as util from "util";
 | 
			
		||||
import * as fs from "fs";
 | 
			
		||||
import { EventEmitter } from "events";
 | 
			
		||||
import * as path from "path";
 | 
			
		||||
 | 
			
		||||
const Reset = "\x1b[0m"
 | 
			
		||||
const Bright = "\x1b[1m"
 | 
			
		||||
@ -68,7 +69,7 @@ export class Logging {
 | 
			
		||||
      }
 | 
			
		||||
      let m = "";
 | 
			
		||||
      (<any>error.stack).forEach(e => {
 | 
			
		||||
         m += e.toString() + "\n";
 | 
			
		||||
         m += e.toString() + " | ";
 | 
			
		||||
      })
 | 
			
		||||
      var message = error.name + " " + error.message + "\n" + m;
 | 
			
		||||
      Logging.message(LoggingTypes.Error, [message]);
 | 
			
		||||
@ -168,9 +169,9 @@ export class Logging {
 | 
			
		||||
         });
 | 
			
		||||
 | 
			
		||||
         Logging.fileStream = fs.createWriteStream(this.logFileLocation + "all.log", { flags: "a" });
 | 
			
		||||
         Logging.fileStream.write("\n\n");
 | 
			
		||||
         Logging.fileStream.write("\n");
 | 
			
		||||
         Logging.errorStream = fs.createWriteStream(this.logFileLocation + "error.log", { flags: "a" });
 | 
			
		||||
         Logging.errorStream.write("\n\n");
 | 
			
		||||
         Logging.errorStream.write("\n");
 | 
			
		||||
      } catch (e) {
 | 
			
		||||
         console.log(e);
 | 
			
		||||
      }
 | 
			
		||||
@ -189,11 +190,8 @@ function _getCallerFile() {
 | 
			
		||||
 | 
			
		||||
      while (err.stack.length) {
 | 
			
		||||
         caller_file = (<any>err.stack).shift().getFileName();
 | 
			
		||||
 | 
			
		||||
         if (current_file !== caller_file) {
 | 
			
		||||
            let array = caller_file.split("/")
 | 
			
		||||
            return array[array.length - 1];
 | 
			
		||||
         }
 | 
			
		||||
         console.log(caller_file);
 | 
			
		||||
         if (current_file !== caller_file) return path.basename(caller_file);
 | 
			
		||||
      }
 | 
			
		||||
   } catch (err) { }
 | 
			
		||||
   return undefined;
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user