Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Bring internal changes to public origin #130

Merged
merged 5 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .github/workflows/publish-to-trunk-workflow.yml

This file was deleted.

22 changes: 2 additions & 20 deletions .github/workflows/pull-request-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,14 @@ jobs:
runs-on: macOS-latest
timeout-minutes: 15
steps:
- name: Cancel previous jobs
uses: styfle/cancel-workflow-action@0.6.0
with:
access_token: ${{ github.token }}
- name: Git checkout
uses: actions/checkout@v2.3.4
with:
fetch-depth: 0
ref: ${{ github.ref }}
- name: Setup Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
- name: Setup ruby and bundler dependencies
uses: ruby/setup-ruby@v1.81.0
with:
bundler-cache: true
- name: Run pod install
run: |
set -eo pipefail
export LIB_VERSION=$(git describe --tags `git rev-list --tags --max-count=1`)
bundle exec pod install --project-directory=Example
- name: Run tests
run: bundle exec fastlane unit_tests device:'iPhone 11'
- name: Validate lib
run: |
set -eo pipefail
export LIB_VERSION=$(git describe --tags `git rev-list --tags --max-count=1`)
bundle exec pod lib lint --allow-warnings
run: swift test

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ default.profraw
fastlane/test_output/
fastlane/report.xml
derived_data/
.build/
2 changes: 0 additions & 2 deletions .ruby-version

This file was deleted.

374 changes: 61 additions & 313 deletions Example/JustLog.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
BuildableName = "JustLog_Example.app"
BuildableName = "JustLog.app"
BlueprintName = "JustLog_Example"
ReferencedContainer = "container:JustLog.xcodeproj">
</BuildableReference>
Expand Down Expand Up @@ -46,7 +46,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
BuildableName = "JustLog_Example.app"
BuildableName = "JustLog.app"
BlueprintName = "JustLog_Example"
ReferencedContainer = "container:JustLog.xcodeproj">
</BuildableReference>
Expand Down Expand Up @@ -85,7 +85,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
BuildableName = "JustLog_Example.app"
BuildableName = "JustLog.app"
BlueprintName = "JustLog_Example"
ReferencedContainer = "container:JustLog.xcodeproj">
</BuildableReference>
Expand All @@ -102,7 +102,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
BuildableName = "JustLog_Example.app"
BuildableName = "JustLog.app"
BlueprintName = "JustLog_Example"
ReferencedContainer = "container:JustLog.xcodeproj">
</BuildableReference>
Expand Down
3 changes: 0 additions & 3 deletions Example/JustLog.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions Example/JustLog.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "swiftybeaver",
"kind" : "remoteSourceControl",
"location" : "https://github.com/SwiftyBeaver/SwiftyBeaver",
"state" : {
"revision" : "12b5acf96d98f91d50de447369bd18df74600f1a",
"version" : "1.9.6"
}
}
],
"version" : 2
}
70 changes: 31 additions & 39 deletions Example/JustLog/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
forceSendLogs(application)
}

private var logger: Logger!

func redactValues(message: String, loggerExeptionList: [ExceptionListResponse], matches: [NSTextCheckingResult]) -> String {

var redactedLogMessage = message
Expand Down Expand Up @@ -81,51 +83,47 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
identifier = UIBackgroundTaskIdentifier.invalid
})

Logger.shared.forceSend { completionHandler in
logger.forceSend { completionHandler in
application.endBackgroundTask(identifier)
identifier = UIBackgroundTaskIdentifier.invalid
}
}

private func setupLogger() {
let logger = Logger.shared
let decoder = JSONDecoder()

// custom keys
logger.logTypeKey = "logtype"
logger.appVersionKey = "app_version"
logger.iosVersionKey = "ios_version"
logger.deviceTypeKey = "ios_device"

// file destination
logger.logFilename = "justeat-demo.log"

// logstash destination
logger.logstashHost = "listener.logz.io"
logger.logstashPort = 5052
logger.logstashTimeout = 5
logger.logLogstashSocketActivity = true


let regexRuleList = "[{\"pattern\": \"(name) = \\\\\\\\*\\\"(.*?[^\\\\\\\\]+)\", \"minimumLogLevel\": \"warning\"}, {\"pattern\": \"(token) = \\\\\\\\*\\\"(.*?[^\\\\\\\\]+)\", \"minimumLogLevel\": \"warning\"}]".data(using: .utf8)
let sanitizationExeceptionList = "[{\"value\": \"Dan Jones\"}, {\"value\": \"Jack Jones\"}]".data(using: .utf8)


let configuration = Configuration(
logFilename: "justeat-demo.log",
logstashHost: "listener.logz.io",
logstashPort: 5052,
logstashTimeout: 5,
logLogstashSocketActivity: true
)

logger = Logger(
configuration: configuration,
logMessageFormatter: JSONStringLogMessageFormatter(keys: FormatterKeys())
)

let regexRuleList = "[{\"pattern\": \"(name) = \\\\\\\\*\\\"(.*?[^\\\\\\\\]+)\", \"minimumLogLevel\": \"warning\"}, {\"pattern\": \"(token) = \\\\\\\\*\\\"(.*?[^\\\\\\\\]+)\", \"minimumLogLevel\": \"warning\"}]".data(using: .utf8)
let sanitizationExeceptionList = "[{\"value\": \"Dan Jones\"}, {\"value\": \"Jack Jones\"}]".data(using: .utf8)

logger.sanitize = { message, type in
var sanitizedMessage = message

guard let ruleList = try? decoder.decode([RegexListReponse].self, from: regexRuleList!) else { return "sanitizedMessage" }
guard let exceptionList = try? decoder.decode([ExceptionListResponse].self, from: sanitizationExeceptionList!) else { return "sanitizedMessage" }

for value in ruleList {
if (value.minimumLogLevel >= type.rawValue) {
if let regex = try? NSRegularExpression(pattern: value.pattern , options: NSRegularExpression.Options.caseInsensitive) {

let range = NSRange(sanitizedMessage.startIndex..<sanitizedMessage.endIndex, in: sanitizedMessage)
let matches = regex.matches(in: sanitizedMessage, options: [], range: range)

sanitizedMessage = self.redactValues(message: sanitizedMessage, loggerExeptionList: exceptionList, matches: matches)
}

for value in ruleList {
if (value.minimumLogLevel >= type.rawValue) {
if let regex = try? NSRegularExpression(pattern: value.pattern , options: NSRegularExpression.Options.caseInsensitive) {

let range = NSRange(sanitizedMessage.startIndex..<sanitizedMessage.endIndex, in: sanitizedMessage)
let matches = regex.matches(in: sanitizedMessage, options: [], range: range)

sanitizedMessage = self.redactValues(message: sanitizedMessage, loggerExeptionList: exceptionList, matches: matches)
}
}
}
return sanitizedMessage
}
Expand All @@ -135,12 +133,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

// untrusted (self-signed) logstash server support
//logger.allowUntrustedServer = <Bool>

// default info
logger.defaultUserInfo = ["application": "JustLog iOS Demo",
"environment": "development",
"session": sessionID]
logger.setup()
}


Expand Down
31 changes: 21 additions & 10 deletions Example/JustLog/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,41 @@ import JustLog
class ViewController: UIViewController {

private var logNumber = 0


private var logger: Logger = Logger(
configuration: Configuration(),
logMessageFormatter: JSONStringLogMessageFormatter(keys: FormatterKeys())
)

@IBAction func verbose() {
Logger.shared.verbose("[\(logNumber)] not so important", userInfo: ["userInfo key": "userInfo value"])
let log = Log(type: .verbose, message: "[\(logNumber)] not so important", customData: ["userInfo key": "userInfo value"])
logger.send(log)
logNumber += 1
}

@IBAction func debug() {
Logger.shared.debug("[\(logNumber)] something to debug", userInfo: ["userInfo key": "userInfo value"])
let log = Log(type: .debug, message: "[\(logNumber)] not so debug", customData: ["userInfo key": "userInfo value"])
logger.send(log)
logNumber += 1
}

@IBAction func info() {
Logger.shared.info("[\(logNumber)] a nice information", userInfo: ["userInfo key": "userInfo value"])
let log = Log(type: .info, message: "[\(logNumber)] a nice information", customData: ["userInfo key": "userInfo value"])
logger.send(log)
logNumber += 1
}

@IBAction func warning() {
Logger.shared.warning("[\(logNumber)] oh no, that won’t be good", userInfo: ["userInfo key": "userInfo value"])
let log = Log(type: .warning, message: "[\(logNumber)] oh no, that won’t be good", customData: ["userInfo key": "userInfo value"])
logger.send(log)
logNumber += 1
}

@IBAction func warningSanitized() {
let messageToSanitize = "conversation ={\\n id = \\\"123455\\\";\\n};\\n from = {\\n id = 123456;\\n name = \\\"John Smith\\\";\\n; \\n token = \\\"123456\\\";\\n"
let sanitizedMessage = Logger.shared.sanitize(messageToSanitize, Logger.LogType.warning)
Logger.shared.warning(sanitizedMessage, userInfo: ["userInfo key": "userInfo value"])
let sanitizedMessage = logger.sanitize(messageToSanitize, LogType.warning)
let log = Log(type: .warning, message: sanitizedMessage, customData: ["userInfo key": "userInfo value"])
logger.send(log)
logNumber += 1
}

Expand All @@ -57,16 +67,17 @@ class ViewController: UIViewController {

let unreadableError = NSError(domain: "com.just-eat.test", code: 1234, userInfo: unreadableUserInfos)

Logger.shared.error("[\(logNumber)] ouch, an error did occur!", error: unreadableError, userInfo: ["userInfo key": "userInfo value"])
let log = Log(type: .error, message: "[\(logNumber)] ouch, an error did occur!", error: unreadableError, customData: ["userInfo key": "userInfo value"])
logger.send(log)
logNumber += 1
}

@IBAction func forceSend() {
Logger.shared.forceSend()
logger.forceSend()
}

@IBAction func cancel(_ sender: Any) {
Logger.shared.cancelSending()
logger.cancelSending()
}
}

25 changes: 0 additions & 25 deletions Example/Podfile

This file was deleted.

23 changes: 0 additions & 23 deletions Example/Podfile.lock

This file was deleted.

24 changes: 0 additions & 24 deletions Example/Tests/Info.plist

This file was deleted.

Loading
Loading