728x90

참고URL

https://codinghub.tistory.com/39

 


Babel 
ECMAScript6를 지원하지 않는 환경에서 ECMAScript6 Syntax를 사용할 수 있게 해줍니다.

Webpack
모듈 번들러입니다.
Browserify 처럼 브라우저 위에서 import(require)을 할 수 있게 해주고 자바스크립트 파일들을 하나로 묶어 줍니다.

webpack-dev-server
webpack에서 지원하는 간단한 개발서버로써 별도의 서버를 구축하지 않아도 웹서버를 열 수 있으며 hot-loader 를 통하여 코드가 수정될때마다 자동으로 리로드되게 할 수 있습니다.


프로젝트를 위한 폴더 생성 및 npm 초기화 - 폴더명 myFristApp

$ mkdir myFirstApp
$ cd  myFirstApp
$ npm init

$ npm init

This utility will walk you through creating a package.json file.

It only covers the most common items, and tries to guess sensible defaults.



See `npm help json` for definitive documentation on these fields

and exactly what they do.



Use `npm install <pkg>` afterwards to install a package and

save it as a dependency in the package.json file.



Press ^C at any time to quit.

package name: (reactjs) 

version: (1.0.0) 

description: 

entry point: (index.js) 

test command: 

git repository: 

keywords: 

author: 

license: (ISC) 

About to write to /Users/jaehonghan/dev/workspace_nodejs/reactjs/package.json:



{

  "name": "reactjs",

  "version": "1.0.0",

  "description": "",

  "main": "index.js",

  "scripts": {

    "test": "echo \"Error: no test specified\" && exit 1"

  },

  "author": "",

  "license": "ISC"

}



Is this OK? (yes) 

 

package.json에 webpack-dev-server 스크립트 추가

package.json에 "dev-server":"webpack-dev-server" 추가해야 합니다.

추후 개발 서버를 실행하기 위해서 필요합니다.

 

$ vi package.json

{
  "name": "reactjs",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev-server":"webpack-dev-server" 
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.3",
    "babel-loader": "^8.1.0",
    "babel-polyfill": "^6.26.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-react-hmre": "^1.1.1",
    "babel-preset-stage-0": "^6.24.1",
    "css-loader": "^3.6.0",
    "file-loader": "^6.0.0",
    "node-sass": "^4.14.1",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-hot-loader": "^4.12.21",
    "sass-loader": "^8.0.2",
    "style-loader": "^1.2.1",
    "url-loader": "^4.1.0",
    "webpack": "^4.43.0",
    "webpack-dev-middleware": "^3.7.2",
    "webpack-dev-server": "^3.11.0",
    "webpack-hot-middleware": "^2.25.0"
  },
  "dependencies": {
    "bootstrap": "^4.5.0",
    "react-bootstrap": "^1.0.1"
  }
}

 

리엑트 설치

$ npm install --save-dev react react-dom

$ npm install --save-dev react react-dom


npm notice created a lockfile as package-lock.json. You should commit this file.

npm WARN reactjs@1.0.0 No description

npm WARN reactjs@1.0.0 No repository field.



+ react-dom@16.13.1

+ react@16.13.1

added 8 packages from 3 contributors and audited 8 packages in 0.695s

found 0 vulnerabilities

 

부트스트랩 설치

$ npm install --save bootstrap react-bootstrap

$ npm install --save bootstrap react-bootstrap

npm WARN bootstrap@4.5.0 requires a peer of jquery@1.9.1 - 3 but none is installed. You must install peer dependencies yourself.

npm WARN bootstrap@4.5.0 requires a peer of popper.js@^1.16.0 but none is installed. You must install peer dependencies yourself.

npm WARN reactjs@1.0.0 No description

npm WARN reactjs@1.0.0 No repository field.



+ react-bootstrap@1.0.1

+ bootstrap@4.5.0

added 22 packages from 43 contributors and audited 30 packages in 2.929s



2 packages are looking for funding

  run `npm fund` for details



found 0 vulnerabilities

 

css /  sass 설치

$ npm install --save-dev sass-loader css-loader style-loader node-sass

$ npm install --save-dev sass-loader css-loader style-loader node-sass

npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142



> node-sass@4.14.1 install /Users/jaehonghan/dev/workspace_nodejs/reactjs/node_modules/node-sass

> node scripts/install.js



Downloading binary from https://github.com/sass/node-sass/releases/download/v4.14.1/darwin-x64-83_binding.node

Download complete░░⸩ ⠋ :

Binary saved to /Users/jaehonghan/dev/workspace_nodejs/reactjs/node_modules/node-sass/vendor/darwin-x64-83/binding.node

Caching binary to /Users/jaehonghan/.npm/node-sass/4.14.1/darwin-x64-83_binding.node



> node-sass@4.14.1 postinstall /Users/jaehonghan/dev/workspace_nodejs/reactjs/node_modules/node-sass

> node scripts/build.js



Binary found at /Users/jaehonghan/dev/workspace_nodejs/reactjs/node_modules/node-sass/vendor/darwin-x64-83/binding.node

Testing binary

Binary is fine

npm WARN bootstrap@4.5.0 requires a peer of jquery@1.9.1 - 3 but none is installed. You must install peer dependencies yourself.

npm WARN bootstrap@4.5.0 requires a peer of popper.js@^1.16.0 but none is installed. You must install peer dependencies yourself.

npm WARN sass-loader@8.0.2 requires a peer of webpack@^4.36.0 || ^5.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN css-loader@3.6.0 requires a peer of webpack@^4.0.0 || ^5.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN style-loader@1.2.1 requires a peer of webpack@^4.0.0 || ^5.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN reactjs@1.0.0 No description

npm WARN reactjs@1.0.0 No repository field.



+ sass-loader@8.0.2

+ css-loader@3.6.0

+ node-sass@4.14.1

+ style-loader@1.2.1

added 224 packages from 177 contributors and audited 254 packages in 9.398s



11 packages are looking for funding

  run `npm fund` for details



found 0 vulnerabilities

 

 

Babel 설치

$ npm install --save-dev babel-core babel-loader babel-cli babel-preset-react babel-preset-es2015 babel-preset-stage-0 babel-polyfill babel-preset-env file-loader url-loader babel-preset-react-hmre

$ npm install --save-dev babel-core babel-loader babel-cli babel-preset-react babel-preset-es2015 babel-preset-stage-0 babel-polyfill babel-preset-env file-loader url-loader babel-preset-react-hmre



npm WARN deprecated babel-preset-es2015@6.24.1: 🙌  Thanks for using Babel: we recommend using babel-preset-env now: please read https://babeljs.io/env to update!

npm WARN deprecated chokidar@1.7.0: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.

npm WARN deprecated core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.

npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.

npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated

npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated



> fsevents@1.2.13 install /Users/jaehonghan/dev/workspace_nodejs/reactjs/node_modules/fsevents

> node install.js



No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.



No receipt for 'com.apple.pkg.DeveloperToolsCLILeo' found at '/'.



No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'.



gyp: No Xcode or CLT version detected!

gyp ERR! configure error 

gyp ERR! stack Error: `gyp` failed with exit code: 1

gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)

gyp ERR! stack     at ChildProcess.emit (events.js:315:20)

gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)

gyp ERR! System Darwin 19.5.0

gyp ERR! command "/usr/local/Cellar/node/14.4.0/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"

gyp ERR! cwd /Users/jaehonghan/dev/workspace_nodejs/reactjs/node_modules/fsevents

gyp ERR! node -v v14.4.0

gyp ERR! node-gyp -v v5.1.0

gyp ERR! not ok 



> core-js@2.6.11 postinstall /Users/jaehonghan/dev/workspace_nodejs/reactjs/node_modules/core-js

> node -e "try{require('./postinstall')}catch(e){}"



Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!



The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 

> https://opencollective.com/core-js 

> https://www.patreon.com/zloirock 



Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)



npm WARN bootstrap@4.5.0 requires a peer of jquery@1.9.1 - 3 but none is installed. You must install peer dependencies yourself.

npm WARN bootstrap@4.5.0 requires a peer of popper.js@^1.16.0 but none is installed. You must install peer dependencies yourself.

npm WARN css-loader@3.6.0 requires a peer of webpack@^4.0.0 || ^5.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN sass-loader@8.0.2 requires a peer of webpack@^4.36.0 || ^5.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN style-loader@1.2.1 requires a peer of webpack@^4.0.0 || ^5.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN babel-loader@8.1.0 requires a peer of @babel/core@^7.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN babel-loader@8.1.0 requires a peer of webpack@>=2 but none is installed. You must install peer dependencies yourself.

npm WARN file-loader@6.0.0 requires a peer of webpack@^4.0.0 || ^5.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN url-loader@4.1.0 requires a peer of webpack@^4.0.0 || ^5.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN reactjs@1.0.0 No description

npm WARN reactjs@1.0.0 No repository field.



+ babel-loader@8.1.0

+ babel-preset-env@1.7.0

+ babel-polyfill@6.26.0

+ babel-cli@6.26.0

+ babel-preset-react@6.24.1

+ babel-core@6.26.3

+ babel-preset-stage-0@6.24.1

+ file-loader@6.0.0

+ url-loader@4.1.0

+ babel-preset-react-hmre@1.1.1

+ babel-preset-es2015@6.24.1

added 314 packages from 130 contributors and audited 569 packages in 38.757s



13 packages are looking for funding

  run `npm fund` for details



found 1 low severity vulnerability

  run `npm audit fix` to fix them, or `npm audit` for details

 

.babelrc  파일 생성

$ vi .babelrc

{
   "presets":["env","react","es2015", "stage-0"],
   "env":{
      "development":{
         "presets":["react-hmre"]
      }
   }
}

 

WebPack 설치

$ npm install --save-dev react-hot-loader webpack webpack-dev-server webpack-dev-middleware webpack-hot-middleware 

$ npm install --save-dev react-hot-loader webpack webpack-dev-server webpack-dev-middleware webpack-hot-middleware 



npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.

npm WARN notsup Unsupported engine for watchpack-chokidar2@2.0.0: wanted: {"node":"<8.10.0"} (current: {"node":"14.4.0","npm":"6.14.4"})

npm WARN notsup Not compatible with your version of node/npm: watchpack-chokidar2@2.0.0

npm WARN babel-loader@8.1.0 requires a peer of @babel/core@^7.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN bootstrap@4.5.0 requires a peer of jquery@1.9.1 - 3 but none is installed. You must install peer dependencies yourself.

npm WARN bootstrap@4.5.0 requires a peer of popper.js@^1.16.0 but none is installed. You must install peer dependencies yourself.

npm WARN reactjs@1.0.0 No description

npm WARN reactjs@1.0.0 No repository field.



+ webpack-dev-middleware@3.7.2

+ webpack-hot-middleware@2.25.0

+ react-hot-loader@4.12.21

+ webpack-dev-server@3.11.0

+ webpack@4.43.0

added 463 packages from 312 contributors and audited 1033 packages in 10.309s



31 packages are looking for funding

  run `npm fund` for details



found 1 low severity vulnerability

  run `npm audit fix` to fix them, or `npm audit` for details

 

 

webpack 설정 -  webpack.config.js

프로젝트 폴더에 webpack 설정파일인 webpack.config.js 을 생성하고 아래의 내용을 입력합니다.

var webpack = require('webpack');

var path = require('path');

module.exports = {

  entry: [

    'webpack-hot-middleware/client',

    './src/index.js'

  ],

  output: {

    path: __dirname + '/public/',

    filename: 'bundle.js'

  },

  devServer: {

    hot: true,

    inline: true,

    port: 4000,

    contentBase: __dirname + '/public/',

  },

  module: {

      loaders: [

        {

          test: /\.js$/,

          loaders: ['react-hot-loader', 'babel-loader'],

          include: path.join(__dirname, 'src')

        },

        {

          test: /\.less$/,

          loader: 'style-loader!css-loader!less-loader'  // use ! to chain loaders

        },

        {

          test: /\.css$/,

          loader: 'style-loader!css-loader'

        },

        {

          test: /\.scss$/,

          loader: 'style-loader!css-loader!sass-loader'

        },

        {

          test: /\.(png|jpg)$/,

          loader: 'url-loader?limit=8192' // inline base64 URLs for <=8k images, direct URLs for the rest

        }

      ]

  },

  plugins: [ new webpack.HotModuleReplacementPlugin() ]

}

react app 만들기

1. 처음에 생성한 myFirstApp 에 public, src 폴더를 생성합니다.

webpack.config.js에서 개발 서버가 바라볼 기본 폴더는 public가 됩니다.

$ cd myFirstApp
$ mkdir public
$ mkdir src

 

2. public 폴더에 index.html 파일을 아래와 같이 생성합니다.

$ cd public/index.html

-- index.html에 간략한 내용 입력

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>React App with Babel + webpack</title>
  </head>

  <body>
    <div id="contents"></div>
    <script src="bundle.js"></script>
  </body>
</html>

 

3. src 폴더에 components 폴더를 생성합니다.

src 폴더의 하위에 components  폴더를 만들고 src/components Contents.react.js 파일을 생성하고 아래의 내용을 입력합니다.

$ cd ../src
$ mkdir components
$ vi Contents.react.js


-- Contents.react.js 파일의 내용

import React from 'react';
class Contents extends React.Component {
  render() {
    return ( <h1>React + Webpack + Babel First Apps</h1> );
  }
}

 

4. 개발 서버를 실행합니다.

브라우저에서 http://localhost:4000에 접속하시면 결과를 확인할 수 있습니다.

$ cd myFirstApp
$ npm run dev-server
728x90

참고문서

[RN] React-Native 시작하기

medium.com/@jang.wangsu/rn-react-native-%EC%8B%9C%EC%9E%91-3aab881f574f

Introduction

reactnative.dev/docs/getting-started

 

1. React-Native 시작하기 전

Homebrew 설치하기

brew.sh/index_ko

 

Homebrew

The Missing Package Manager for macOS (or Linux).

brew.sh

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

 

npm 을 사용하기 위해 node 설치

$ brew update
$ brew uninstall node
$ brew install node
$ brew postinstall

 

npm 설치확인

$ npm --version

 

 

 

 

Yarn 설치하기

$ npm install --global yarn


/usr/local/bin/yarn -> /usr/local/lib/node_modules/yarn/bin/yarn.js
/usr/local/bin/yarnpkg -> /usr/local/lib/node_modules/yarn/bin/yarn.js
+ yarn@1.22.4

 

 

2. React-Native 를 위한 2가지 방법

샘플 앱 실행을 위해서는 크게 2가지가 존재합니다.

 

1. CRNA (Create-react-native-app)를 이용하는 방법

Xcode나 android studio를 설치할 필요가 없는 방식으로 바로 실행해 보길 원하는 경우에 이용합니다.

이때 Expo 를 이용하면, android studio, Xcode 가 필요없이 개발 진행을 도와주고, Expo Clint로 테스트도 가능합니다.

 

2. React-native 명령어를 이용하는 방법
이전 react native를 사용하는 보통의 개발 방법입니다.
CRNA가 2017년 나왔으며 앞으로는 CRNA를 권장할 가능성이 있습니다.
react-native 명령어를 이용하는 방법은 iOS 개발을 위해 Mac이 꼭 필요합니다.

 

 

2-1. CRNA (Create-react-native-app)를 이용하는 경우, 설치

-- CRNA 설치

$ npm install -g create-react-native-app

-- 프로젝트를 생성합니다.

$ create-react-native-app 프로젝트명
$ cd 프로젝트 명
$ npm start

 

먄약 실행이 안된다면

Androi인 경우는 USB에 안드로이드 폰을 연결하세요.
https://developer.android.com/studio/run/device.html#developer-device-options
그리고 실행후에는 안드로이드 폰은 노트북과 같은 Wi-Fi에 같이 존재해야 합니다.

 

 

노드는 설치가 되어 있다면 아래  watchman 설치, 자세한 설명은 프로젝트 Readme.md에 나와있습니다.

$ brew install watchman
6. Readme.md 파일 확인

 

 

2-2. React-native 명령어를 이용하는 방법

-- react-native-cli 설치

$ npm install -g react-native-cli

-- react-native 를 설치하진 마세요.

$ react-native init 프로젝트명
$ cd 프로젝트명

$ react-native run-ios
또는 
$ react-native run-android

* npm install -g react-native  을 설치하지 마세요.

 

Error 발생시

처음에 언급한 getting-started Site에서 빠진 부분이 없는지 확인해야 됩니다.

 

iOS : Xcode -> Preferences -> Locations -> Command Line Tools 의 설정이 빠져있다면 설정해주세요.

Android: JDK 설치 유무확인, SDK Manager에서 필수 설치 미설치 여부 인해야 합니다.

 

테스트 버전정보

$ brew --version
Homebrew 2.4.2
Homebrew/homebrew-core (git revision 94f44; last commit 2020-06-30)

$ react-native --version
react-native-cli: 2.0.1
react-native: 0.62.2

$ yarn --version
1.22.4

$ create-react-native-app --version
3.5.0

$ node --version
v14.4.0

$ npm --version
6.14.4

 

728x90

 

Android 개발 가이드 / Android 개발 가이드라인 / Android 코딩 스타일 가이드

http://developer.gaeasoft.co.kr/development-guide/android-guide/android-coding-style-guide/

 

Follow Field Naming Conventions

가. Non-public, non-static field 는 m으로 시작

예) 
private int mPrivate;

int mPackagePrivate;

protected int mProtected;

 

 

나. Static field 는 s로 시작

예) private static MyClass sSingleton;

 

다. 나머지는 소문자로 시작.

 예) public int publicField;

 

라. Public static final fields (상수) 는 모두 대문자로 ALL_CAPS_WITH_UNDERSCORES.

예) public static final int SOME_CONSTANT = 42;

 

public class MyClass {

	public static final int SOME_CONSTANT = 42;

	public int publicField;

	private static MyClass sSingleton;

	int mPackagePrivate;

	private int mPrivate;

	protected int mProtected;

}

 

시작 중괄호는 "{" 따로 한줄을 차지하지 않는다.

class MyClass {

	int func() {

		if (something) {

			// ...

		} else if (somethingElse) {

			// ...

		} else {

			// ...

		}
	}
}

 

if (condition) body();

 

TODO 주석문 또는 FIXME 주석문을 사용 할 것.

단기처방이나, 완벽하지 않은 해결책인 경우에는 반드시 TODO or FIXME주석문을 기입할 것.

// TODO: UrlTable2

또는

// FIXME: flag

 


Activity 개발 시 주의 사항

context를 별도 멤버로 선언하고 관리하지 않도록 하자.

context가 필요하면 getContext() 를 사용하자.

 

잘못된 사례

아래 예시는 잘못된 예시입니다.

public class MyActivity extends Activity {

	private Context mContext = null;

	...

	...

	protected void onCreated(Bundle savedInstanceState){

	mContext = this;

}

 


JavaTests Style Rules

테스트 방법 명명 규칙 준수

Test Method 의 이름을 설계할 때, test case를 "_" 뒤에 붙여줄 수 있다.

예)

testMethod_specificCase1 testMethod_specificCase2

void testIsDistinguishable_protanopia() {
 ColorMatcher colorMatcher = new ColorMatcher(PROTANOPIA)
 assertFalse(colorMatcher.isDistinguishable(Color.RED, Color.BLACK))
 assertTrue(colorMatcher.isDistinguishable(Color.X, Color.Y))
}

 


로깅(Log)은 간결하게.

로깅은 성능에 지대한 영향을 준다.

로깅하기 전에 먼저, 로그 레벨을 이해하자.

 

ERROR 레벨: 항상 기록되는 레벨, 뭔가 치명적인 상황을 기록한다.

따라서 조심스럽게 사용해야 한다. 먼가 치명적인 상황을 기록한다.

예를 들어 어떤 데이터를 직접 삭제하거나, 앱을 지우거나, 폰을 싹 밀어버리거나 하기 전에는 복구가 안되는 상황을 사용자가 직면해야 할때만 기록하고, (가능하면)통계수집 서버에 통보하도록 하자.

 

WARNING 레벨: 항상 기록되는 레벨, 심각한 상황을 기록한다.

심각한 상황을 기록한다.

예를 들어 사용자가 인식할 수 있는 오류결과가 나타나고, 사용하던 데이터(다운로드 중인 데이터 등등)가 날아가버리고,

사용자가 앱 혹은 폰을 리부팅하거나, 화면을 죽이거나, 새로운 버전의 앱을 다운 받기 전에는 복구가 안되는 상황에 사용하자.

 

0 INFORMATIVE: 역시 항상 기록되는 레벨, 오류가 아닌 뭔가 대단한 상황일 경우 기록한다.

오류는 아니더라고, 뭔가 모두가 알았으면 하는 대단한 상황일 경우 기록한다.

예를 들어 오류는 아니지만, 동접자 수가 100만명이 넘어갔다거나, 악성코드로 의심되는 입력값이 감지되었다거나 등등 모두가 알면 좋을 만한 사건이 발생한 상황에 사용하자.

 

DEBUG 레벨: 디버그 모드에서만 기록되는 레벨, 디버깅 과정과 관련된 추가 정보를 기록한다.

디버깅 과정과 관련한 추가 정보를 기록할 때 사용한다.

만약 로깅 자체보다는 개발자 본인의 관심사와 관련한 정보라면 verbose level로 로깅하자.

 

배포 버전에도 로깅이 가능하며, 로깅과 관련한 소스가 컴파일 되기 때문에 성능을 고려한다면

로깅 소스는 반드시 다음과 같이 if (LOCAL_LOG) or if (LOCAL_LOGD) 구문내에 구현해야 한다.

 

혹시나, 다른 대안으로 리펙토링을 통해 logging 기능을 밖으로 빼는 방법을 생각해보기도 하는데 (re-factoring out), 이는 좋은 생각이 아니다.

왜냐하면, String 파라미터가 전달되면서 불필요한 String 생성이 발생하기 때문이다.

 

VERBOSE 레벨: 뭐든 로깅해도 되는 레벨, 개발자 본인의 관심사와 관련된 정보 등을 기록한다.

debug level 처럼 반드시 if구문내에 구현하도록 하자.

아니면 배포전에 아예 없애버리자.

 


기억할 것

1. VERBOSE 레벨 이 아닐경우 - 상위 method 오버로딩 시 상위 method에 logging하자.

하나의 모듈 내에 있는 하나의 function chain 내에서 오류는 가능한 한번만 보고(logging)가 되도록 해야 한다.

이를테면 method overloading 방식으로 methodA(param1) 가 methodA(param1, param2)를 호출하면 error는 methodA(param1, param2) 에서만 기록하도록 하자.

그래야 issue를 격리시키는 게 쉬워진다.

 

2. VERBOSE 레벨 이 아닐경우 2 - 상위 모듈에 전달된 DATA 가 문제가 될 경우, debug모드로 

연쇄적으로 작동하는 모듈간에 만약 상위 모듈에서 전달된 data에 문제가 있다고 판단될 경우 로깅을 하려면 debug 모드로 해야 한다.

굳이 information 이상 레벨의 로깅이 필요하다면, 상위 레벨 모듈에서 처리해야한다.

특히 lib 나 프레임워크개발시에 이런 규칙이 중요하다.

lib 나 framework를 가져다 쓰는 경우 마음대로 로깅을 남기고 곤란한 경우가 발생한다.

 

3. 반복되거나 동일한 작업이 예상되는 것은 일정한 조건을 걸어서 로깅해라.

이를 테면, onTouchEvent 내에 로깅할때 네트웍 단절 상태등은 충분히 예상되는 내용이다. debug verbose 이상의 로깅을 하지 말자.

 

 

4. 다른 앱에서 접근가능한 파일시스템 용량 초과 같은 이슈는 INFORMATIVE 이하 레벨로 검증 되지 않은 소스로부터 들어오는 잘못된 데이터 입력등의 이슈는 DEBUG 이하로 작성할 것.

 

5. Log.v() 는 배포버전에서도 컴파일 된다.

레벨에 따라 로깅이 안될 뿐이지. 따라서 반드시 if 구문안에서 String을 처리해야함.

 

 

6. 모든 로깅은 간결하고 누구나 쉽게 이해할 수 있어야 한다.

작성자만 알아볼 수 있게 하지 말 것. (DEBUG level 이상의 로깅이라면 말이지)

 

7. 가능한 한줄로 표현되게끔 해주세요. 너무 길지도 않게.

 

8. 작업 성공 여부 같은 것은 VERBOSE 외에선 사용하지 말 것.

 

9. 검사나 분석을 위한 임시 로깅은 반드시 DEBUG or VERBOSE level 에서만 작성할 것.

 

10. 로깅으로 개인정보 등 보안 정보가 유출되지 않도록 각별히 신경 쓸것.

 

11. System.out.println()(or printf() for native code) 는 절대 사용하지 말것.

System.out와 System.err는 /dev/null 로 연결되므로 아무 기능도 안하게 되는데 괜히 StringBuilder 만 잡아 먹게 된다.

 

12. 로그가 로그를 만들게 하지 말자.

 

 

 

+ Recent posts