Add Dotfiles Xcode project, with ShellLog target for logging shell stuff to os_log facilities
This commit is contained in:
		
							parent
							
								
									a0cd8f4680
								
							
						
					
					
						commit
						d91d7ca90b
					
				
					 5 changed files with 408 additions and 0 deletions
				
			
		
							
								
								
									
										57
									
								
								Dotfiles/ShellLog/main.swift
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								Dotfiles/ShellLog/main.swift
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,57 @@
 | 
			
		|||
//
 | 
			
		||||
//  main.swift
 | 
			
		||||
//  ShellLog
 | 
			
		||||
//
 | 
			
		||||
//  Created by Eryn Wells on 1/18/22.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
import ArgumentParser
 | 
			
		||||
import OSLog
 | 
			
		||||
 | 
			
		||||
enum Level {
 | 
			
		||||
    case Debug
 | 
			
		||||
    case Info
 | 
			
		||||
    case Warn
 | 
			
		||||
    case Error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extension Level: ExpressibleByArgument {
 | 
			
		||||
    init?(argument: String) {
 | 
			
		||||
        switch (argument) {
 | 
			
		||||
        case "debug":
 | 
			
		||||
            self = .Debug
 | 
			
		||||
        case "info":
 | 
			
		||||
            self = .Info
 | 
			
		||||
        case "warn":
 | 
			
		||||
            self = .Warn
 | 
			
		||||
        case "error":
 | 
			
		||||
            self = .Error
 | 
			
		||||
        default:
 | 
			
		||||
            return nil
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct ShellLog: ParsableCommand {
 | 
			
		||||
 | 
			
		||||
    @Option(name: .shortAndLong, help: "The log level")
 | 
			
		||||
    var level: Level?
 | 
			
		||||
 | 
			
		||||
    @Argument() var message: String
 | 
			
		||||
 | 
			
		||||
    func run() throws {
 | 
			
		||||
        let log = Logger(subsystem: "me.erynwells.shell", category: "Shell")
 | 
			
		||||
        switch level {
 | 
			
		||||
        case .some(.Debug):
 | 
			
		||||
            log.debug("\(message, privacy: .public)")
 | 
			
		||||
        case .none, .some(.Info):
 | 
			
		||||
            log.info("\(message, privacy: .public)")
 | 
			
		||||
        case .some(.Warn):
 | 
			
		||||
            log.warning("\(message, privacy: .public)")
 | 
			
		||||
        case .some(.Error):
 | 
			
		||||
            log.error("\(message, privacy: .public)")
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ShellLog.main()
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue