Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c9a1b4e

Browse files
authored
Merge pull request Tencent#69 from Jinkeycode/dev
Add Swift Xlogger Demo
2 parents 6c9290c + 2d0c91b commit c9a1b4e

File tree

24 files changed

+1914
-0
lines changed

24 files changed

+1914
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python
2+
3+
import sys
4+
import os
5+
import glob
6+
import shutil
7+
8+
9+
MARS_OPEN_LIBRARIES_PATH = os.path.join(os.path.split(os.path.realpath(__file__))[0], "../../../../mars/libraries")
10+
sys.path.append(MARS_OPEN_LIBRARIES_PATH)
11+
12+
from build_apple import *
13+
from mars_utils import *
14+
15+
SAMPLE_LIBS_DIRECTORY = "samplexloglibs"
16+
proj = APPLE_PROJECTS[2]
17+
18+
SAMPLE_LIBS_PATH = RELATIVE_PATH + "libraries/" + SAMPLE_LIBS_DIRECTORY + "/" + os.path.splitext(os.path.split(proj.path)[1])[0] + proj.other_cflags + "/" + proj.framework_name
19+
DES_PATH = os.path.join(os.path.split(os.path.realpath(__file__))[0], "MarsLib/" + proj.framework_name)
20+
21+
def main():
22+
23+
if not check_python_version():
24+
exit("python env error")
25+
26+
if build_apple(proj, SAMPLE_LIBS_DIRECTORY):
27+
pass
28+
else:
29+
exit("build mars fail!")
30+
31+
if os.path.exists(DES_PATH):
32+
shutil.rmtree(DES_PATH)
33+
shutil.copytree(SAMPLE_LIBS_PATH, DES_PATH)
34+
35+
36+
37+
if __name__ == "__main__":
38+
39+
main()
40+

samples/iOS/XloggerSwiftDemo/XloggerSwiftDemo.xcodeproj/project.pbxproj

Lines changed: 652 additions & 0 deletions
Large diffs are not rendered by default.

samples/iOS/XloggerSwiftDemo/XloggerSwiftDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Tencent is pleased to support the open source community by making Mars available.
2+
// Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
3+
4+
// Licensed under the MIT License (the "License"); you may not use this file except in
5+
// compliance with the License. You may obtain a copy of the License at
6+
// http://opensource.org/licenses/MIT
7+
8+
// Unless required by applicable law or agreed to in writing, software distributed under the License is
9+
// distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10+
// either express or implied. See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
13+
14+
/*
15+
* AppDelegate.swift
16+
*
17+
* Created on: 2017-1-3
18+
* Author: Jinkey
19+
*/
20+
21+
import UIKit
22+
23+
@UIApplicationMain
24+
class AppDelegate: UIResponder, UIApplicationDelegate {
25+
26+
var window: UIWindow?
27+
28+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
29+
30+
var jmb = JinkeyMarsBridge()
31+
jmb.initXlogger(.debug, releaseLevel: .info, path: "/jinkeylog", prefix: "Test")
32+
jmb.log(.debug, tag: "JinkeyXlogger", content: "github Jinkeycode")
33+
34+
return true
35+
}
36+
37+
func applicationWillResignActive(_ application: UIApplication) {
38+
39+
}
40+
41+
func applicationDidEnterBackground(_ application: UIApplication) {
42+
43+
}
44+
45+
func applicationWillEnterForeground(_ application: UIApplication) {
46+
47+
}
48+
49+
func applicationDidBecomeActive(_ application: UIApplication) {
50+
51+
}
52+
53+
func applicationWillTerminate(_ application: UIApplication) {
54+
JinkeyMarsBridge().deinitXlogger()
55+
}
56+
57+
58+
}
59+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Tencent is pleased to support the open source community by making Mars available.
2+
// Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
3+
// Licensed under the MIT License (the "License"); you may not use this file except in
4+
// compliance with the License. You may obtain a copy of the License at
5+
// http://opensource.org/licenses/MIT
6+
// Unless required by applicable law or agreed to in writing, software distributed under the License is
7+
// distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
8+
// either express or implied. See the License for the specific language governing permissions and
9+
// limitations under the License.
10+
/*
11+
* appender-swift-bridge.h
12+
*
13+
* Created on: 2017-1-3
14+
* Author: Jinkey
15+
*/
16+
17+
18+
#include <stdio.h>
19+
#import <Foundation/Foundation.h>
20+
#import "LogUtil.h"
21+
22+
23+
typedef NS_ENUM(NSUInteger, XloggerType) {
24+
25+
debug,
26+
info,
27+
warning,
28+
error,
29+
30+
};
31+
32+
@interface JinkeyMarsBridge: NSObject
33+
34+
- (void)initXlogger: (XloggerType)debugLevel releaseLevel: (XloggerType)releaseLevel path: (NSString*)path prefix: (const char*)prefix;
35+
- (void)deinitXlogger;
36+
37+
- (void)log: (XloggerType) level tag: (const char*)tag content: (NSString*)content;
38+
39+
@end
40+
41+
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
2+
// Tencent is pleased to support the open source community by making Mars available.
3+
// Copyright (C) 207 THL A29 Limited, a Tencent company. All rights reserved.
4+
// Licensed under the MIT License (the "License"); you may not use this file except in
5+
// compliance with the License. You may obtain a copy of the License at
6+
// http://opensource.org/licenses/MIT
7+
// Unless required by applicable law or agreed to in writing, software distributed under the License is
8+
// distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
9+
// either express or implied. See the License for the specific language governing permissions and
10+
// limitations under the License.
11+
/*
12+
* appender-swift-bridge.mm
13+
*
14+
* Created on: 2017-1-3
15+
* Author: Jinkey
16+
*/
17+
18+
#import "appender-swift-bridge.h"
19+
#import <mars/xlog/appender.h>
20+
#import <mars/xlog/xlogger.h>
21+
#import <sys/xattr.h>
22+
23+
@implementation JinkeyMarsBridge
24+
25+
// 封装了初始化 Xlogger 方法
26+
// initialize Xlogger
27+
-(void)initXlogger: (XloggerType)debugLevel releaseLevel: (XloggerType)releaseLevel path: (NSString*)path prefix: (const char*)prefix{
28+
29+
NSString* logPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingString:path];
30+
31+
// set do not backup for logpath
32+
const char* attrName = "io.jinkey";
33+
u_int8_t attrValue = 1;
34+
setxattr([logPath UTF8String], attrName, &attrValue, sizeof(attrValue), 0, 0);
35+
36+
// init xlog
37+
#if DEBUG
38+
switch (debugLevel) {
39+
case debug:
40+
xlogger_SetLevel(kLevelDebug);
41+
case info:
42+
xlogger_SetLevel(kLevelInfo);
43+
case warning:
44+
xlogger_SetLevel(kLevelWarn);
45+
case error:
46+
xlogger_SetLevel(kLevelError);
47+
default:
48+
break;
49+
}
50+
appender_set_console_log(true);
51+
#else
52+
switch (releaseLevel) {
53+
case debug:
54+
xlogger_SetLevel(kLevelDebug);
55+
case info:
56+
xlogger_SetLevel(kLevelInfo);
57+
case warning:
58+
xlogger_SetLevel(kLevelWarn);
59+
case error:
60+
xlogger_SetLevel(kLevelError);
61+
default:
62+
break;
63+
}
64+
appender_set_console_log(false);
65+
#endif
66+
appender_open(kAppednerAsync, [logPath UTF8String], prefix);
67+
68+
}
69+
70+
// 封装了关闭 Xlogger 方法
71+
// deinitialize Xlogger
72+
-(void)deinitXlogger {
73+
appender_close();
74+
}
75+
76+
77+
// 利用微信提供的 LogUtil.h 封装了打印日志的方法
78+
// print log using LogUtil.h provided by Wechat
79+
-(void) log: (XloggerType) level tag: (const char*)tag content: (NSString*)content{
80+
81+
NSString* levelDescription = @"";
82+
83+
switch (level) {
84+
case debug:
85+
LOG_DEBUG(tag, content);
86+
levelDescription = @"Debug";
87+
break;
88+
case info:
89+
LOG_INFO(tag, content);
90+
levelDescription = @"Info";
91+
break;
92+
case warning:
93+
LOG_WARNING(tag, content);
94+
levelDescription = @"Warn";
95+
break;
96+
case error:
97+
LOG_ERROR(tag, content);
98+
levelDescription = @"Error";
99+
break;
100+
default:
101+
break;
102+
}
103+
104+
}
105+
106+
@end
107+
108+
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "iphone",
5+
"size" : "20x20",
6+
"scale" : "2x"
7+
},
8+
{
9+
"idiom" : "iphone",
10+
"size" : "20x20",
11+
"scale" : "3x"
12+
},
13+
{
14+
"idiom" : "iphone",
15+
"size" : "29x29",
16+
"scale" : "2x"
17+
},
18+
{
19+
"idiom" : "iphone",
20+
"size" : "29x29",
21+
"scale" : "3x"
22+
},
23+
{
24+
"idiom" : "iphone",
25+
"size" : "40x40",
26+
"scale" : "2x"
27+
},
28+
{
29+
"idiom" : "iphone",
30+
"size" : "40x40",
31+
"scale" : "3x"
32+
},
33+
{
34+
"idiom" : "iphone",
35+
"size" : "60x60",
36+
"scale" : "2x"
37+
},
38+
{
39+
"idiom" : "iphone",
40+
"size" : "60x60",
41+
"scale" : "3x"
42+
},
43+
{
44+
"idiom" : "ipad",
45+
"size" : "20x20",
46+
"scale" : "1x"
47+
},
48+
{
49+
"idiom" : "ipad",
50+
"size" : "20x20",
51+
"scale" : "2x"
52+
},
53+
{
54+
"idiom" : "ipad",
55+
"size" : "29x29",
56+
"scale" : "1x"
57+
},
58+
{
59+
"idiom" : "ipad",
60+
"size" : "29x29",
61+
"scale" : "2x"
62+
},
63+
{
64+
"idiom" : "ipad",
65+
"size" : "40x40",
66+
"scale" : "1x"
67+
},
68+
{
69+
"idiom" : "ipad",
70+
"size" : "40x40",
71+
"scale" : "2x"
72+
},
73+
{
74+
"idiom" : "ipad",
75+
"size" : "76x76",
76+
"scale" : "1x"
77+
},
78+
{
79+
"idiom" : "ipad",
80+
"size" : "76x76",
81+
"scale" : "2x"
82+
},
83+
{
84+
"idiom" : "ipad",
85+
"size" : "83.5x83.5",
86+
"scale" : "2x"
87+
}
88+
],
89+
"info" : {
90+
"version" : 1,
91+
"author" : "xcode"
92+
}
93+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
}
6+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"scale" : "1x"
6+
},
7+
{
8+
"idiom" : "universal",
9+
"filename" : "qr.jpeg",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}

0 commit comments

Comments
 (0)