Repository: yorkie-team/yorkie
Pull request #296 (2022-01-25 18:37:30)

Introduce named logging to separate logs by request or routine
<!--  Thanks for sending a pull request! -->

**What this PR does / why we need it**:

Introduce named logging to separate logs by request or routine

TO-BE

```bash
2022-01-26T03:36:20.960+0900    INFO    b27     SNAP: 'codepairs$tkqfj', serverSeq: 31
2022-01-26T03:36:21.334+0900    INFO    r109    PUSH: '61f0431fcd0b111db049d746' pushes 1 changes into 'codepairs$tkqfj', rejected 0 changes, serverSeq: 31 -> 32, cp: serverSeq=32, clientSeq=6
2022-01-26T03:36:21.334+0900    DEBUG   b28     Publish(codepairs$tkqfj,61f0431fcd0b111db049d746) Start
2022-01-26T03:36:21.334+0900    DEBUG   b28     Publish(codepairs$tkqfj,61f0431fcd0b111db049d746) to 61f0431ccd0b111db049d742
2022-01-26T03:36:21.334+0900    DEBUG   b28     Publish(codepairs$tkqfj,61f0431fcd0b111db049d746) End
2022-01-26T03:36:21.335+0900    INFO    b28     SNAP: 'codepairs$tkqfj', serverSeq: 32
2022-01-26T03:36:21.340+0900    INFO    r110    PULL: '61f0431ccd0b111db049d742' pulls 4 changes(29~32) from 'codepairs$tkqfj', cp: serverSeq=32, clientSeq=1
2022-01-26T03:36:23.033+0900    DEBUG   r111    Publish(codepairs$tkqfj,61f0431fcd0b111db049d746) Start
2022-01-26T03:36:23.033+0900    DEBUG   r111    Publish(codepairs$tkqfj,61f0431fcd0b111db049d746) to 61f0431ccd0b111db049d742
2022-01-26T03:36:23.033+0900    DEBUG   r111    Publish(codepairs$tkqfj,61f0431fcd0b111db049d746) End

```

**Which issue(s) this PR fixes**:
<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->
Fixes #

**Special notes for your reviewer**:

**Does this PR introduce a user-facing change?**:
<!--
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
-->
```release-note

```

**Additional documentation**:

<!--
This section can be blank if this pull request does not require a release note.

Please use the following format for linking documentation:
- [Usage]: <link>
- [Other doc]: <link>
-->
```docs

```

**Checklist**:
- [x] Added relevant tests or not required
- [x] Didn't break anything


codecov[bot]: # [Codecov](https://codecov.io/gh/yorkie-team/yorkie/pull/296?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=yorkie-team) Report
> Merging [#296](https://codecov.io/gh/yorkie-team/yorkie/pull/296?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=yorkie-team) (0fde5b8) into [main](https://codecov.io/gh/yorkie-team/yorkie/commit/904e7eaeba3ff3b4bb13b7760d390b1e9fd79df6?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=yorkie-team) (904e7ea) will **increase** coverage by `0.03%`.
> The diff coverage is `6.31%`.

[![Impacted file tree graph](https://codecov.io/gh/yorkie-team/yorkie/pull/296/graphs/tree.svg?width=650&height=150&src=pr&token=P6COB1ZNIC&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=yorkie-team)](https://codecov.io/gh/yorkie-team/yorkie/pull/296?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=yorkie-team)

```diff
@@            Coverage Diff             @@
##             main     #296      +/-   ##
==========================================
+ Coverage   48.88%   48.91%   +0.03%     
==========================================
  Files          59       59              
  Lines        4764     4767       +3     
==========================================
+ Hits         2329     2332       +3     
  Misses       2173     2173              
  Partials      262      262              
```


| [Impacted Files](https://codecov.io/gh/yorkie-team/yorkie/pull/296?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=yorkie-team) | Coverage Δ | |
|---|---|---|
| [yorkie/backend/backend.go](https://codecov.io/gh/yorkie-team/yorkie/pull/296/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=yorkie-team#diff-eW9ya2llL2JhY2tlbmQvYmFja2VuZC5nbw==) | `0.00% <0.00%> (ø)` | |
| [yorkie/backend/db/change\_info.go](https://codecov.io/gh/yorkie-team/yorkie/pull/296/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=yorkie-team#diff-eW9ya2llL2JhY2tlbmQvZGIvY2hhbmdlX2luZm8uZ28=) | `26.92% <0.00%> (ø)` | |
| [yorkie/backend/db/mongo/client.go](https://codecov.io/gh/yorkie-team/yorkie/pull/296/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=yorkie-team#diff-eW9ya2llL2JhY2tlbmQvZGIvbW9uZ28vY2xpZW50Lmdv) | `0.00% <0.00%> (ø)` | |
| [yorkie/backend/db/mongo/encoder.go](https://codecov.io/gh/yorkie-team/yorkie/pull/296/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=yorkie-team#diff-eW9ya2llL2JhY2tlbmQvZGIvbW9uZ28vZW5jb2Rlci5nbw==) | `0.00% <0.00%> (ø)` | |
| [yorkie/backend/sync/etcd/locker.go](https://codecov.io/gh/yorkie-team/yorkie/pull/296/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=yorkie-team#diff-eW9ya2llL2JhY2tlbmQvc3luYy9ldGNkL2xvY2tlci5nbw==) | `0.00% <0.00%> (ø)` | |
| [yorkie/backend/sync/etcd/membermap.go](https://codecov.io/gh/yorkie-team/yorkie/pull/296/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=yorkie-team#diff-eW9ya2llL2JhY2tlbmQvc3luYy9ldGNkL21lbWJlcm1hcC5nbw==) | `0.00% <0.00%> (ø)` | |
| [yorkie/backend/sync/etcd/pubsub.go](https://codecov.io/gh/yorkie-team/yorkie/pull/296/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=yorkie-team#diff-eW9ya2llL2JhY2tlbmQvc3luYy9ldGNkL3B1YnN1Yi5nbw==) | `0.00% <0.00%> (ø)` | |
| [yorkie/backend/sync/memory/coordinator.go](https://codecov.io/gh/yorkie-team/yorkie/pull/296/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=yorkie-team#diff-eW9ya2llL2JhY2tlbmQvc3luYy9tZW1vcnkvY29vcmRpbmF0b3IuZ28=) | `0.00% <0.00%> (ø)` | |
| [yorkie/backend/sync/memory/locker.go](https://codecov.io/gh/yorkie-team/yorkie/pull/296/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=yorkie-team#diff-eW9ya2llL2JhY2tlbmQvc3luYy9tZW1vcnkvbG9ja2VyLmdv) | `0.00% <0.00%> (ø)` | |
| [yorkie/backend/sync/memory/pubsub.go](https://codecov.io/gh/yorkie-team/yorkie/pull/296/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=yorkie-team#diff-eW9ya2llL2JhY2tlbmQvc3luYy9tZW1vcnkvcHVic3ViLmdv) | `45.45% <0.00%> (ø)` | |
| ... and [7 more](https://codecov.io/gh/yorkie-team/yorkie/pull/296/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=yorkie-team) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/yorkie-team/yorkie/pull/296?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=yorkie-team).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=yorkie-team)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/yorkie-team/yorkie/pull/296?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=yorkie-team). Last update [904e7ea...0fde5b8](https://codecov.io/gh/yorkie-team/yorkie/pull/296?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=yorkie-team). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=yorkie-team).


Patch:
diff --git a/internal/cli/agent.go b/internal/cli/agent.go
index c38e8f3a..c8ee1a45 100644
--- a/internal/cli/agent.go
+++ b/internal/cli/agent.go
@@ -28,7 +28,7 @@ import (
 	"github.com/yorkie-team/yorkie/yorkie"
 	"github.com/yorkie-team/yorkie/yorkie/backend/db/mongo"
 	"github.com/yorkie-team/yorkie/yorkie/backend/sync/etcd"
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 )
 
 var (
@@ -100,7 +100,7 @@ func newAgentCmd() *cobra.Command {
 				conf = parsed
 			}
 
-			if err := log.SetLogLevel(flagLogLevel); err != nil {
+			if err := logging.SetLogLevel(flagLogLevel); err != nil {
 				return err
 			}
 
diff --git a/yorkie/auth/webhook.go b/yorkie/auth/webhook.go
index 5f112fb4..f46acfb0 100644
--- a/yorkie/auth/webhook.go
+++ b/yorkie/auth/webhook.go
@@ -30,7 +30,7 @@ import (
 	"github.com/yorkie-team/yorkie/pkg/document/change"
 	"github.com/yorkie-team/yorkie/pkg/types"
 	"github.com/yorkie-team/yorkie/yorkie/backend"
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 )
 
 var (
@@ -96,7 +96,7 @@ func VerifyAccess(ctx context.Context, be *backend.Backend, info *types.AccessIn
 
 		defer func() {
 			if err := resp.Body.Close(); err != nil {
-				log.Logger().Error(err)
+				logging.From(ctx).Error(err)
 			}
 		}()
 
diff --git a/yorkie/backend/backend.go b/yorkie/backend/backend.go
index deb3d214..57817483 100644
--- a/yorkie/backend/backend.go
+++ b/yorkie/backend/backend.go
@@ -31,7 +31,7 @@ import (
 	"github.com/yorkie-team/yorkie/yorkie/backend/sync"
 	"github.com/yorkie-team/yorkie/yorkie/backend/sync/etcd"
 	memsync "github.com/yorkie-team/yorkie/yorkie/backend/sync/memory"
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 	"github.com/yorkie-team/yorkie/yorkie/profiling/prometheus"
 )
 
@@ -119,7 +119,7 @@ func New(
 		dbInfo = mongoConf.ConnectionURI
 	}
 
-	log.Logger().Infof(
+	logging.DefaultLogger().Infof(
 		"backend created: id: %s, rpc: %s: db: %s",
 		agentInfo.ID,
 		agentInfo.RPCAddr,
@@ -149,14 +149,14 @@ func (b *Backend) Shutdown() error {
 	}
 
 	if err := b.Coordinator.Close(); err != nil {
-		log.Logger().Error(err)
+		logging.DefaultLogger().Error(err)
 	}
 
 	if err := b.DB.Close(); err != nil {
-		log.Logger().Error(err)
+		logging.DefaultLogger().Error(err)
 	}
 
-	log.Logger().Infof(
+	logging.DefaultLogger().Infof(
 		"backend stoped: id: %s, rpc: %s",
 		b.agentInfo.ID,
 		b.agentInfo.RPCAddr,
diff --git a/yorkie/backend/background/background.go b/yorkie/backend/background/background.go
index df833b3d..b42331c5 100644
--- a/yorkie/backend/background/background.go
+++ b/yorkie/backend/background/background.go
@@ -1,11 +1,21 @@
 package background
 
 import (
+	"context"
+	"strconv"
 	"sync"
+	"sync/atomic"
 
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 )
 
+type routineID int32
+
+func (c *routineID) next() string {
+	next := atomic.AddInt32((*int32)(c), 1)
+	return "b" + strconv.Itoa(int(next))
+}
+
 // Background is the background service.
 type Background struct {
 	// closing is closed by backend close.
@@ -17,6 +27,9 @@ type Background struct {
 	// wg is used to wait for the goroutines that depends on the backend state
 	// to exit when closing the backend.
 	wg sync.WaitGroup
+
+	// routineID is used to generate routine ID.
+	routineID routineID
 }
 
 // New creates a new background service.
@@ -28,21 +41,22 @@ func New() *Background {
 
 // AttachGoroutine creates a goroutine on a given function and tracks it using
 // the background's WaitGroup.
-func (b *Background) AttachGoroutine(f func()) {
+func (b *Background) AttachGoroutine(f func(ctx context.Context)) {
 	b.wgMu.RLock() // this blocks with ongoing close(b.closing)
 	defer b.wgMu.RUnlock()
 	select {
 	case <-b.closing:
-		log.Logger().Warn("backend has closed; skipping AttachGoroutine")
+		logging.DefaultLogger().Warn("backend has closed; skipping AttachGoroutine")
 		return
 	default:
 	}
 
 	// now safe to add since WaitGroup wait has not started yet
 	b.wg.Add(1)
+	routineLogger := logging.New(b.routineID.next())
 	go func() {
 		defer b.wg.Done()
-		f()
+		f(logging.With(context.Background(), routineLogger))
 	}()
 }
 
diff --git a/yorkie/backend/db/change_info.go b/yorkie/backend/db/change_info.go
index 4da5a57f..20241aee 100644
--- a/yorkie/backend/db/change_info.go
+++ b/yorkie/backend/db/change_info.go
@@ -24,7 +24,6 @@ import (
 	"github.com/yorkie-team/yorkie/pkg/document/change"
 	"github.com/yorkie-team/yorkie/pkg/document/operation"
 	"github.com/yorkie-team/yorkie/pkg/document/time"
-	"github.com/yorkie-team/yorkie/yorkie/log"
 )
 
 // ErrEncodeOperationFailed is returned when encoding operation failed.
@@ -54,7 +53,6 @@ func EncodeOperations(operations []operation.Operation) ([][]byte, error) {
 	for _, pbOp := range changes {
 		encodedOp, err := pbOp.Marshal()
 		if err != nil {
-			log.Logger().Error(err)
 			return nil, ErrEncodeOperationFailed
 		}
 		encodedOps = append(encodedOps, encodedOp)
@@ -76,7 +74,6 @@ func (i *ChangeInfo) ToChange() (*change.Change, error) {
 	for _, bytesOp := range i.Operations {
 		pbOp := api.Operation{}
 		if err := pbOp.Unmarshal(bytesOp); err != nil {
-			log.Logger().Error(err)
 			return nil, err
 		}
 		pbOps = append(pbOps, &pbOp)
diff --git a/yorkie/backend/db/mongo/client.go b/yorkie/backend/db/mongo/client.go
index 70b62370..a8d7f4b8 100644
--- a/yorkie/backend/db/mongo/client.go
+++ b/yorkie/backend/db/mongo/client.go
@@ -31,7 +31,7 @@ import (
 	"github.com/yorkie-team/yorkie/pkg/document/change"
 	"github.com/yorkie-team/yorkie/pkg/document/time"
 	"github.com/yorkie-team/yorkie/yorkie/backend/db"
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 )
 
 // Client is a client that connects to Mongo DB and reads or saves Yorkie data.
@@ -52,7 +52,7 @@ func Dial(conf *Config) (*Client, error) {
 			SetRegistry(newRegistryBuilder().Build()),
 	)
 	if err != nil {
-		log.Logger().Error(err)
+		logging.DefaultLogger().Error(err)
 		return nil, err
 	}
 
@@ -61,16 +61,16 @@ func Dial(conf *Config) (*Client, error) {
 	defer cancel()
 
 	if err := client.Ping(ctxPing, readpref.Primary()); err != nil {
-		log.Logger().Errorf("fail to connect to %s in %f sec", conf.ConnectionURI, pingTimeout.Seconds())
+		logging.DefaultLogger().Errorf("fail to connect to %s in %f sec", conf.ConnectionURI, pingTimeout.Seconds())
 		return nil, err
 	}
 
 	if err := ensureIndexes(ctx, client.Database(conf.YorkieDatabase)); err != nil {
-		log.Logger().Error(err)
+		logging.DefaultLogger().Error(err)
 		return nil, err
 	}
 
-	log.Logger().Infof("MongoDB connected, URI: %s, DB: %s", conf.ConnectionURI, conf.YorkieDatabase)
+	logging.DefaultLogger().Infof("MongoDB connected, URI: %s, DB: %s", conf.ConnectionURI, conf.YorkieDatabase)
 
 	return &Client{
 		config: conf,
@@ -81,7 +81,7 @@ func Dial(conf *Config) (*Client, error) {
 // Close all resources of this client.
 func (c *Client) Close() error {
 	if err := c.client.Disconnect(context.Background()); err != nil {
-		log.Logger().Error(err)
+		logging.DefaultLogger().Error(err)
 		return err
 	}
 
@@ -100,7 +100,7 @@ func (c *Client) ActivateClient(ctx context.Context, key string) (*db.ClientInfo
 		},
 	}, options.Update().SetUpsert(true))
 	if err != nil {
-		log.Logger().Error(err)
+		logging.From(ctx).Error(err)
 		return nil, err
 	}
 
@@ -224,7 +224,7 @@ func (c *Client) UpdateClientInfoAfterPushPull(
 		if result.Err() == mongo.ErrNoDocuments {
 			return fmt.Errorf("%s: %w", clientInfo.Key, db.ErrClientNotFound)
 		}
-		log.Logger().Error(result.Err())
+		logging.From(ctx).Error(result.Err())
 		return result.Err()
 	}
 
@@ -279,7 +279,7 @@ func (c *Client) FindDocInfoByKey(
 		},
 	}, options.Update().SetUpsert(createDocIfNotExist))
 	if err != nil {
-		log.Logger().Error(err)
+		logging.From(ctx).Error(err)
 		return nil, err
 	}
 
@@ -299,11 +299,11 @@ func (c *Client) FindDocInfoByKey(
 			"key": bsonDocKey,
 		})
 		if result.Err() == mongo.ErrNoDocuments {
-			log.Logger().Error(result.Err())
+			logging.From(ctx).Error(result.Err())
 			return nil, fmt.Errorf("%s: %w", bsonDocKey, db.ErrDocumentNotFound)
 		}
 		if result.Err() != nil {
-			log.Logger().Error(result.Err())
+			logging.From(ctx).Error(result.Err())
 			return nil, result.Err()
 		}
 	}
@@ -354,7 +354,7 @@ func (c *Client) CreateChangeInfos(
 		models,
 		options.BulkWrite().SetOrdered(true),
 	); err != nil {
-		log.Logger().Error(err)
+		logging.From(ctx).Error(err)
 		return err
 	}
 
@@ -368,7 +368,7 @@ func (c *Client) CreateChangeInfos(
 		},
 	})
 	if err != nil {
-		log.Logger().Error(err)
+		logging.From(ctx).Error(err)
 		return err
 	}
 	if res.MatchedCount == 0 {
@@ -422,13 +422,13 @@ func (c *Client) FindChangeInfosBetweenServerSeqs(
 		},
 	}, options.Find())
 	if err != nil {
-		log.Logger().Error(err)
+		logging.From(ctx).Error(err)
 		return nil, err
 	}
 
 	var infos []*db.ChangeInfo
 	if err := cursor.All(ctx, &infos); err != nil {
-		log.Logger().Error(cursor.Err())
+		logging.From(ctx).Error(cursor.Err())
 		return nil, cursor.Err()
 	}
 
@@ -456,7 +456,7 @@ func (c *Client) CreateSnapshotInfo(
 		"snapshot":   snapshot,
 		"created_at": gotime.Now(),
 	}); err != nil {
-		log.Logger().Error(err)
+		logging.From(ctx).Error(err)
 		return err
 	}
 
@@ -485,7 +485,7 @@ func (c *Client) FindLastSnapshotInfo(
 	}
 
 	if result.Err() != nil {
-		log.Logger().Error(result.Err())
+		logging.From(ctx).Error(result.Err())
 		return nil, result.Err()
 	}
 
@@ -524,7 +524,7 @@ func (c *Client) UpdateAndFindMinSyncedTicket(
 		return time.InitialTicket, nil
 	}
 	if result.Err() != nil {
-		log.Logger().Error(result.Err())
+		logging.From(ctx).Error(result.Err())
 		return nil, result.Err()
 	}
 	syncedSeqInfo := db.SyncedSeqInfo{}
@@ -575,7 +575,7 @@ func (c *Client) UpdateSyncedSeq(
 			"doc_id":    encodedDocID,
 			"client_id": encodedClientID,
 		}, options.Delete()); err != nil {
-			log.Logger().Error(err)
+			logging.From(ctx).Error(err)
 			return err
 		}
 		return nil
@@ -596,7 +596,7 @@ func (c *Client) UpdateSyncedSeq(
 			"server_seq": serverSeq,
 		},
 	}, options.Update().SetUpsert(true)); err != nil {
-		log.Logger().Error(err)
+		logging.From(ctx).Error(err)
 		return err
 	}
 
@@ -631,7 +631,7 @@ func (c *Client) findTicketByServerSeq(
 	}
 
 	if result.Err() != nil {
-		log.Logger().Error(result.Err())
+		logging.From(ctx).Error(result.Err())
 		return nil, result.Err()
 	}
 
diff --git a/yorkie/backend/db/mongo/encoder.go b/yorkie/backend/db/mongo/encoder.go
index 07ee06ce..83da77b8 100644
--- a/yorkie/backend/db/mongo/encoder.go
+++ b/yorkie/backend/db/mongo/encoder.go
@@ -23,7 +23,6 @@ import (
 
 	"github.com/yorkie-team/yorkie/pkg/document/time"
 	"github.com/yorkie-team/yorkie/yorkie/backend/db"
-	"github.com/yorkie-team/yorkie/yorkie/log"
 )
 
 func encodeActorID(id *time.ActorID) primitive.ObjectID {
@@ -35,7 +34,6 @@ func encodeActorID(id *time.ActorID) primitive.ObjectID {
 func encodeID(id db.ID) (primitive.ObjectID, error) {
 	objectID, err := primitive.ObjectIDFromHex(id.String())
 	if err != nil {
-		log.Logger().Error(err)
 		return objectID, fmt.Errorf("%s: %w", id, db.ErrInvalidID)
 	}
 	return objectID, nil
diff --git a/yorkie/backend/housekeeping/housekeeping.go b/yorkie/backend/housekeeping/housekeeping.go
index d6d23e30..1cd0fd86 100644
--- a/yorkie/backend/housekeeping/housekeeping.go
+++ b/yorkie/backend/housekeeping/housekeeping.go
@@ -23,7 +23,7 @@ import (
 
 	"github.com/yorkie-team/yorkie/yorkie/backend/db"
 	"github.com/yorkie-team/yorkie/yorkie/backend/sync"
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 )
 
 const (
@@ -141,7 +141,8 @@ func (h *Housekeeping) Stop() error {
 // run is the housekeeping loop.
 func (h *Housekeeping) run() {
 	for {
-		if err := h.deactivateCandidates(context.Background()); err != nil {
+		ctx := context.Background()
+		if err := h.deactivateCandidates(ctx); err != nil {
 			continue
 		}
 
@@ -167,7 +168,7 @@ func (h *Housekeeping) deactivateCandidates(ctx context.Context) error {
 
 	defer func() {
 		if err := locker.Unlock(ctx); err != nil {
-			log.Logger().Error(err)
+			logging.From(ctx).Error(err)
 		}
 	}()
 
@@ -208,7 +209,7 @@ func (h *Housekeeping) deactivateCandidates(ctx context.Context) error {
 	}
 
 	if len(candidates) > 0 {
-		log.Logger().Infof(
+		logging.From(ctx).Infof(
 			"HSKP: candidates %d, deactivated %d, %s",
 			len(candidates),
 			deactivatedCount,
diff --git a/yorkie/backend/sync/etcd/client.go b/yorkie/backend/sync/etcd/client.go
index b62e84e8..f2badc15 100644
--- a/yorkie/backend/sync/etcd/client.go
+++ b/yorkie/backend/sync/etcd/client.go
@@ -26,7 +26,7 @@ import (
 	"github.com/yorkie-team/yorkie/api"
 	"github.com/yorkie-team/yorkie/yorkie/backend/sync"
 	"github.com/yorkie-team/yorkie/yorkie/backend/sync/memory"
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 )
 
 // clusterClientInfo represents a cluster client and its connection.
@@ -101,11 +101,11 @@ func (c *Client) Dial() error {
 		Password:    c.config.Password,
 	})
 	if err != nil {
-		log.Logger().Error(err)
+		logging.DefaultLogger().Error(err)
 		return err
 	}
 
-	log.Logger().Infof("etcd connected, URI: %s", c.config.Endpoints)
+	logging.DefaultLogger().Infof("etcd connected, URI: %s", c.config.Endpoints)
 
 	c.client = cli
 	return nil
@@ -116,7 +116,7 @@ func (c *Client) Close() error {
 	c.cancelFunc()
 
 	if err := c.removeAgent(context.Background()); err != nil {
-		log.Logger().Error(err)
+		logging.DefaultLogger().Error(err)
 	}
 
 	for id := range c.clusterClientMap {
diff --git a/yorkie/backend/sync/etcd/locker.go b/yorkie/backend/sync/etcd/locker.go
index 5f7883e3..8661bd47 100644
--- a/yorkie/backend/sync/etcd/locker.go
+++ b/yorkie/backend/sync/etcd/locker.go
@@ -22,7 +22,7 @@ import (
 	"go.etcd.io/etcd/client/v3/concurrency"
 
 	"github.com/yorkie-team/yorkie/yorkie/backend/sync"
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 )
 
 // NewLocker creates locker of the given key.
@@ -37,7 +37,7 @@ func (c *Client) NewLocker(
 		concurrency.WithTTL(ttl),
 	)
 	if err != nil {
-		log.Logger().Error(err)
+		logging.DefaultLogger().Error(err)
 		return nil, err
 	}
 
@@ -55,7 +55,7 @@ type internalLocker struct {
 // Lock locks the mutex with a cancelable context
 func (il *internalLocker) Lock(ctx context.Context) error {
 	if err := il.mu.Lock(ctx); err != nil {
-		log.Logger().Error(err)
+		logging.DefaultLogger().Error(err)
 		return err
 	}
 
@@ -69,7 +69,7 @@ func (il *internalLocker) TryLock(ctx context.Context) error {
 			return sync.ErrAlreadyLocked
 		}
 
-		log.Logger().Error(err)
+		logging.DefaultLogger().Error(err)
 		return err
 	}
 
@@ -79,7 +79,7 @@ func (il *internalLocker) TryLock(ctx context.Context) error {
 // Unlock unlocks the mutex.
 func (il *internalLocker) Unlock(ctx context.Context) error {
 	if err := il.mu.Unlock(ctx); err != nil {
-		log.Logger().Error(err)
+		logging.DefaultLogger().Error(err)
 		return err
 	}
 
diff --git a/yorkie/backend/sync/etcd/membermap.go b/yorkie/backend/sync/etcd/membermap.go
index 18f4d045..899d90a2 100644
--- a/yorkie/backend/sync/etcd/membermap.go
+++ b/yorkie/backend/sync/etcd/membermap.go
@@ -27,7 +27,7 @@ import (
 	clientv3 "go.etcd.io/etcd/client/v3"
 
 	"github.com/yorkie-team/yorkie/yorkie/backend/sync"
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 )
 
 const (
@@ -92,7 +92,7 @@ func (c *Client) initializeMemberMap(ctx context.Context) error {
 func (c *Client) putAgentPeriodically() {
 	for {
 		if err := c.putAgent(c.ctx); err != nil {
-			log.Logger().Error(err)
+			logging.DefaultLogger().Error(err)
 		}
 
 		select {
@@ -149,7 +149,7 @@ func (c *Client) syncAgents() {
 				case mvccpb.PUT:
 					var info sync.AgentInfo
 					if err := json.Unmarshal(event.Kv.Value, &info); err != nil {
-						log.Logger().Error(err)
+						logging.DefaultLogger().Error(err)
 						continue
 					}
 					c.setAgentInfo(k, info)
diff --git a/yorkie/backend/sync/etcd/pubsub.go b/yorkie/backend/sync/etcd/pubsub.go
index c343158a..06be93fe 100644
--- a/yorkie/backend/sync/etcd/pubsub.go
+++ b/yorkie/backend/sync/etcd/pubsub.go
@@ -30,7 +30,7 @@ import (
 	"github.com/yorkie-team/yorkie/pkg/document/time"
 	"github.com/yorkie-team/yorkie/pkg/types"
 	"github.com/yorkie-team/yorkie/yorkie/backend/sync"
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 )
 
 const (
@@ -43,7 +43,7 @@ func (c *Client) Subscribe(
 	subscriber types.Client,
 	keys []*key.Key,
 ) (*sync.Subscription, map[string][]types.Client, error) {
-	sub, err := c.localPubSub.Subscribe(subscriber, keys)
+	sub, err := c.localPubSub.Subscribe(ctx, subscriber, keys)
 	if err != nil {
 		return nil, nil, err
 	}
@@ -74,7 +74,7 @@ func (c *Client) Unsubscribe(
 	keys []*key.Key,
 	sub *sync.Subscription,
 ) error {
-	c.localPubSub.Unsubscribe(keys, sub)
+	c.localPubSub.Unsubscribe(ctx, keys, sub)
 	return c.removeSubscriptions(ctx, keys, sub)
 }
 
@@ -84,7 +84,7 @@ func (c *Client) Publish(
 	publisherID *time.ActorID,
 	event sync.DocEvent,
 ) {
-	c.localPubSub.Publish(publisherID, event)
+	c.localPubSub.Publish(ctx, publisherID, event)
 	c.broadcastToMembers(ctx, event)
 }
 
@@ -94,7 +94,7 @@ func (c *Client) PublishToLocal(
 	publisherID *time.ActorID,
 	event sync.DocEvent,
 ) {
-	c.localPubSub.Publish(publisherID, event)
+	c.localPubSub.Publish(ctx, publisherID, event)
 }
 
 // UpdateMetadata updates the metadata of the given client.
@@ -153,7 +153,7 @@ func (c *Client) ensureClusterClient(
 	if _, ok := c.clusterClientMap[member.ID]; !ok {
 		conn, err := grpc.Dial(member.RPCAddr, grpc.WithInsecure())
 		if err != nil {
-			log.Logger().Error(err)
+			logging.DefaultLogger().Error(err)
 			return nil, err
 		}
 
@@ -173,7 +173,7 @@ func (c *Client) removeClusterClient(id string) {
 
 	if info, ok := c.clusterClientMap[id]; ok {
 		if err := info.conn.Close(); err != nil {
-			log.Logger().Error(err)
+			logging.DefaultLogger().Error(err)
 		}
 
 		delete(c.clusterClientMap, id)
@@ -189,7 +189,7 @@ func (c *Client) publishToMember(
 ) error {
 	docEvent, err := converter.ToDocEvent(event)
 	if err != nil {
-		log.Logger().Error(err)
+		logging.From(ctx).Error(err)
 		return err
 	}
 
@@ -197,7 +197,7 @@ func (c *Client) publishToMember(
 		PublisherId: publisherID.Bytes(),
 		Event:       docEvent,
 	}); err != nil {
-		log.Logger().Error(err)
+		logging.From(ctx).Error(err)
 		return err
 	}
 
@@ -219,7 +219,7 @@ func (c *Client) putSubscriptions(
 	for _, k := range keys {
 		k := path.Join(subscriptionsPath, k.BSONKey(), sub.ID())
 		if _, err = c.client.Put(ctx, k, encoded); err != nil {
-			log.Logger().Error(err)
+			logging.From(ctx).Error(err)
 			return fmt.Errorf("put %s: %w", k, err)
 		}
 	}
@@ -238,7 +238,7 @@ func (c *Client) pullSubscriptions(
 		clientv3.WithPrefix(),
 	)
 	if err != nil {
-		log.Logger().Error(err)
+		logging.From(ctx).Error(err)
 		return nil, err
 	}
 
@@ -263,7 +263,7 @@ func (c *Client) removeSubscriptions(
 	for _, docKey := range keys {
 		k := path.Join(subscriptionsPath, docKey.BSONKey(), sub.ID())
 		if _, err := c.client.Delete(ctx, k); err != nil {
-			log.Logger().Error(err)
+			logging.From(ctx).Error(err)
 			return err
 		}
 	}
diff --git a/yorkie/backend/sync/memory/coordinator.go b/yorkie/backend/sync/memory/coordinator.go
index 3edc8b71..87614de5 100644
--- a/yorkie/backend/sync/memory/coordinator.go
+++ b/yorkie/backend/sync/memory/coordinator.go
@@ -45,66 +45,66 @@ func NewCoordinator(agentInfo *sync.AgentInfo) *Coordinator {
 }
 
 // NewLocker creates locker of the given key.
-func (m *Coordinator) NewLocker(
+func (c *Coordinator) NewLocker(
 	ctx context.Context,
 	key sync.Key,
 ) (sync.Locker, error) {
 	return &internalLocker{
 		key.String(),
-		m.locks,
+		c.locks,
 	}, nil
 }
 
 // Subscribe subscribes to the given documents.
-func (m *Coordinator) Subscribe(
-	_ context.Context,
+func (c *Coordinator) Subscribe(
+	ctx context.Context,
 	subscriber types.Client,
 	keys []*key.Key,
 ) (*sync.Subscription, map[string][]types.Client, error) {
-	sub, err := m.pubSub.Subscribe(subscriber, keys)
+	sub, err := c.pubSub.Subscribe(ctx, subscriber, keys)
 	if err != nil {
 		return nil, nil, err
 	}
 
-	peersMap := m.pubSub.BuildPeersMap(keys)
+	peersMap := c.pubSub.BuildPeersMap(keys)
 	return sub, peersMap, nil
 }
 
 // Unsubscribe unsubscribes the given documents.
-func (m *Coordinator) Unsubscribe(
-	_ context.Context,
+func (c *Coordinator) Unsubscribe(
+	ctx context.Context,
 	keys []*key.Key,
 	sub *sync.Subscription,
 ) error {
-	m.pubSub.Unsubscribe(keys, sub)
+	c.pubSub.Unsubscribe(ctx, keys, sub)
 	return nil
 }
 
 // Publish publishes the given event.
-func (m *Coordinator) Publish(
-	_ context.Context,
+func (c *Coordinator) Publish(
+	ctx context.Context,
 	publisherID *time.ActorID,
 	event sync.DocEvent,
 ) {
-	m.pubSub.Publish(publisherID, event)
+	c.pubSub.Publish(ctx, publisherID, event)
 }
 
 // PublishToLocal publishes the given event.
-func (m *Coordinator) PublishToLocal(
-	_ context.Context,
+func (c *Coordinator) PublishToLocal(
+	ctx context.Context,
 	publisherID *time.ActorID,
 	event sync.DocEvent,
 ) {
-	m.pubSub.Publish(publisherID, event)
+	c.pubSub.Publish(ctx, publisherID, event)
 }
 
 // UpdateMetadata updates the metadata of the given client.
-func (m *Coordinator) UpdateMetadata(
+func (c *Coordinator) UpdateMetadata(
 	_ context.Context,
 	publisher *types.Client,
 	keys []*key.Key,
 ) (*sync.DocEvent, error) {
-	m.pubSub.UpdateMetadata(publisher, keys)
+	c.pubSub.UpdateMetadata(publisher, keys)
 
 	return &sync.DocEvent{
 		Type:         types.MetadataChangedEvent,
@@ -114,13 +114,13 @@ func (m *Coordinator) UpdateMetadata(
 }
 
 // Members returns the members of this cluster.
-func (m *Coordinator) Members() map[string]*sync.AgentInfo {
+func (c *Coordinator) Members() map[string]*sync.AgentInfo {
 	members := make(map[string]*sync.AgentInfo)
-	members[m.agentInfo.ID] = m.agentInfo
+	members[c.agentInfo.ID] = c.agentInfo
 	return members
 }
 
 // Close closes all resources of this Coordinator.
-func (m *Coordinator) Close() error {
+func (c *Coordinator) Close() error {
 	return nil
 }
diff --git a/yorkie/backend/sync/memory/locker.go b/yorkie/backend/sync/memory/locker.go
index a5ef1625..7d0fc7de 100644
--- a/yorkie/backend/sync/memory/locker.go
+++ b/yorkie/backend/sync/memory/locker.go
@@ -21,7 +21,7 @@ import (
 
 	"github.com/moby/locker"
 
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 )
 
 type internalLocker struct {
@@ -47,7 +47,7 @@ func (il *internalLocker) TryLock(ctx context.Context) error {
 // Unlock unlocks the mutex.
 func (il *internalLocker) Unlock(ctx context.Context) error {
 	if err := il.locks.Unlock(il.key); err != nil {
-		log.Logger().Error(err)
+		logging.DefaultLogger().Error(err)
 		return err
 	}
 
diff --git a/yorkie/backend/sync/memory/pubsub.go b/yorkie/backend/sync/memory/pubsub.go
index 35781217..694b0eb3 100644
--- a/yorkie/backend/sync/memory/pubsub.go
+++ b/yorkie/backend/sync/memory/pubsub.go
@@ -17,6 +17,7 @@
 package memory
 
 import (
+	"context"
 	gosync "sync"
 	gotime "time"
 
@@ -26,7 +27,7 @@ import (
 	"github.com/yorkie-team/yorkie/pkg/document/time"
 	"github.com/yorkie-team/yorkie/pkg/types"
 	"github.com/yorkie-team/yorkie/yorkie/backend/sync"
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 )
 
 // subscriptions is a map of subscriptions.
@@ -81,6 +82,7 @@ func NewPubSub() *PubSub {
 
 // Subscribe subscribes to the given document keys.
 func (m *PubSub) Subscribe(
+	ctx context.Context,
 	subscriber types.Client,
 	keys []*key.Key,
 ) (*sync.Subscription, error) {
@@ -88,8 +90,8 @@ func (m *PubSub) Subscribe(
 		return nil, sync.ErrEmptyDocKeys
 	}
 
-	if log.Core().Enabled(zap.DebugLevel) {
-		log.Logger().Debugf(
+	if logging.Enabled(zap.DebugLevel) {
+		logging.From(ctx).Debugf(
 			`Subscribe(%s,%s) Start`,
 			keys[0].BSONKey(),
 			subscriber.ID.String(),
@@ -110,8 +112,8 @@ func (m *PubSub) Subscribe(
 		m.subscriptionsMapByDocKey[bsonKey].Add(sub)
 	}
 
-	if log.Core().Enabled(zap.DebugLevel) {
-		log.Logger().Debugf(
+	if logging.Enabled(zap.DebugLevel) {
+		logging.From(ctx).Debugf(
 			`Subscribe(%s,%s) End`,
 			keys[0].BSONKey(),
 			subscriber.ID.String(),
@@ -136,14 +138,15 @@ func (m *PubSub) BuildPeersMap(keys []*key.Key) map[string][]types.Client {
 
 // Unsubscribe unsubscribes the given docKeys.
 func (m *PubSub) Unsubscribe(
+	ctx context.Context,
 	docKeys []*key.Key,
 	sub *sync.Subscription,
 ) {
 	m.subscriptionsMapMu.Lock()
 	defer m.subscriptionsMapMu.Unlock()
 
-	if log.Core().Enabled(zap.DebugLevel) {
-		log.Logger().Debugf(
+	if logging.Enabled(zap.DebugLevel) {
+		logging.From(ctx).Debugf(
 			`Unsubscribe(%s,%s) Start`,
 			docKeys[0].BSONKey(),
 			sub.SubscriberID(),
@@ -164,8 +167,8 @@ func (m *PubSub) Unsubscribe(
 		}
 	}
 
-	if log.Core().Enabled(zap.DebugLevel) {
-		log.Logger().Debugf(
+	if logging.Enabled(zap.DebugLevel) {
+		logging.From(ctx).Debugf(
 			`Unsubscribe(%s,%s) End`,
 			docKeys[0].BSONKey(),
 			sub.SubscriberID(),
@@ -175,6 +178,7 @@ func (m *PubSub) Unsubscribe(
 
 // Publish publishes the given event.
 func (m *PubSub) Publish(
+	ctx context.Context,
 	publisherID *time.ActorID,
 	event sync.DocEvent,
 ) {
@@ -184,8 +188,8 @@ func (m *PubSub) Publish(
 	for _, docKey := range event.DocumentKeys {
 		k := docKey.BSONKey()
 
-		if log.Core().Enabled(zap.DebugLevel) {
-			log.Logger().Debugf(`Publish(%s,%s) Start`, k, publisherID.String())
+		if logging.Enabled(zap.DebugLevel) {
+			logging.From(ctx).Debugf(`Publish(%s,%s) Start`, k, publisherID.String())
 		}
 
 		if subs, ok := m.subscriptionsMapByDocKey[k]; ok {
@@ -194,8 +198,8 @@ func (m *PubSub) Publish(
 					continue
 				}
 
-				if log.Core().Enabled(zap.DebugLevel) {
-					log.Logger().Debugf(
+				if logging.Enabled(zap.DebugLevel) {
+					logging.From(ctx).Debugf(
 						`Publish(%s,%s) to %s`,
 						k,
 						publisherID.String(),
@@ -208,7 +212,7 @@ func (m *PubSub) Publish(
 				select {
 				case sub.Events() <- event:
 				case <-gotime.After(100 * gotime.Millisecond):
-					log.Logger().Warnf(
+					logging.From(ctx).Warnf(
 						`Publish(%s,%s) to %s timeout`,
 						k,
 						publisherID.String(),
@@ -217,8 +221,8 @@ func (m *PubSub) Publish(
 				}
 			}
 		}
-		if log.Core().Enabled(zap.DebugLevel) {
-			log.Logger().Debugf(`Publish(%s,%s) End`, k, publisherID.String())
+		if logging.Enabled(zap.DebugLevel) {
+			logging.From(ctx).Debugf(`Publish(%s,%s) End`, k, publisherID.String())
 		}
 	}
 }
diff --git a/yorkie/config.go b/yorkie/config.go
index 507da3b3..1eb4ed68 100644
--- a/yorkie/config.go
+++ b/yorkie/config.go
@@ -28,7 +28,7 @@ import (
 	"github.com/yorkie-team/yorkie/yorkie/backend/db/mongo"
 	"github.com/yorkie-team/yorkie/yorkie/backend/housekeeping"
 	"github.com/yorkie-team/yorkie/yorkie/backend/sync/etcd"
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 	"github.com/yorkie-team/yorkie/yorkie/profiling"
 	"github.com/yorkie-team/yorkie/yorkie/rpc"
 )
@@ -80,12 +80,12 @@ func NewConfigFromFile(path string) (*Config, error) {
 	conf := &Config{}
 	bytes, err := ioutil.ReadFile(filepath.Clean(path))
 	if err != nil {
-		log.Logger().Error(err)
+		logging.DefaultLogger().Error(err)
 		return nil, err
 	}
 
 	if err = yaml.Unmarshal(bytes, conf); err != nil {
-		log.Logger().Error(err)
+		logging.DefaultLogger().Error(err)
 		return nil, err
 	}
 
diff --git a/yorkie/logging/context.go b/yorkie/logging/context.go
new file mode 100644
index 00000000..95aeb6dd
--- /dev/null
+++ b/yorkie/logging/context.go
@@ -0,0 +1,27 @@
+package logging
+
+import (
+	"context"
+)
+
+// loggerKey is the type used for the logger key in context.
+type loggerKey struct{}
+
+// With returns a new context with the provided logger.
+func With(ctx context.Context, logger Logger) context.Context {
+	return context.WithValue(ctx, loggerKey{}, logger)
+}
+
+// From returns the logger stored in the provided context.
+func From(ctx context.Context) Logger {
+	if ctx == nil {
+		return defaultLogger
+	}
+
+	logger, ok := ctx.Value(loggerKey{}).(Logger)
+	if !ok {
+		return defaultLogger
+	}
+
+	return logger
+}
diff --git a/yorkie/log/log.go b/yorkie/logging/logging.go
similarity index 75%
rename from yorkie/log/log.go
rename to yorkie/logging/logging.go
index 60ad224d..ca6195ec 100644
--- a/yorkie/log/log.go
+++ b/yorkie/logging/logging.go
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package log
+package logging
 
 import (
 	"fmt"
@@ -26,30 +26,15 @@ import (
 	"go.uber.org/zap/zapcore"
 )
 
-var defaultLogger *zap.SugaredLogger
-var coreLogger zapcore.Core
+// Logger is a wrapper of zap.Logger.
+type Logger = *zap.SugaredLogger
 
+var defaultLogger Logger
 var logLevel = zapcore.InfoLevel
 var loggerOnce sync.Once
 
-// Logger returns the default logger used by Yorkie.
-func Logger() *zap.SugaredLogger {
-	loggerOnce.Do(func() {
-		initialize()
-	})
-	return defaultLogger
-}
-
-// Core returns the Core logger, where Core is a minimal, fast logger interface.
-func Core() zapcore.Core {
-	loggerOnce.Do(func() {
-		initialize()
-	})
-	return coreLogger
-}
-
 // SetLogLevel sets the level of global logger with ["debug", "info", "warn", "error", "panic", "fatal"].
-// Loglevel must be sets before calling DefaultLogger() or CoreLogger() function.
+// SetLoglevel must be sets before calling DefaultLogger() or New().
 func SetLogLevel(level string) error {
 	switch strings.ToLower(level) {
 	case "debug":
@@ -70,6 +55,35 @@ func SetLogLevel(level string) error {
 	return nil
 }
 
+// New creates a new logger with the given configuration.
+func New(name string) Logger {
+	return newLogger(name)
+}
+
+// DefaultLogger returns the default logger used by Yorkie.
+func DefaultLogger() Logger {
+	loggerOnce.Do(func() {
+		defaultLogger = newLogger("default")
+	})
+	return defaultLogger
+}
+
+// Enabled returns true if the given level is enabled.
+func Enabled(level zapcore.Level) bool {
+	return level >= logLevel
+}
+
+// newLogger returns a new raw logger.
+func newLogger(name string) Logger {
+	return zap.New(zapcore.NewTee(
+		zapcore.NewCore(
+			zapcore.NewConsoleEncoder(humanEncoderConfig()),
+			zapcore.AddSync(os.Stdout),
+			logLevel,
+		),
+	), zap.AddStacktrace(zap.ErrorLevel)).Named(name).Sugar()
+}
+
 func encoderConfig() zapcore.EncoderConfig {
 	return zapcore.EncoderConfig{
 		TimeKey:        "T",
@@ -93,15 +107,3 @@ func humanEncoderConfig() zapcore.EncoderConfig {
 	cfg.EncodeDuration = zapcore.StringDurationEncoder
 	return cfg
 }
-
-func initialize() {
-	rawLogger := zap.New(zapcore.NewTee(
-		zapcore.NewCore(
-			zapcore.NewConsoleEncoder(humanEncoderConfig()),
-			zapcore.AddSync(os.Stdout),
-			logLevel,
-		),
-	), zap.AddStacktrace(zap.ErrorLevel))
-	defaultLogger = rawLogger.Sugar()
-	coreLogger = rawLogger.Core()
-}
diff --git a/yorkie/packs/packs.go b/yorkie/packs/packs.go
index 887479f4..c62bb175 100644
--- a/yorkie/packs/packs.go
+++ b/yorkie/packs/packs.go
@@ -28,7 +28,7 @@ import (
 	"github.com/yorkie-team/yorkie/yorkie/backend"
 	"github.com/yorkie-team/yorkie/yorkie/backend/db"
 	"github.com/yorkie-team/yorkie/yorkie/backend/sync"
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 )
 
 // NewPushPullKey creates a new sync.Key of PushPull for the given document.
@@ -60,7 +60,7 @@ func PushPull(
 	initialServerSeq := docInfo.ServerSeq
 
 	// 01. push changes.
-	pushedCP, pushedChanges, err := pushChanges(clientInfo, docInfo, reqPack, initialServerSeq)
+	pushedCP, pushedChanges, err := pushChanges(ctx, clientInfo, docInfo, reqPack, initialServerSeq)
 	if err != nil {
 		return nil, err
 	}
@@ -107,20 +107,19 @@ func PushPull(
 
 	// 05. publish document change event then store snapshot asynchronously.
 	if reqPack.HasChanges() {
-		be.Background.AttachGoroutine(func() {
+		be.Background.AttachGoroutine(func(ctx context.Context) {
 			publisherID, err := time.ActorIDFromHex(clientInfo.ID.String())
 			if err != nil {
-				log.Logger().Error(err)
+				logging.From(ctx).Error(err)
 				return
 			}
 
-			ctx := context.Background()
 			locker, err := be.Coordinator.NewLocker(
 				ctx,
 				NewSnapshotKey(reqPack.DocumentKey),
 			)
 			if err != nil {
-				log.Logger().Error(err)
+				logging.From(ctx).Error(err)
 				return
 			}
 			// NOTE: If the snapshot is already being created by another routine, it
@@ -131,7 +130,7 @@ func PushPull(
 
 			defer func() {
 				if err := locker.Unlock(ctx); err != nil {
-					log.Logger().Error(err)
+					logging.From(ctx).Error(err)
 					return
 				}
 			}()
@@ -153,7 +152,7 @@ func PushPull(
 				docInfo,
 				minSyncedTicket,
 			); err != nil {
-				log.Logger().Error(err)
+				logging.From(ctx).Error(err)
 			}
 			be.Metrics.ObservePushPullSnapshotDurationSeconds(
 				gotime.Since(start).Seconds(),
diff --git a/yorkie/packs/pushpull.go b/yorkie/packs/pushpull.go
index 16c23632..2c521be0 100644
--- a/yorkie/packs/pushpull.go
+++ b/yorkie/packs/pushpull.go
@@ -28,7 +28,7 @@ import (
 	"github.com/yorkie-team/yorkie/pkg/document/change"
 	"github.com/yorkie-team/yorkie/yorkie/backend"
 	"github.com/yorkie-team/yorkie/yorkie/backend/db"
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 )
 
 var (
@@ -39,6 +39,7 @@ var (
 
 // pushChanges returns the changes excluding already saved in DB.
 func pushChanges(
+	ctx context.Context,
 	clientInfo *db.ClientInfo,
 	docInfo *db.DocInfo,
 	pack *change.Pack,
@@ -54,14 +55,14 @@ func pushChanges(
 			cn.SetServerSeq(serverSeq)
 			pushedChanges = append(pushedChanges, cn)
 		} else {
-			log.Logger().Warnf("change already pushed: %d vs %d ", cn.ID().ClientSeq(), cp.ClientSeq)
+			logging.From(ctx).Warnf("change already pushed: %d vs %d ", cn.ID().ClientSeq(), cp.ClientSeq)
 		}
 
 		cp = cp.SyncClientSeq(cn.ClientSeq())
 	}
 
 	if len(pack.Changes) > 0 {
-		log.Logger().Infof(
+		logging.From(ctx).Infof(
 			"PUSH: '%s' pushes %d changes into '%s', rejected %d changes, serverSeq: %d -> %d, cp: %s",
 			clientInfo.ID,
 			len(pushedChanges),
@@ -137,7 +138,7 @@ func pullChangeInfos(
 	pulledCP := pushedCP.NextServerSeq(docInfo.ServerSeq)
 
 	if len(pulledChanges) > 0 {
-		log.Logger().Infof(
+		logging.From(ctx).Infof(
 			"PULL: '%s' pulls %d changes(%d~%d) from '%s', cp: %s",
 			clientInfo.ID,
 			len(pulledChanges),
@@ -167,7 +168,7 @@ func pullSnapshot(
 
 	if snapshotInfo.ServerSeq >= initialServerSeq {
 		pulledCP := pushedCP.NextServerSeq(docInfo.ServerSeq)
-		log.Logger().Infof(
+		logging.From(ctx).Infof(
 			"PULL: '%s' pulls snapshot without changes from '%s', cp: %s",
 			clientInfo.ID,
 			docInfo.Key,
@@ -213,8 +214,8 @@ func pullSnapshot(
 		return nil, nil, err
 	}
 
-	if log.Core().Enabled(zap.DebugLevel) {
-		log.Logger().Debugf(
+	if logging.Enabled(zap.DebugLevel) {
+		logging.From(ctx).Debugf(
 			"after apply %d changes: elements: %d removeds: %d, %s",
 			len(pack.Changes),
 			doc.Root().ElementMapLen(),
@@ -225,7 +226,7 @@ func pullSnapshot(
 
 	pulledCP := pushedCP.NextServerSeq(docInfo.ServerSeq)
 
-	log.Logger().Infof(
+	logging.From(ctx).Infof(
 		"PULL: '%s' pulls snapshot with changes(%d~%d) from '%s', cp: %s",
 		clientInfo.ID,
 		pack.Checkpoint.ServerSeq+1,
diff --git a/yorkie/packs/serverpacks.go b/yorkie/packs/serverpacks.go
index 0f9d3926..85f882e6 100644
--- a/yorkie/packs/serverpacks.go
+++ b/yorkie/packs/serverpacks.go
@@ -23,7 +23,7 @@ import (
 	"github.com/yorkie-team/yorkie/pkg/document/key"
 	"github.com/yorkie-team/yorkie/pkg/document/time"
 	"github.com/yorkie-team/yorkie/yorkie/backend/db"
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 )
 
 // ServerPack is similar to change.Pack, but has ChangeInfos instead of Changes
@@ -94,7 +94,7 @@ func (p *ServerPack) ToPBChangePack() (*api.ChangePack, error) {
 		for _, bytesOp := range changeInfo.Operations {
 			pbOp := api.Operation{}
 			if err := pbOp.Unmarshal(bytesOp); err != nil {
-				log.Logger().Error(err)
+				logging.DefaultLogger().Error(err)
 				return nil, err
 			}
 			pbOps = append(pbOps, &pbOp)
diff --git a/yorkie/packs/snapshots.go b/yorkie/packs/snapshots.go
index fa9ea6ab..b8e21918 100644
--- a/yorkie/packs/snapshots.go
+++ b/yorkie/packs/snapshots.go
@@ -24,7 +24,7 @@ import (
 	"github.com/yorkie-team/yorkie/pkg/document/time"
 	"github.com/yorkie-team/yorkie/yorkie/backend"
 	"github.com/yorkie-team/yorkie/yorkie/backend/db"
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 )
 
 func storeSnapshot(
@@ -91,7 +91,7 @@ func storeSnapshot(
 		return err
 	}
 
-	log.Logger().Infof(
+	logging.From(ctx).Infof(
 		"SNAP: '%s', serverSeq: %d",
 		docInfo.Key,
 		doc.Checkpoint().ServerSeq,
diff --git a/yorkie/profiling/server.go b/yorkie/profiling/server.go
index eef7db5c..0fe78d31 100644
--- a/yorkie/profiling/server.go
+++ b/yorkie/profiling/server.go
@@ -24,7 +24,7 @@ import (
 
 	"github.com/prometheus/client_golang/prometheus/promhttp"
 
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 	"github.com/yorkie-team/yorkie/yorkie/profiling/prometheus"
 )
 
@@ -79,22 +79,22 @@ func (s *Server) Start() error {
 func (s *Server) Shutdown(graceful bool) {
 	if graceful {
 		if err := s.httpServer.Shutdown(context.Background()); err != nil {
-			log.Logger().Error("HTTP server Shutdown: %v", err)
+			logging.DefaultLogger().Error("HTTP server Shutdown: %v", err)
 		}
 		return
 	}
 
 	if err := s.httpServer.Close(); err != nil {
-		log.Logger().Error("HTTP server close: %v", err)
+		logging.DefaultLogger().Error("HTTP server close: %v", err)
 	}
 }
 
 func (s *Server) listenAndServe() error {
 	go func() {
-		log.Logger().Infof(fmt.Sprintf("serving profiling on %d", s.conf.Port))
+		logging.DefaultLogger().Infof(fmt.Sprintf("serving profiling on %d", s.conf.Port))
 		s.httpServer.Handler = s.serveMux
 		if err := s.httpServer.ListenAndServe(); err != http.ErrServerClosed {
-			log.Logger().Error("HTTP server ListenAndServe: %v", err)
+			logging.DefaultLogger().Error("HTTP server ListenAndServe: %v", err)
 		}
 	}()
 	return nil
diff --git a/yorkie/rpc/cluster_server.go b/yorkie/rpc/cluster_server.go
index 409ea560..3af85823 100644
--- a/yorkie/rpc/cluster_server.go
+++ b/yorkie/rpc/cluster_server.go
@@ -24,7 +24,7 @@ import (
 	"github.com/yorkie-team/yorkie/pkg/document/time"
 	"github.com/yorkie-team/yorkie/pkg/types"
 	"github.com/yorkie-team/yorkie/yorkie/backend"
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 )
 
 // clusterServer is a normal server that processes the broadcast by the agent.
@@ -44,13 +44,13 @@ func (s *clusterServer) BroadcastEvent(
 ) (*api.BroadcastEventResponse, error) {
 	actorID, err := time.ActorIDFromBytes(request.PublisherId)
 	if err != nil {
-		log.Logger().Error(err)
+		logging.DefaultLogger().Error(err)
 		return nil, err
 	}
 
 	docEvent, err := converter.FromDocEvent(request.Event)
 	if err != nil {
-		log.Logger().Error(err)
+		logging.DefaultLogger().Error(err)
 		return nil, err
 	}
 
diff --git a/yorkie/rpc/interceptors/default.go b/yorkie/rpc/interceptors/default.go
index a4e72d39..888594b1 100644
--- a/yorkie/rpc/interceptors/default.go
+++ b/yorkie/rpc/interceptors/default.go
@@ -30,13 +30,12 @@ import (
 	"github.com/yorkie-team/yorkie/yorkie/auth"
 	"github.com/yorkie-team/yorkie/yorkie/backend/db"
 	"github.com/yorkie-team/yorkie/yorkie/clients"
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 	"github.com/yorkie-team/yorkie/yorkie/packs"
 )
 
 // DefaultInterceptor is a interceptor for default.
-type DefaultInterceptor struct {
-}
+type DefaultInterceptor struct{}
 
 // NewDefaultInterceptor creates a new instance of DefaultInterceptor.
 func NewDefaultInterceptor() *DefaultInterceptor {
@@ -53,12 +52,15 @@ func (i *DefaultInterceptor) Unary() grpc.UnaryServerInterceptor {
 	) (interface{}, error) {
 		start := gotime.Now()
 		resp, err := handler(ctx, req)
+		reqLogger := logging.From(ctx)
 		if err != nil {
-			log.Logger().Warnf("RPC : %q %s: %q => %q", info.FullMethod, gotime.Since(start), req, err)
+			reqLogger.Warnf("RPC : %q %s: %q => %q", info.FullMethod, gotime.Since(start), req, err)
 			return nil, toStatusError(err)
 		}
 
-		log.Logger().Infof("RPC : %q %s", info.FullMethod, gotime.Since(start))
+		if gotime.Since(start) > 100*gotime.Millisecond {
+			reqLogger.Infof("RPC : %q %s", info.FullMethod, gotime.Since(start))
+		}
 		return resp, err
 	}
 }
@@ -71,14 +73,16 @@ func (i *DefaultInterceptor) Stream() grpc.StreamServerInterceptor {
 		info *grpc.StreamServerInfo,
 		handler grpc.StreamHandler,
 	) error {
+		reqLogger := logging.From(ss.Context())
+
 		start := gotime.Now()
 		err := handler(srv, ss)
 		if err != nil {
-			log.Logger().Warnf("RPC : stream %q %s => %q", info.FullMethod, gotime.Since(start), err.Error())
+			reqLogger.Warnf("RPC : stream %q %s => %q", info.FullMethod, gotime.Since(start), err.Error())
 			return toStatusError(err)
 		}
 
-		log.Logger().Infof("RPC : stream %q %s", info.FullMethod, gotime.Since(start))
+		reqLogger.Infof("RPC : stream %q %s", info.FullMethod, gotime.Since(start))
 		return err
 	}
 }
diff --git a/yorkie/rpc/interceptors/logging.go b/yorkie/rpc/interceptors/logging.go
new file mode 100644
index 00000000..4a9b4b5a
--- /dev/null
+++ b/yorkie/rpc/interceptors/logging.go
@@ -0,0 +1,57 @@
+package interceptors
+
+import (
+	"context"
+	"strconv"
+	"sync/atomic"
+
+	grpcmiddleware "github.com/grpc-ecosystem/go-grpc-middleware"
+	"google.golang.org/grpc"
+
+	"github.com/yorkie-team/yorkie/yorkie/logging"
+)
+
+type reqID int32
+
+func (c *reqID) next() string {
+	next := atomic.AddInt32((*int32)(c), 1)
+	return "r" + strconv.Itoa(int(next))
+}
+
+// LoggingInterceptor is an interceptor for request logging.
+type LoggingInterceptor struct {
+	reqID reqID
+}
+
+// NewLoggingInterceptor creates a new instance of LoggingInterceptor.
+func NewLoggingInterceptor() *LoggingInterceptor {
+	return &LoggingInterceptor{}
+}
+
+// Unary creates a unary server interceptor for request logging.
+func (i *LoggingInterceptor) Unary() grpc.UnaryServerInterceptor {
+	return func(
+		ctx context.Context,
+		req interface{},
+		info *grpc.UnaryServerInfo,
+		handler grpc.UnaryHandler,
+	) (resp interface{}, err error) {
+		reqLogger := logging.New(i.reqID.next())
+		return handler(logging.With(ctx, reqLogger), req)
+	}
+}
+
+// Stream creates a stream server interceptor for request logging.
+func (i *LoggingInterceptor) Stream() grpc.StreamServerInterceptor {
+	return func(
+		srv interface{},
+		ss grpc.ServerStream,
+		info *grpc.StreamServerInfo,
+		handler grpc.StreamHandler,
+	) error {
+		reqLogger := logging.New(i.reqID.next())
+		wrapped := grpcmiddleware.WrapServerStream(ss)
+		wrapped.WrappedContext = logging.With(ss.Context(), reqLogger)
+		return handler(srv, wrapped)
+	}
+}
diff --git a/yorkie/rpc/server.go b/yorkie/rpc/server.go
index e2e824a6..abff6adf 100644
--- a/yorkie/rpc/server.go
+++ b/yorkie/rpc/server.go
@@ -30,7 +30,7 @@ import (
 
 	"github.com/yorkie-team/yorkie/api"
 	"github.com/yorkie-team/yorkie/yorkie/backend"
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 	"github.com/yorkie-team/yorkie/yorkie/rpc/interceptors"
 )
 
@@ -43,16 +43,19 @@ type Server struct {
 
 // NewServer creates a new instance of Server.
 func NewServer(conf *Config, be *backend.Backend) (*Server, error) {
+	loggingInterceptor := interceptors.NewLoggingInterceptor()
 	authInterceptor := interceptors.NewAuthInterceptor(be.Config.AuthWebhookURL)
 	defaultInterceptor := interceptors.NewDefaultInterceptor()
 
 	opts := []grpc.ServerOption{
 		grpc.UnaryInterceptor(grpcmiddleware.ChainUnaryServer(
+			loggingInterceptor.Unary(),
 			be.Metrics.ServerMetrics().UnaryServerInterceptor(),
 			authInterceptor.Unary(),
 			defaultInterceptor.Unary(),
 		)),
 		grpc.StreamInterceptor(grpcmiddleware.ChainStreamServer(
+			loggingInterceptor.Stream(),
 			be.Metrics.ServerMetrics().StreamServerInterceptor(),
 			authInterceptor.Stream(),
 			defaultInterceptor.Stream(),
@@ -62,7 +65,7 @@ func NewServer(conf *Config, be *backend.Backend) (*Server, error) {
 	if conf.CertFile != "" && conf.KeyFile != "" {
 		creds, err := credentials.NewServerTLSFromFile(conf.CertFile, conf.KeyFile)
 		if err != nil {
-			log.Logger().Error(err)
+			logging.DefaultLogger().Error(err)
 			return nil, err
 		}
 		opts = append(opts, grpc.Creds(creds))
@@ -111,16 +114,16 @@ func (s *Server) GRPCServer() *grpc.Server {
 func (s *Server) listenAndServeGRPC() error {
 	lis, err := net.Listen("tcp", fmt.Sprintf(":%d", s.conf.Port))
 	if err != nil {
-		log.Logger().Error(err)
+		logging.DefaultLogger().Error(err)
 		return err
 	}
 
 	go func() {
-		log.Logger().Infof("serving RPC on %d", s.conf.Port)
+		logging.DefaultLogger().Infof("serving RPC on %d", s.conf.Port)
 
 		if err := s.grpcServer.Serve(lis); err != nil {
 			if err != grpc.ErrServerStopped {
-				log.Logger().Error(err)
+				logging.DefaultLogger().Error(err)
 			}
 		}
 	}()
diff --git a/yorkie/rpc/yorkie_server.go b/yorkie/rpc/yorkie_server.go
index 941ffff9..d1698295 100644
--- a/yorkie/rpc/yorkie_server.go
+++ b/yorkie/rpc/yorkie_server.go
@@ -28,7 +28,7 @@ import (
 	"github.com/yorkie-team/yorkie/yorkie/backend/db"
 	"github.com/yorkie-team/yorkie/yorkie/backend/sync"
 	"github.com/yorkie-team/yorkie/yorkie/clients"
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 	"github.com/yorkie-team/yorkie/yorkie/packs"
 )
 
@@ -137,7 +137,7 @@ func (s *yorkieServer) AttachDocument(
 		}
 		defer func() {
 			if err := locker.Unlock(ctx); err != nil {
-				log.Logger().Error(err)
+				logging.DefaultLogger().Error(err)
 			}
 		}()
 	}
@@ -202,7 +202,7 @@ func (s *yorkieServer) DetachDocument(
 		}
 		defer func() {
 			if err := locker.Unlock(ctx); err != nil {
-				log.Logger().Error(err)
+				logging.DefaultLogger().Error(err)
 			}
 		}()
 	}
@@ -267,12 +267,12 @@ func (s *yorkieServer) PushPull(
 		}
 
 		if err := locker.Lock(ctx); err != nil {
-			log.Logger().Error(err)
+			logging.DefaultLogger().Error(err)
 			return nil, err
 		}
 		defer func() {
 			if err := locker.Unlock(ctx); err != nil {
-				log.Logger().Error(err)
+				logging.DefaultLogger().Error(err)
 			}
 		}()
 	}
@@ -346,7 +346,7 @@ func (s *yorkieServer) WatchDocuments(
 		docKeys,
 	)
 	if err != nil {
-		log.Logger().Error(err)
+		logging.From(stream.Context()).Error(err)
 		return err
 	}
 
@@ -357,7 +357,7 @@ func (s *yorkieServer) WatchDocuments(
 			},
 		},
 	}); err != nil {
-		log.Logger().Error(err)
+		logging.From(stream.Context()).Error(err)
 		s.unwatchDocs(docKeys, subscription)
 		return err
 	}
@@ -385,7 +385,7 @@ func (s *yorkieServer) WatchDocuments(
 					},
 				},
 			}); err != nil {
-				log.Logger().Error(err)
+				logging.From(stream.Context()).Error(err)
 				s.unwatchDocs(docKeys, subscription)
 				return err
 			}
@@ -425,7 +425,7 @@ func (s *yorkieServer) watchDocs(
 		docKeys,
 	)
 	if err != nil {
-		log.Logger().Error(err)
+		logging.From(ctx).Error(err)
 		return nil, nil, err
 	}
 
diff --git a/yorkie/yorkie.go b/yorkie/yorkie.go
index 2d45afb8..ca146a17 100644
--- a/yorkie/yorkie.go
+++ b/yorkie/yorkie.go
@@ -21,7 +21,7 @@ import (
 
 	"github.com/yorkie-team/yorkie/yorkie/backend"
 	"github.com/yorkie-team/yorkie/yorkie/backend/sync"
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 	"github.com/yorkie-team/yorkie/yorkie/profiling"
 	"github.com/yorkie-team/yorkie/yorkie/profiling/prometheus"
 	"github.com/yorkie-team/yorkie/yorkie/rpc"
@@ -92,7 +92,7 @@ func (r *Yorkie) Start() error {
 	if r.profilingServer != nil {
 		err := r.profilingServer.Start()
 		if err != nil {
-			log.Logger().Error(err)
+			logging.DefaultLogger().Error(err)
 			return err
 		}
 	}


Test patch:
diff --git a/test/integration/main_test.go b/test/integration/main_test.go
index d1d29f8a..e265d09a 100644
--- a/test/integration/main_test.go
+++ b/test/integration/main_test.go
@@ -32,7 +32,7 @@ import (
 	"github.com/yorkie-team/yorkie/pkg/types"
 	"github.com/yorkie-team/yorkie/test/helper"
 	"github.com/yorkie-team/yorkie/yorkie"
-	"github.com/yorkie-team/yorkie/yorkie/log"
+	"github.com/yorkie-team/yorkie/yorkie/logging"
 )
 
 type clientAndDocPair struct {
@@ -50,13 +50,13 @@ var defaultAgent *yorkie.Yorkie
 func TestMain(m *testing.M) {
 	agent := helper.TestYorkie()
 	if err := agent.Start(); err != nil {
-		log.Logger().Fatal(err)
+		logging.DefaultLogger().Fatal(err)
 	}
 	defaultAgent = agent
 	code := m.Run()
 	if defaultAgent != nil {
 		if err := defaultAgent.Shutdown(true); err != nil {
-			log.Logger().Error(err)
+			logging.DefaultLogger().Error(err)
 		}
 	}
 	os.Exit(code)
diff --git a/yorkie/backend/sync/memory/pubsub_test.go b/yorkie/backend/sync/memory/pubsub_test.go
index 12893d31..5136eaff 100644
--- a/yorkie/backend/sync/memory/pubsub_test.go
+++ b/yorkie/backend/sync/memory/pubsub_test.go
@@ -17,6 +17,7 @@
 package memory_test
 
 import (
+	"context"
 	gosync "sync"
 	"testing"
 
@@ -48,11 +49,12 @@ func TestPubSub(t *testing.T) {
 			DocumentKeys: docKeys,
 		}
 
+		ctx := context.Background()
 		// subscribe the documents by actorA
-		subA, err := pubSub.Subscribe(actorA, docKeys)
+		subA, err := pubSub.Subscribe(ctx, actorA, docKeys)
 		assert.NoError(t, err)
 		defer func() {
-			pubSub.Unsubscribe(docKeys, subA)
+			pubSub.Unsubscribe(ctx, docKeys, subA)
 		}()
 
 		var wg gosync.WaitGroup
@@ -64,7 +66,7 @@ func TestPubSub(t *testing.T) {
 		}()
 
 		// publish the event to the documents by actorB
-		pubSub.Publish(actorB.ID, event)
+		pubSub.Publish(ctx, actorB.ID, event)
 		wg.Wait()
 	})
 
@@ -77,8 +79,10 @@ func TestPubSub(t *testing.T) {
 			},
 		}
 
+		ctx := context.Background()
+
 		for i := 0; i < 5; i++ {
-			_, err := pubSub.Subscribe(actorA, docKeys)
+			_, err := pubSub.Subscribe(ctx, actorA, docKeys)
 			assert.NoError(t, err)
 
 			subs := pubSub.BuildPeersMap(docKeys)