Skip to content

Commit

Permalink
Add the example usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
xingheng committed Mar 28, 2021
1 parent d2d9ec5 commit 2e1eeb5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
5 changes: 4 additions & 1 deletion CLILoggerClient/CLILoggerClient/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ client.log("See", "you", "next", "time!")
#else
DDLog.add(CLILogger.shared)

DDLogVerbose("Hello!")
DDLogDebug("This is \(Host.current().name ?? "a guest")")
DDLogVerbose("See you!")
DDLogInfo("The default internal log level is INFO")
DDLogWarn("Warn me if something wrong you encounter")
DDLogError("Remember to attach the error context verbosely")
#endif
RunLoop.main.run()

2 changes: 1 addition & 1 deletion CLILoggerServer/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
CLILogger: 54effa34b0b6762c244ea0ec19d6ec6461fb83c9
CLILogger: a579e5cfbcb0549518afcf027a079430e57a989d
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
CocoaLumberjack: e8955b9d337ac307103b0a34fd141c32f27e53c5
RainbowSwift: 97eea9ffebcfeb9f9c3a4c0cabf9ff2684c2b588
Expand Down
41 changes: 28 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# CLILogger

A logging utility like [NSLogger](https://github.com/fpillet/NSLogger) but based on command line viewer.

![example](./Resources/example.png)

## Server

Expand Down Expand Up @@ -28,7 +30,7 @@ OPTIONS:
##### Installation

```ruby
pod 'CLILogger',, :configurations => ['Debug'], :git => 'https://github.com/CLILogger/CLILogger', :branch => 'master'
pod 'CLILogger', :configurations => ['Debug'], :git => 'https://github.com/CLILogger/CLILogger', :branch => 'master'
```

> It still stays in alpha stage but it’s ready for common usages, I’ll be careful for `master`. :)
Expand Down Expand Up @@ -79,11 +81,8 @@ When starting to search the local logging bonjour service, make sure the logging

Support to forward the log messages to CLILoggingClient easily, take the log filename without extension as module name.

```objective-c

NSString *module = logMessage->_file.lastPathComponent.stringByDeletingPathExtension;
CLILoggingEntity *entity = [[CLILoggingEntity alloc] initWithMessage:message flag:logMessage->_flag module:module];
[CLILoggingClient.shared logWithEntity:entity];
```swift
DDLog.add(CLILogger.shared)
```

It's highly recommended you integrate it with `CococaLumberjack` since we use the `DDLogFlag` type as message flag and `DDLog` functions to trace internal logs inside, too.
Expand All @@ -92,19 +91,15 @@ It's highly recommended you integrate it with `CococaLumberjack` since we use th

## Technology

`cli-logger` starts a tcp server with specified name and port for reading all the incoming clients’ arranged data (called `entity` internally),
`cli-logger` starts a tcp server with specified name and port for reading all the incoming clients’ arranged data (called `entity` internally), once receiving the data message from client, it will output the formatted message in console.

Try to discover the logging bonjour service via [Discovery for macOS](https://apps.apple.com/app/discovery-dns-sd-browser/id1381004916?mt=12), [Discovery for iOS](https://apps.apple.com/app/discovery-dns-sd-browser/id305441017) or `dns-sd`:

```bash
➜ dns-sd -B _cli-logger-server._tcp.
```


`CLILogger` in client side try to search the fixed tcp type in domain `local.`, once the connection established successfully, it waits the log message when calling `log(:entity:)` of `CLILoggingClient`, note that there is a pending message queue inside used to cache the messages when *connection to logging service is not established*, they will be cleaned up one by one after the connection is available. Don’t doubt the message date you see in console output, that’s the time generated from client’s logger exactly.



Expand All @@ -121,13 +116,33 @@ For iOS 14, bonjour service on local network is disabled by default, adding the
</array>
```

Otherwise you will [get error](https://developer.apple.com/forums/thread/653316) `["NSNetServicesErrorDomain": 10, "NSNetServicesErrorCode": -72000]`.
Otherwise you will [get this error](https://developer.apple.com/forums/thread/653316):

````
["NSNetServicesErrorDomain": 10, "NSNetServicesErrorCode": -72000]
````



#### Differences [NSLogger](https://github.com/fpillet/NSLogger)

`CLILogger` loves [CLI](https://en.wikipedia.org/wiki/Command-line_interface), it receives the messages from client and pipe it to custom scripts whatever in macOS/*nix.

`CLILogger` is a big fans of `CocoaLumberjack`, too. It reuses the log flag/level definition of `CocoaLumberjack` and trace the internal logs inside. Besides, it’s so easy for iOS client app to integrate with `CocoaLumberjack`.



## Plan

#### Client

- [ ] Support to choose logger service when multiple services in a same WLAN environment.

#### Server

- [ ] Support to show client alias.
- [ ] Support to save and pipe the logging message to local file and other process.
- [ ] Custom the log color by log level in the config file.



Expand Down
Binary file added Resources/example.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Sources/CLILogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public class CLILogger: NSObject, DDLogger {
}

public func log(message logMessage: DDLogMessage) {
client.log(logMessage.message, flag: logMessage.flag, module: logMessage.file)
client.log(logMessage.message, flag: logMessage.flag, module: logMessage.fileName)
}
}

0 comments on commit 2e1eeb5

Please sign in to comment.